1. insert into 与 insert overwrite区别
insert into 与 insert overwrite 都可以向hive表中插入数据,但是insert into直接追加到表中数据的尾部,而insert overwrite会重写数据,既先进行删除,再写入
注意:如果存在分区的情况,insert overwrite只重写当前分区数据,不会全部重写
2. insert 与 with as 子查询一起使用
当在hive中同时使用insert into(overwrite) table xx 与with子查询时候,需要将insert放在with as子查询后面(区分:与StarRocks不同,insert放在with as子查询前面)文章来源:https://www.toymoban.com/news/detail-774187.html
WITH TEMP_A AS (
SELECT TIME,IOT_ID,NAME FROM IOT_XX_A
),
TEMP_B AS (
SELECT TIME,IOT_ID,NAME,COUNT(DISTINCT IOT_ID) AS TIMES FROM TEMP_A
GROUP BY TIME,IOT_ID,NAME
)
INSERT INTO TABLE TABLE_B
SELECT TIME,IOT_ID,NAME,TIMES FROM TEMP_B
注意: 当使用以下语句建表时,需要将create放在with as子查询前面文章来源地址https://www.toymoban.com/news/detail-774187.html
DROP TABLE IF EXISTS xx ;
CREATE TABLE xx AS
WITH TEMP_A AS (
SELECT TIME,IOT_ID,NAME FROM IOT_XX_A
),
TEMP_B AS (
SELECT TIME,IOT_ID,NAME,COUNT(DISTINCT IOT_ID) AS TIMES FROM TEMP_A
GROUP BY TIME,IOT_ID,NAME
)
SELECT TIME,IOT_ID,NAME,TIMES FROM TEMP_B
到了这里,关于Hive insert插入数据与with子查询的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!