목록빅데이터/Hive (4)
Monday
report.sql이란 파일이 다음과 같이 저장되어 있을 때 beeline을 통해서 사용하는 법을 보여드리겠습니다. # report.sql SELECT * FROM accounting.current WHERE month= '${hivevar:month}' or # report.sql (변수 선언 포함) SET hivevar:month = October; SELECT * FROM accounting.current WHERE month= '${hivevar:month}' 사용법 $ beeline -u jdbc:hive2://localhost:10000 --hivevar month="October" -f report.sql
-AND Operator- NULL 값일 때 AND 결과 Expression Value true AND NULL NULL false AND NULL false NULL AND NULL NULL -OR Operator- NULL 값일 때 OR 결과 Expression Value true OR NULL true false OR NULL NULL NULL OR NULL NULL -NOT Operator- Expression Value NOT NULL NULL ※ 주의, 문자열 처리시 ""(empty string) ≠ NULL NULL 처리에 유용한 특수 함수 1) If if(조건, 값1, 값2) 처럼 사용하며 조건이 참일때 값1 반환, 거짓일 때 값2 반환 select if(money is NULL, 0, m..
쿼리에는 문자열 일부분을 매칭시켜 찾을 때 사용할 수 있는 % 연산자가 있습니다. %는 0개 이상의 문자와 매칭되는 것을 의미합니다. 또한 1개의 어떤 문자와 매칭되는 _(underscore)도 사용하실 수 있습니다. SELECT * FROM inventory WHERE shop LIKE '%ice%' # shop이 dicey와 같이 ice를 포함하는걸 출력해줌. or SELECT * FROM inventory WHERE shop LIKE '__ce_' # shop 5글자여야하고, 3,4번째 글자가 ce인 샵
하이브에서 비대화형 모드로 쿼리를 사용하고 싶을 때 Beeline 모드를 사용하실 수 있습니다. 사용법은 beeline -u "하이브 서버 url" -e "명령어" 입니다. $ beeline -h //Beeline Command 정보보기 $ beeline -u jdbc:hive2://localhost:10000 -e 'SELECT * FROM fun.games' $ beeline -u jdbc:hive2://localhost:10000 -e 'USE fun; SELECT * FROM games' $ beeline -u jdbc:hive2://localhost:10000 --silent=true -e 'SELECT * FROM fun.games' 또한, 직접 쿼리를 치지 않아도 파일을 통해서 쿼리를 수행할..