[使用Athena JDBC驱动程序运行ALTER TABLE ADD PARTITION
会引发难以理解的异常,这是代码:
package none;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class test {
public static void main(String[] args) throws Exception {
Properties info = new Properties();
info.put("User","myUser");
info.put("Password","myPass");
info.put("S3OutputLocation", "s3://my-bucket/output");
Class.forName("com.simba.athena.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:awsathena://AwsRegion=us-east-1;",info);
Statement statement = connection.createStatement();
ResultSet queryResults = statement.executeQuery("ALTER TABLE test01 ADD PARTITION (col2 = 'b') LOCATION 's3://my-bucket/col2=b/'");
}
}
这是上面的代码引发的错误,请注意查询在Athena控制台中运行正常,如果我从错误消息中复制并粘贴它:
Exception in thread "main" java.sql.SQLDataException: [Simba][JDBC](11300) A ResultSet was expected but not generated from query "ALTER TABLE test01 ADD PARTITION (col2 = 'b') LOCATION 's3://my-bucket/col2=b/'". Query not executed.
at com.simba.athena.exceptions.ExceptionConverter.toSQLException(Unknown Source)
at com.simba.athena.jdbc.common.SStatement.checkCondition(Unknown Source)
at com.simba.athena.jdbc.common.SStatement.executeNoParams(Unknown Source)
at com.simba.athena.jdbc.common.SStatement.executeNoParams(Unknown Source)
at com.simba.athena.jdbc.common.SStatement.executeQuery(Unknown Source)
at none.test.main(test.java:22)
但是,如果我用简单的SELECT替换语句,则可以正常工作:
//this works fine
ResultSet queryResults = statement.executeQuery("SELECT * FROM test01");
queryResults.next();
System.out.println(queryResults.getString("col1") + " -> " + queryResults.getString("col2"));
这是表的定义:
CREATE EXTERNAL TABLE test01 (
`col1` string
) PARTITIONED BY (
col2 string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'serialization.format' = ',',
'field.delim' = ','
) LOCATION 's3://my-bucket/'
TBLPROPERTIES ('has_encrypted_data'='false');
使用的驱动程序版本是Athena文档提供的版本:https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.9/AthenaJDBC42_2.0.9.jar
关于如何解决此问题的任何想法?谢谢!
您似乎正在使用statement.executeQuery(...)
执行不是查询的SQL语句。
尝试改用statement.execute(...)
:
statement.execute("ALTER TABLE test01 ADD PARTITION (col2 = 'b') LOCATION 's3://my-bucket/col2=b/'");