2017-07-18 4 views
2

J'ai une table dans HBase où les caractères chinois sont stockés dans une certaine colonne, disons 'FLT: CREW_DEPT'. Maintenant, j'ai besoin de filtrer toutes les lignes que 'FLT: CREW_DEPT' équivaut à une certaine valeur. Lors de cette opération dans la coquille HBase, il fonctionne très bien, comme ci-dessousLe filtre ne fonctionne pas lors de l'utilisation de Happybase pour scanner une table HBase avec un caractère chinois

scan 'PAX_EXP_FACT', {COLUMNS => ['FLT:CREW_DEPT'], FILTER => "SingleColumnValueFilter ('FLT', 'CREW_DEPT', =, 'binary:\xe4\xb8\x80\xe9\x83\xa8', true, true)", LIMIT => 5} 
ROW             COLUMN+CELL 
CA101-20160808-PEK-001192753702      column=FLT:CREW_DEPT, timestamp=1500346136328, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161103-PEK-001181988752      column=FLT:CREW_DEPT, timestamp=1500346230204, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161105-PEK-000728690130      column=FLT:CREW_DEPT, timestamp=1500346244963, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161201-PEK-006731936575      column=FLT:CREW_DEPT, timestamp=1500346233640, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161212-PEK-001512808262      column=FLT:CREW_DEPT, timestamp=1500346223572, value=\xE4\xB8\x80\xE9\x83\xA8 
5 row(s) in 0.0060 seconds 

Cependant, lorsque vous faites la même chose en python utilisant happybase, rien est retourné:

import happybase 
import datetime 
import pytz 

connection = happybase.Connection('192.168.199.200', port=9090) 
table = connection.table('PAX_EXP_FACT') 

filter_str = "" 
filter_str += "SingleColumnValueFilter('FLT', 'CREW_DEPT', =, 'binary:\xe4\xba\x8c\xe9\x83\xa8')" 

results = table.scan(
    filter=filter_str 
    #  ,limit=100 
) 

count = 0 
for key, data in results: 
    count += 1 
    print(data[b'FLT:CREW_DEPT'].decode('utf-8')) 

print('No. of flight matches:', count) 

connection.close() 

0 lignes sont renvoyées ...

Quelqu'un peut-il aider? Très appréciée!!!

Répondre

1

La réponse est avéré être très simple ... Je l'ai utilisé

"SingleColumnValueFilter('FLT', 'CREW_DEPT', =, 'binary:中文')" 

au lieu de le convertir en chaîne d'octets codé utf-8 première ... même en coquille HBase je peux faire la même chose (même si elle est affichée en points d'interrogation)

scan 'PAX_EXP_FACT', {COLUMNS => ['FLT:CREW_DEPT'], FILTER => "SingleColumnValueFilter ('FLT', 'CREW_DEPT', =, 'binary:??', true, true)", LIMIT => 5} 
ROW             COLUMN+CELL 
CA101-20160808-PEK-001192753702      column=FLT:CREW_DEPT, timestamp=1500353334419, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161103-PEK-001181988752      column=FLT:CREW_DEPT, timestamp=1500353426641, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161105-PEK-000728690130      column=FLT:CREW_DEPT, timestamp=1500353447707, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161201-PEK-006731936575      column=FLT:CREW_DEPT, timestamp=1500353432222, value=\xE4\xB8\x80\xE9\x83\xA8 
CA101-20161212-PEK-001512808262      column=FLT:CREW_DEPT, timestamp=1500353417107, value=\xE4\xB8\x80\xE9\x83\xA8 
5 row(s) in 0.0100 seconds 

L'utilisation ne fonctionnera pas sous-chaîne, qui était ce que j'avais essayé avant soulevé cette question idiote ...