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

问题描述 投票:2回答:2

我正在运行此查询:

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一个ResultSet是预期的但不是从查询生成的

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

java hadoop hive cloudera
2个回答
2
投票

不可能在一个execute语句中运行两个查询。

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

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

注意使用相同的Connection来执行该语句。


1
投票

您可以使用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
...
© www.soinside.com 2019 - 2024. All rights reserved.