0

Hbase データベースへの接続に happybase を使用しています。「irisSample」というサンプルテーブルを作りました。これが私が問題を抱えているコードの部分です-

import happybase
from happybase import *
import json

connection = happybase.Connection('<ip-address>', '9090')

table = connection.table('irisSample')

n = 0
x = 1
for u in y:
    data = {'petalWidth':points['petalWidth'][n], 'sepalLength':points['sepalLength'][n], 
          'petalLength':points['petalLength'][n], 'label': u}
    row = 'row' + str(x)
    table.put(row, {'flowers': str(data)})
    n += 1
    x += 1

そして、私は次のようになります。

TApplicationException                     Traceback (most recent call last)
<ipython-input-15-94741a8b04dc> in <module>()
      9           'petalLength':points['petalLength'][n], 'label': u}
     10     row = 'row' + str(x)
---> 11     table.put(row, {'flowers': str(data)})
     12     n += 1
     13     x += 1

/root/anaconda/lib/python2.7/site-packages/happybase/table.pyc in put(self, row, data, timestamp, wal)
    437         """
    438         with self.batch(timestamp=timestamp, wal=wal) as batch:
--> 439             batch.put(row, data)
    440 
    441     def delete(self, row, columns=None, timestamp=None, wal=True):

/root/anaconda/lib/python2.7/site-packages/happybase/batch.pyc in __exit__(self, exc_type, exc_value, traceback)
    130             return
    131 
--> 132         self.send()

/root/anaconda/lib/python2.7/site-packages/happybase/batch.pyc in send(self)
     53                      self._table.name, self._mutation_count, len(bms))
     54         if self._timestamp is None:
---> 55             self._table.connection.client.mutateRows(self._table.name, bms, {})
     56         else:
     57             self._table.connection.client.mutateRowsTs(

/root/anaconda/lib/python2.7/site-packages/happybase/hbase/Hbase.pyc in mutateRows(self, tableName, rowBatches, attributes)
   1574     """
   1575     self.send_mutateRows(tableName, rowBatches, attributes)
-> 1576     self.recv_mutateRows()
   1577 
   1578   def send_mutateRows(self, tableName, rowBatches, attributes):

/root/anaconda/lib/python2.7/site-packages/happybase/hbase/Hbase.pyc in recv_mutateRows(self)
   1592       x.read(self._iprot)
   1593       self._iprot.readMessageEnd()
-> 1594       raise x
   1595     result = mutateRows_result()
   1596     result.read(self._iprot)

TApplicationException: Internal error processing mutateRows

同じ例外をスローしたjson.dumps(data)代わりに、私も試しました。str(data)

私が集めているものからは、Thriftの問題のように思えますが、間違っている可能性があります. 代わりにスターベースを見る必要があるかもしれません。わからないので皆さんにお聞きします。

4

2 に答える 2

1

「データ」オブジェクトでは、列名とともに列ファミリーを指定していないようです。

data = {'petalWidth':points['petalWidth'[n], 'sepalLength':points['sepalLength'][n], 'petalLength':points['petalLength'][n], 'label': u}

各列値の前に列ファミリーが必要です。たとえば、列ファミリーが「cf」の場合、「petalWidth」の代わりに「cf:petalWidth」が必要です。

data = {'cf:petalWidth':points['petalWidth'[n], 'cf:sepalLength':points['sepalLength'][n], 'cf:petalLength':points['petalLength'][n], 'cf:label': u}

これを行うと、mutateRows エラーが修正されました。

于 2016-01-28T20:54:55.777 に答える
-1

ここで答えを見つけました。未使用のポートで REST フレームワークを実行する必要がありました。次に、そのポートに接続し、Hbase 内のすべてのテーブルのリストを表示して、データベースにデータを挿入することができました。コマンドは./hbase-daemon.sh start rest -p <unused port number>. どこにも答えが見つからず、数日間誰もコメントすらしなかったので、これがお役に立てば幸いです! これがコードです。使ってしまいましたstarbase

import starbase
from starbase import Connection

c = Connection(host='<ip-address>', port=8000)

ちなみにデフォルトポートは8000です。

t = c.table('irisSample')

for flower in range(len(labels)):
    data = {'petalWidth':X[flower][3], 'petalLength':X[flower][2], 
              'sepalLength':X[flower][0], 'sepalWidth':X[flower][1], 'cluster': labels[flower]}
    n += 1
    row = 'row' + str(n)
    t.insert(row, {'flowers': data})
于 2016-01-21T16:14:40.970 に答える