-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table Put - How Do We Assign And Use A Variable For the 'Row Key' #255
Comments
If there is a solution to the above questions, I intend to scale up to writing from a CSV, reading into Python, then writing into HBase using HappyBase. |
you actually did not show the errors at all, only some very incomplete snippets of code. your problem has nothing to do with hardcoding values at all. you're likely not using the connection pool and connections correctly. a connection obtained from a pool is only valid in a |
ok, if I do not use any pool connection,
|
the error is right there if you read carefully:
|
The 'NoSuchColumnFamilyException' does not make sense to me. |
your approach 4 is broken code. you're not using connections and connection pools correctly. the basic structure of your code should look like this: pool = happybase.ConnectionPool(size=3, host=...)
with pool.connection() as connection:
table = connection.table(...)
table.put(...) |
Hi @wbolster, Thank you for your help. I tried your approach with and without using variables in the put - and it worked! # Without variables in the put
import happybase as hb
pool = hb.ConnectionPool(size=3, host='localhost')
with pool.connection() as conn:
table = conn.table('table1')
table.put('rowKey1', {'key1': 'value1'}, timestamp=123456)
with pool.connection() as conn:
table = conn.table('table')
table.row('rowKey1')
>>>{b'key1': b'value1'} With variables in the putimport happybase as hb
pool = hb.ConnectionPool(size=3, host='localhost')
row_key = 'rowKey2'
value_dict_key_1 = 'key1'
value_dict_value_1 = 'value1'
timestamp = 123457
values_dict = dict()
values_dict[value_dict_key_1] = value_dict_value_1 #{'key1': 'value1'}
with pool.connection() as conn:
table = conn.table('table1')
table.put(row_key, values_dict, timestamp=timestamp)
table.row(row_key)
>>>{b'key1': b'value1'} Observation/What I don't quite understand is: when there is a period of time between my first Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/home/kai/.local/lib/python3.8/site-packages/happybase/table.py", line 464, in put
batch.put(row, data)
File "/home/kai/.local/lib/python3.8/site-packages/happybase/batch.py", line 137, in __exit__
self.send()
File "/home/kai/.local/lib/python3.8/site-packages/happybase/batch.py", line 62, in send
self._table.connection.client.mutateRowsTs(
File "/home/kai/.local/lib/python3.8/site-packages/thriftpy2/thrift.py", line 219, in _req
return self._recv(_api)
File "/home/kai/.local/lib/python3.8/site-packages/thriftpy2/thrift.py", line 231, in _recv
fname, mtype, rseqid = self._iprot.read_message_begin()
File "thriftpy2/protocol/cybin/cybin.pyx", line 429, in cybin.TCyBinaryProtocol.read_message_begin
File "thriftpy2/protocol/cybin/cybin.pyx", line 60, in cybin.read_i32
File "thriftpy2/transport/buffered/cybuffered.pyx", line 65, in thriftpy2.transport.buffered.cybuffered.TCyBufferedTransport.c_read
File "thriftpy2/transport/buffered/cybuffered.pyx", line 69, in thriftpy2.transport.buffered.cybuffered.TCyBufferedTransport.read_trans
File "thriftpy2/transport/cybase.pyx", line 61, in thriftpy2.transport.cybase.TCyBuffer.read_trans
File "/home/kai/.local/lib/python3.8/site-packages/thriftpy2/transport/socket.py", line 131, in read
raise TTransportException(type=TTransportException.END_OF_FILE,
thriftpy2.transport.base.TTransportException: TTransportException(type=4, message='TSocket read 0 bytes') |
References:
When using Table Put,
within python3 shell
Approach 1 - Hardcoding values => put was successful
Approach 2 - Turning 'key' and 'value' pairs within the dictionary into bytes => put encountered errors
Approach 3 - Use variables for all other things except for the row key => put was successful
Approach 4 - Use variables for all other things except for the row key => put encountered errors
Approach 4's error
The text was updated successfully, but these errors were encountered: