2013-11-04 3 views
1

하이브에서 다음과 같은 것을 시도하고 있습니다.하이브 변수 대체 기능 포함

집합 TODAY = "2013-11-04"; // this works

SET TODAY = to_date (from_unixtime (unix_timestamp())); // 이건 ..

오늘 설정; 오늘 = to_date (from_unixtime (unix_timestamp()))

의견이 있으십니까?

+0

을 예, 그것은 좋은 것입니다 HQL이 몇 가지 제어 기능을 추가했지만 현재는 쉘에서 전달할 수 있습니다. 예를 들어'hive --hiveconf TODAY = $ (date + "% Y- % m- % d")' – libjack

답변

2
SET TODAY = to_date(from_unixtime(unix_timestamp())); 

하이브에서는 사용할 수 없습니다. 당신이 할 수있는 것은 당신이

set TODAY=2013-11-05; 

파일 fileName.sql 필요가 다른 따라 쿼리를 실행하기 전에로드 할 볼 파일 fileName.sql에서 지금

select concat ('set TODAY=',to_date(from_unixtime(unix_timestamp())),'\;') from testTableName limit 1 >>/path/to/HQL/file/fileName.sql 

입니다. 이에 의해 할 수있는 :

hive -f hiveQueries.sql 

당신은 같은 것을 포함해야 hiveQueries.sql 파일 :이 도움이

use testDB; 
    source /path/to/HQL/file/fileName.sql; 
    select * from testTable where someColumn=${hiveconf:TODAY}; 

희망을 .. :)