java - 使用 java 使用语句类的单个 execute() 方法执行多个配置单元查询

标签 java hadoop hive hiveql hadoop2

我正在使用 Java API 访问 HiveServer2,我需要在单次调用语句类的 execute() 方法时执行多个配置单元查询。是否可以在对execute() 方法的一次调用中提交多个配置单元查询。我有配置单元属性设置为:

SET hive.exec.max.created.files=200000;
SET hive.exec.compress.output=true;
SET mapred.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
SET hive.exec.dynamic.partition = true; 
SET hive.exec.dynamic.partition.mode = nonstrict; 
set hive.exec.max.dynamic.partitions=5000;
set hive.exec.max.dynamic.partitions.pernode=5000; 
              .
              .
Statement stmt = con.createStatement();
stmt.execute("SET hive.exec.max.created.files=200000");
              .
              .

为此,我现在使用execute() 方法一次设置这些属性。有什么方法可以通过一次调用 execute() 方法执行上述所有语句来设置所有这些属性。
预期:

stmt.execute("SET hive.exec.max.created.files=200000;
    SET hive.exec.dynamic.partition = true; 
    SET hive.exec.dynamic.partition.mode = nonstrict; 
    set hive.exec.max.dynamic.partitions=5000;
    set hive.exec.max.dynamic.partitions.pernode=5000;");


谢谢。

最佳答案

答案很明显。您不能在单个 execute() 方法中执行多个查询。为什么你不能像下面这样在 for 循环中做同样的事情

String[] queries = new String[] {"SET hive.exec.dynamic.partition = true", "set hive.exec.max.dynamic.partitions=5000"}; //and so on

Statement stmt = con.createStatement();

for(int i = 0; i < queries.length; i++){
   stmt.execute(queries[i]);
}

这也适用于多个 hive sql 查询,如选择、插入、删除等。根据sql语句结果集打印或填充到JTable中。

注意:execute()、executeUpdate() 和 executeQuery() 是不一样的。根据你的sql语句选择。

execute() - Returns true if the first object that the query returns is a ResultSet object.

executeUpdate() - Returns an integer representing the number of rows affected by the SQL statement.

executeQuery() - Returns one ResultSet object.

引用:docs.oracle.com/javase

HTH

关于java - 使用 java 使用语句类的单个 execute() 方法执行多个配置单元查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37678990/

相关文章:

java - 在 Spring Webflow 中创建新对象的首选替代方法

hadoop - 在 HIVE 中加载外部表时如何忽略括号

hive - 在 Hive 中将空白转换为 NULL

sql - 在 Hive 中选择一个随机行作为聚合函数

java - 中间键值对流是否在 hadoop 中优化

Apache Kylin - 空值度量变为零?

java - Elasticsearch:java.lang.InternalError:无法连接到窗口服务器

java - Google Drive Java 快速入门指南警告

java - HttpClient:确定响应中的空实体

java - 使用 Apache Sqoop 从 MySQL 导入数据 - 错误 : No manager for connect string