我有一个shell脚本,该脚本可以自动执行beeline实用程序执行以下操作:
截断登台表 将数据加载到登台表 附加历史记录表。
到目前为止,一切都很好。我的代码是截断并将数据加载到语句表中,但没有将任何数据附加到历史表中。因为当我启动命令“ select count(*) from history_tbl
”时。我在beeline中得到0条记录。
+------+--+
| _c0 |
+------+--+
| 0 |
+------+--+
令人惊讶的是,当我执行“ select * from history_tbl;
”时
我可以看到实际数据
| "601809196400"|2018-09-19|"default"|"19"|2018-09-24 08:07:36|0.181156|0.514380|0.033541|0.171328|0.035591|0.064005|0|"df"|
"SYSTEM"|"A3"|"LT40"|"OTH"|"1_1day"|"TRADE"|"NA"|"Z_S"|"40-55"|"M"|"2"|0|"8_14"|0|"N"|"Unilateral
| left knee"|""|"SYSTEM"|142|0|0.400000|"UN"|1|"9111"|"6"|"S"|53|"M"|23700.000000|"N"|13|"M"||"rico
"|"zuba"|"BY "|"chris
"|"2023-07-30"|0|"PR" | NULL| NULL| NUL| NULL| NULL | NU
我对这个特性很困惑。
下面是shell脚本。
#!/bin/bash
timestamp=$(date +%Y-%m-%d-%H:%M:%S:%N)
number=$RANDOM
unix_time=$(date +%Y-%m-%d-%H:%M:%S)
cd path to script
export BEELINE_PREFIX='"jdbc:hive2://server:port,server:port,server:port/;serviceDiscoveryMode=zookeeper;zookeeperNamespace=hiveserver2;principal=hive/server@hello.COM"'
beeline -u $BEELINE_PREFIX -e "use next;"
echo "truncating the staging table tbl..."
beeline -u $BEELINE_PREFIX -e "TRUNCATE TABLE next.tbl;"
echo "Loading the data in staging table tbl"
beeline -u $BEELINE_PREFIX -e "LOAD DATA LOCAL INPATH '/path/tbl' INTO TABLE next.tbl;"
echo "Appending the data into history table HIST_tbl.."
beeline -u $BEELINE_PREFIX -e "insert into table next.HIST_tbl select *,'$unix_time','$number' from next.tbl;"