쿼리 실행
명령행(CLI)에 쿼리를 직접 입력하여 실행
# -e : Query that should be executed. Double or single quotes enclose the query string. This option can be specified multiple times.
beeline -e <query>
# single quotes
beeline -e 'SELECT * FROM SOSS.DM_SAFE_IDEX_GRID'
# dobule quotes
beeline -e "SELECT * FROM SOSS.DM_SAFE_IDEX_GRID"
스크립트 파일로 실행 (비대화식 모드)
# -f <file> : Script file that should be executed.
beeline -f <file>
# file
SELECT * FROM SOSS.DM_SAFE_IDEX_GRID
# execute
beeline -f select_idex_info.hql
hiveconf 옵션 주기
# --hiveconf property=value : Use value for the given configuration property. Properties that are listed in hive.conf.restricted.
beeline --hiveconf <property>=<value>
# hive.cli.print.header : 컬럼명까지 출력
beeline --hiveconf hive.cli.print.header=True -e "SELECT * FROM SOSS.DM_SAFE_IDEX_GRID"
스크립트 변수에 값 전달하기
# --hivevar name=value : Hive variable name and value. This is a Hive-specific setting in which variables can be set at the session level and referenced in Hive commands or queries.
beeline --hivevar <name>=<value>
beeline --hivevar dt=20221201 -f select_idex_info.hql
[exec file] SELECT * FROM SOSS.DM_SAFE_IDEX_GRID WHERE PT_STDR_DE = ${dt}
스크립트 실행 출력 내용을 CSV 파일로 추출 (컬럼명 포함)
beeline --hiveconf hive.cli.print.header=True --hivevar <name>=<value> -f <query-script> | sed 's/[\t]/,/g' > <./file.csv>
beeline --hiveconf hive.cli.print.header=True --hivevar dt='20221201' -f select_idex_info.hql | sed 's/[\t]/,/g' > ./output.csv