繁体   English   中英

使用Java在单个语句中运行多个Hive查询时出错

[英]Error in Running multiple Hive Queries in single statement using Java

我正在运行此查询:

Set hive.limit.query.max.table.partition=9000;select distinct ps169 as hotel_code,pd5 as city_code,datediff(to_date(pd32),to_date(FROM_UNIXTIME(UNIX_TIMESTAMP()))) as ap1,ps180 as los from camustest.a_1229 r join ht.ttl_values ttl on r.ps169=ttl.hotel_code and datediff(to_date(pd32),to_date(FROM_UNIXTIME(UNIX_TIMESTAMP())))=ttl.ap  and year= 2016 and month=12 and day=30 where pd5 IS NOT NULL and trim(ttl.hotel_code)!='' and trim(ttl.hotel_code)!='null' and ttl.hotel_code IS NOT NULL and trim(ttl.city_code)!= '' and ttl.ttl > 0 and ttl.ttl <= 4 and hour >= 8 and hour <= 12 and date = '2016-06-01--2016-06-15' and ap<=90 and ps180<=7 

我可以在Hive Console上运行它。 但是从Java代码运行时,出现此错误:

[2016-12-30 12:39:24,409]错误tomcat-pool-1 com.mmt.rateRefresh.hive.HiveManager-错误[Cloudera] JDBC预期结果集,但不是从查询生成的

[2016-12-30 12:39:24,409]错误tomcat-pool-1 com.mmt.rateRefresh.hive.HiveManager-查询错误

在一个execute语句中无法运行两个查询。

唯一方法:将它们作为单独的查询运行。

您设置的属性“ Set hive.limit.query.max.table.partition = 9000”将出现在会话中。(Java api会注意这一点)

注意使用相同的连接来执行两个语句。

您可以使用beeline命令行工具执行此操作:

beeline -u "jdbc:hive2://HIVESERVER/default" << EOF >> /tmp/log.txt 2>&1
Set hive.limit.query.max.table.partition=9000;select distinct ps169 as ... ;
!quit;
EOF

SQL是否在文件中-执行它:

beeline -u "jdbc:hive2://HIVESERVER/default" << EOF >> /tmp/log.txt 2>&1
!run /tmp/script.sql
!quit;
EOF

另外,您可以定义带有请求结果的文件:

...
!record /tmp/script-output.txt
!run /tmp/script.sql
!record
...

暂无
暂无

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

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