복붙노트

[HADOOP] 함수를 사용한 하이브 변수 대체

HADOOP

함수를 사용한 하이브 변수 대체

Hive에서 다음과 같은 것을하려고합니다.

TODAY = "2013-11-04"; //이 작동

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

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

어떤 제안?

해결법

  1. ==============================

    1.

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

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

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

    이제 fileName.sql 파일에

    set TODAY=2013-11-05;
    

    다른 종속 쿼리를 실행하기 전에 fileName.sql 파일을로드해야합니다. 당신이 할 수있는 것 :

    hive -f hiveQueries.sql
    

    hiveQueries.sql 파일에는 다음과 같은 내용이 포함되어야합니다.

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

    희망이 있습니다 .. :)

  2. from https://stackoverflow.com/questions/19775040/hive-variable-substitution-with-function by cc-by-sa and MIT license