2014-02-11 3 views
1

파이썬 아파치 하이브 클라이언트 (https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-Python)를 사용하여 상어 서버에서 쿼리를 실행하고 있습니다.파이썬 하이브 쿼리가 100으로 제한됩니다.

필자는 상어 CLI에서 쿼리를 정상적으로 실행할 때 전체 결과 집합을 얻을 수 있지만 하이브 파이썬 클라이언트를 사용하면 100 개의 행만 반환합니다. 내 선택 쿼리에는 제한이 없습니다.

상어 CLI :

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

: 나는 파이썬 코드에서 COUNT (*)를 실행할 때

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 

는 이상하게도, 내가 얻을 :

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

이 설정 있는가 이 제한을 해제하기 위해 액세스 할 수있는 파일 또는 변수는 무엇입니까?

답변

1

100 행의 제한은 in the underlying Driver으로 설정되고 private int maxRows = 100;을 찾으십시오. 당신이 the fetchN() method를 사용하는 경우

maxRows를가 원하는 값으로 드라이버에 설정됩니다

public List<String> fetchN(int numRows) 

가능한 해결 방법은() 다음 패치 n을 호출하는 행의 총 수를 얻는 첫번째 포함 할 수있다. 그러나 반환 된 데이터에 잠재적으로 엄청난 수의 행이 관련된 경우 문제가 발생할 수 있습니다. 이러한 이유로 데이터를 청크로 가져와 처리하는 것이 훨씬 더 좋은 방법 인 것 같습니다. 비교 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 : 예, 정확하게. 두 번째 링크를 따라 가면 fetchN()의'driver.setMaxRows (numRows);에 대한 적절한 호출을 발견 할 것이다. – JensG

+0

고마워. 이를 임시 캐시 된 테이블을 사용하여 해결 한 다음 COUNT를 실행 한 다음 fetchN (count_var)을 실행합니다. 감사. – greenafrican

관련 문제