一、presto不支持insert overwrite
Presto中不支持insert overwrite语法,只能先delete,然后insert into。
详见:Presto上使用SQL遇到的一些坑:https://segmentfault.com/a/1190000013120454
presto insert overwrite 替代方案:
1.hive建表
2.presto查询结果放到txt文件
3.load
hive -e"
use app;
CREATE external TABLE IF NOT EXISTS app.tablename(
...
m_pt bigint COMMENT '播放时长'
)
COMMENT '表描述'
PARTITIONED BY(dt STRING, testid STRING, type STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE
LOCATION '/dw/app/tablename';
"
# run sql
$presto --server uhadoop-op3raf-master1:28080 --catalog hive --schema adm --file $TO_SQL | sed 's/"//g' > $RESULT_LINK
# load data
hive -e "load data local inpath '${RESULT_LINK}' overwrite into table app.tablename partition (dt='${in_dt}', testid='${in_testid}', type='${in_type}');"
二、presto不支持传递参数到.sql文件
可通过shell脚本中的sed将.sql文件中的变量替换掉
# get sql
cat $from_sql \
| sed 's/\${datebuf}/'$in_dt'/g' \
| sed 's/\${testid}/'${in_testid}'/g' > $TO_SQL
# run sql
$presto --server uhadoop-op3raf-master1:28080 --catalog hive --schema adm --file $TO_SQL | sed 's/"//g' > $RESULT_LINK
# load data
hive -e "load data local inpath '${RESULT_LINK}' overwrite into table app.${TABLE} partition (dt='${in_dt}', testid='${in_testid}');"
本文介绍了Presto不支持INSERT OVERWRITE操作的事实,提出了通过Hive建表、Presto查询结果存储为TXT文件再进行LOAD的替代方案。同时,针对Presto无法在.sql文件中传递参数的问题,建议使用shell脚本的sed命令进行变量替换来解决。
2042





