Hadoop에서 Hive 쿼리를 위해 Python으로 UDF를 작성하고 있습니다. 내 테이블에는 여러 개의 bigint
필드와 여러 개의 string
필드가 있습니다.Hadoop UDF 출력 (스트리밍)에서 열 데이터 형식 유지
내 UDF는 bigint
필드를 수정하고 수정 된 버전을 새 열 (숫자 여야 함)로 빼고 string
필드를있는 그대로 둡니다.
쿼리에서 UDF를 실행하면 결과는 모두 string
개입니다.
어떻게 보존 또는 내 UDF의 출력 유형을 지정할 수 있습니다?
자세한 내용 :
내 파이썬 UDF : 나는 myudf.py
으로이 UDF를 저장하고 하이브에 추가
import sys
for line in sys.stdin:
# pre-process row
line = line.strip()
inputs = line.split('\t')
# modify numeric fields, calculate new field
inputs[0], inputs[1], new_field = process(int(inputs[0]), int(inputs[1]))
# leave rest of inputs as is; they are string fields.
# output row
outputs = [new_field]
outputs.extend(inputs)
print '\t'.join([str(i) for i in outputs]) # doesn't preserve types!
.
내 하이브 쿼리 :
CREATE TABLE calculated_tbl AS
SELECT TRANSFORM(bigintfield1, bigintfield2, stringfield1, stringfield2)
USING 'python myudf.py'
AS (calculated_int, modified_bif1, modified_bif2, stringfield1, stringfield2)
FROM original_tbl;