简体   繁体   English

Hive插入从Hive CLI可以正常工作,但在终端上失败

[英]Hive Insert works fine from Hive CLI but fails from terminal

I currently have the following situation: 我目前有以下情况:

I have a shellscript that creates two tables and then fills one of them with data of the other. 我有一个shellscript,它创建两个表,然后用另一个数据填充其中一个。

my script looks somewhat like this: 我的脚本看起来像这样:

    hive -e "CREATE EXTERNAL TABLE table1 ... ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION '/user/input/'"
    hive -e "CREATE EXTERNAL TABLE table2 ... PARTITIONED BY ..."
    hive -e "WITH data AS (SELECT date, ...) FROM data INSERT OVERWRITE TABLE table2 PARTITION(part_date) SELECT ... date"

and then some more shellscript that selects certain data from table2. 然后再一些shellscript从table2中选择某些数据。 I use shellscript because there is some logic that has to be applied before I can do the selects on table2 . 我使用shellscript是因为必须先应用一些逻辑,然后才能对table2进行选择。

The script runs without error, the tables are created, table1 has data in it but table2 ends up empty. 脚本运行无错误,表已创建,表table1有数据,但table2最终为空。 For some reason it works when I use a very small test dataset, but as soon as the dataset becomes bigger (>1GB) table2 is empty. 出于某种原因,当我使用非常小的测试数据集时它可以工作,但是一旦数据集变大(> 1GB), table2就空了。

If I run the very same commands from Hives CLI manually everything works fine and table2 has the expected data in it. 如果我从Hives CLI手动运行相同的命令,则一切正常,并且table2包含预期的数据。

Why does this happen, and how could i resolve this? 为什么会发生这种情况,我该如何解决?

Your shell script commands must be executed sequentially to get data in table2 . 您的shell脚本命令必须顺序执行才能获取table2数据。

Try this in your shell script: 在您的shell脚本中尝试以下操作:

hive -e "your first query" && 
hive -e "your second query" &&
hive -e "your third query"

This should execute your hive queries one after another. 这应该一个接一个地执行您的配置单元查询。 (2nd query waits for 1st to finish and 3rd query waits for both 1st and 2nd to finish) (第二个查询等待第一个查询完成,第三个查询同时等待第一个查询和第二个查询)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM