googleapis / googleapis/google-cloud-java

[java-spanner-jdbc] Spanner: Column is not of correct type: expected one of [STRING, NUMERIC] but was NUMERIC, when reading NUMERIC column as Long

未关闭
#12,274 0 条评论 0 个 reaction 已指派 1 人 已被 @olavloite 认领 在 GitHub 查看
api: spanner
主要语言
Java
星标
2.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
154

描述

#### Environment details

2. OS type and version: Microsoft Windows [Version 10.0.26100.7171]
3. Java version: openjdk version "21.0.7" 2025-04-15 LTS
4. version(s): I'm working with the spanner emulator: https://github.com/GoogleCloudPlatform/cloud-spanner-emulator and JDBC driver version: `com.google.cloud:google-cloud-spanner-jdbc:2.34.0`

#### Steps to reproduce

Read a `NUMERIC` value using `ResultSet::getLong`

#### Code example

```java
try (
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("select cast(1 as numeric)")
) {
while (rs.next()) {
System.out.println(rs.getLong(1));
}
}
```

#### Stack trace

```
Exception in thread "main" java.lang.IllegalStateException: Column 0 is not of correct type: expected one of [STRING, NUMERIC] but was NUMERIC
at com.google.common.base.Preconditions.checkState(Preconditions.java:853)
at com.google.cloud.spanner.AbstractStructReader.checkNonNullOfTypes(AbstractStructReader.java:724)
at com.google.cloud.spanner.AbstractStructReader.getString(AbstractStructReader.java:238)
at com.google.cloud.spanner.connection.DirectExecuteResultSet.getString(DirectExecuteResultSet.java:224)
at com.google.cloud.spanner.jdbc.JdbcResultSet.getLong(JdbcResultSet.java:435)
at org.jooq.testscripts.JDBC.main(JDBC.java:45)
```

This doesn't happen when reading it using `ResultSet::getInt`, for example.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。