2014-02-11 38 views
1

我正在使用Python Apache Hive客戶端(https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-Python)在Shark服務器上運行查詢。Python Hive查詢被限制爲100

probelm是當我在Shark CLI中正常運行查詢時我得到了一整套結果,但是當我使用Hive Python客戶端時,它只返回100行。我的選擇查詢沒有限制。

鯊魚CLI:

[localhost:10000] shark> SELECT COUNT(*) FROM table; 
46831 

的Python:

import sys 
from hive_service import ThriftHive 
from hive_service.ttypes import HiveServerException 
from thrift import Thrift 
from thrift.transport import TSocket 
from thrift.transport import TTransport 
from thrift.protocol import TBinaryProtocol 

try: 
    transport = TSocket.TSocket('localhost', 10000) 
    transport = TTransport.TBufferedTransport(transport) 
    protocol = TBinaryProtocol.TBinaryProtocol(transport) 

    client = ThriftHive.Client(protocol) 
    transport.open() 

    client.execute("SELECT * from table") 
    hdata = client.fetchAll() 
    transport.close() 
    .... 

In [97]: len(hdata) 
Out[97]: 100 

奇怪的是,當我運行在Python代碼COUNT(*)我得到:

In [104]: hdata 
Out[104]: ['46831'] 

是否有設置文件或變量,我可以訪問解鎖此限制?

回答

1

將100行的限制設置爲in the underlying Driver,查找private int maxRows = 100;

的maxRows進行是在駕駛者所期望的值設置,如果你使用the fetchN() method

public List<String> fetchN(int numRows) 

可能的解決方法可能涉及首先得到行總數,然後調用fetchN()。但是如果返回的數據涉及可能數量巨大的行,則可能會遇到麻煩。出於這個原因,看起來好像是一個更好的想法,以大塊的方式獲取和處理數據。爲了便於比較,here's what the CLI does

do { 
    results = client.fetchN(LINES_TO_FETCH); 
    for (String line : results) { 
    out.println(line); 
    } 
} while (results.size() == LINES_TO_FETCH); 

其中LINES_TO_FETCH = 40。但是這或多或少是一個隨心所欲的值,您可以根據自己的特定需求調整代碼。

+0

您的意思是說,在fetchAll()方法上設置了maxRows? – greenafrican

+0

@greenAfrican:確實如此。如果你按照第二個鏈接,你會找到'driver.setMaxRows(numRows);'''在'fetchN()'' – JensG

+0

的合適的調用謝謝。使用臨時緩存表解決此問題,然後運行COUNT,然後執行fetchN(count_var)。謝謝。 – greenafrican