当执行满足所有这些条件的查询时,BigQuery返回错误Unparseable query parameter `` in type ``TYPE_INT64``"
:
SELECT
.
SELECT ? AS field_1...
.例如,这段代码:
import java.sql.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TestBigQueryPreparedStatement {
private static final String CONNECTION_URI =
"jdbc:bigquery://<connection_uri>";
private static final String QUERY = "SELECT ? AS `_SOURCE_TABLE`, field1 FROM test_view";
public static void main(String[] args) throws ClassNotFoundException {
Class.forName("com.simba.googlebigquery.jdbc42.Driver");
try (Connection connection = DriverManager.getConnection(CONNECTION_URI)) {
try (PreparedStatement ps = connection.prepareStatement(QUERY)) {
// The problem also occurs if I replace this line with "ps.setObject(...)
ps.setString(1, "SOURCE_TABLE");
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getInt(2));
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
产生此错误:
java.sql.SQLException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Unparseable query parameter `` in type `TYPE_INT64`, Bad int64 value: SOURCE_TABLE value: 'SOURCE_TABLE'
at com.simba.googlebigquery.googlebigquery.client.requests.jobs.JobsInsertRequest.throwException(Unknown Source)
at com.simba.googlebigquery.googlebigquery.client.requests.AbstractRequestWithRetry.executeWithRetry(Unknown Source)
at com.simba.googlebigquery.googlebigquery.client.queryclient.JobsInsertClient.executeQuery(Unknown Source)
at com.simba.googlebigquery.googlebigquery.client.BQClient.executeQuery(Unknown Source)
at com.simba.googlebigquery.googlebigquery.dataengine.BQAbstractExecutor.execute(Unknown Source)
at com.simba.googlebigquery.googlebigquery.dataengine.BQSQLExecutor.execute(Unknown Source)
at com.simba.googlebigquery.jdbc.common.SPreparedStatement.executeWithParams(Unknown Source)
at com.simba.googlebigquery.jdbc.common.SPreparedStatement.executeQuery(Unknown Source)
at TestBigQueryPreparedStatement.main(TestBigQueryPreparedStatement.java:20)
Caused by: com.simba.googlebigquery.googlebigquery.client.exceptions.JobExecutionErrorException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Unparseable query parameter `` in type `TYPE_INT64`, Bad int64 value: SOURCE_TABLE value: 'SOURCE_TABLE'
... 9 more
Caused by: java.lang.Exception: Unparseable query parameter `` in type `TYPE_INT64`, Bad int64 value: SOURCE_TABLE value: 'SOURCE_TABLE'
at com.simba.googlebigquery.googlebigquery.client.requests.jobs.JobsInsertRequest.execute(Unknown Source)
at com.simba.googlebigquery.googlebigquery.client.requests.jobs.JobsInsertRequest.execute(Unknown Source)
... 8 more
PreparedStatement.setDate(...)
和setFloat(...)
中,但在setDecimal(...)
、setInt(...)
中运行良好(我没有使用PreparedStatement
)的所有setXXX方法检查输出。
是否可以在BigQuery查询中执行SELECT
中有文字的查询,并将查询作为准备好的语句执行?
这是一个示例场景。我的应用程序有一个在任何数据库上运行SQL查询的执行引擎,它总是使用准备好的语句来执行SQL查询。有时候,查询在SELECT
中会有一个文字,而在BigQuery中,我在上面得到了这个错误(它适用于任何其他数据库)。我可以专门为BigQuery的查询生成器进行某些更改,但是要更改代码非常困难,因此SELECT
子句中的文字作为文字传递,而不是作为准备语句的参数传递。
发布于 2022-10-18 15:50:39
不能在查询的select
或from
部分中使用位置查询参数。位置参数只能出现在查询的where
子句中。
SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE corpus = ?
AND word_count >= ?
ORDER BY word_count DESC;";
另见https://cloud.google.com/bigquery/docs/samples/bigquery-query-params-positional
https://stackoverflow.com/questions/73967451
复制相似问题