하이브는 매크로를 이용할 수 있습니다.
생성
기본 문법은 아래와 같습니다. 칼럼 이름을 표현식에 사용할 수 있습니다. 기본 빌트인 함수를 이용하여 매크로를 생성할 수도 있습니다. 매크로는 현재 세션에만 유지됩니다.
CREATE TEMPORARY MACRO macro_name([col_name col_type, ...]) expression;
매크로를 생성하는 방법은 아래와 같습니다.
CREATE TEMPORARY MACRO fixed_number() 42;
CREATE TEMPORARY MACRO string_len_plus_two(x string) length(x) + 2;
CREATE TEMPORARY MACRO simple_add (x int, y int) x + y;
CREATE TEMPORARY MACRO mfunc(a string, b string, c string) CONCAT(CONCAT_WS("/", a, b, c), "/");
hive> select fixed_number();
OK
42
hive> select string_len_plus_two("AB");
OK
4
hive> select simple_add(10, 5);
OK
15
hive> select mfunc('a', 'b', 'c');
OK
a/b/c/
삭제
매크로 이름을 입력하여 삭제합니다.
DROP TEMPORARY MACRO [IF EXISTS] macro_name;
반응형
'빅데이터 > hive' 카테고리의 다른 글
[hive] 맵조인과 셔플조인(Map Join vs Shuffle Join) (0) | 2020.06.09 |
---|---|
[hive] collect_list()와 같은 UDAF 함수의 GC 오류 해결 방법 (0) | 2020.06.01 |
[hive] This command is not allowed on an ACID table default.table_name with a non-ACID transaction manager 오류 해결 방법 (0) | 2020.03.17 |
[hive] 구체화 뷰(Materialized View) (0) | 2020.01.21 |
[hive] UDF에서 발생하는 argument type mismatch 오류 수정 (0) | 2020.01.14 |