使用 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 控制台上 运行 它。但是当从 Java 代码 运行ning 时,我得到这个错误:
[2016-12-30 12:39:24,409] ERROR tomcat-pool-1 com.mmt.rateRefresh.hive.HiveManager - error[Cloudera]JDBC A ResultSet was expected but not generated from query
[2016-12-30 12:39:24,409] ERROR tomcat-pool-1 com.mmt.rateRefresh.hive.HiveManager - error in query
不可能 运行 在一个执行语句中执行两个查询。
唯一的方法:运行它们作为单独的查询。
您设置的 属性 "Set hive.limit.query.max.table.partition=9000" 将出现在会话中。(Java api 小心)
注意 使用同一个连接来执行这两个语句。
您可以使用直线命令行工具来完成:
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
...
我正在运行宁此查询:
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 控制台上 运行 它。但是当从 Java 代码 运行ning 时,我得到这个错误:
[2016-12-30 12:39:24,409] ERROR tomcat-pool-1 com.mmt.rateRefresh.hive.HiveManager - error[Cloudera]JDBC A ResultSet was expected but not generated from query
[2016-12-30 12:39:24,409] ERROR tomcat-pool-1 com.mmt.rateRefresh.hive.HiveManager - error in query
不可能 运行 在一个执行语句中执行两个查询。
唯一的方法:运行它们作为单独的查询。
您设置的 属性 "Set hive.limit.query.max.table.partition=9000" 将出现在会话中。(Java api 小心)
注意 使用同一个连接来执行这两个语句。
您可以使用直线命令行工具来完成:
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
...