Commit 51ba902
authored
fix(bigquery-jdbc): fallback to standard precision and scale for numeric, integer, and temporal types (googleapis#13321)
b/516471484
## Problem
Currently, `ResultSetMetaData.getPrecision()` and `getScale()` fall back
to `0` for all standard BigQuery types unless explicitly returned by the
server's field metadata (which is rarely populated for basic columns).
Returning `0` violates the JDBC specification for exact numeric,
integer, and temporal types, which can cause ORMs and schema inspectors
to misbehave.
Additionally, the type mappings inside `BigQueryDatabaseMetaData` used
for schema queries (like `getColumns()`) were inconsistent with the JDBC
specification and standard string length representations for temporal
types, reporting a precision of `29` with `null` scale for `TIMESTAMP`
and `DATETIME`, and missing scale definitions for `TIME` and `DATE`.
### Solution
1. **`BigQueryResultSetMetadata`**:
Modified BigQueryResultSetMetadata.java to fall back to the standard SQL
type definition properties when explicit schema-defined precision/scale
are absent.
The driver now returns standard fallback values based on the column's
StandardSQLTypeName:
| BigQuery Type | JDBC SQL Type | Fallback Precision | Fallback Scale |
Justification |
| :--- | :--- | :--- | :--- | :--- |
| **`INT64`** | `Types.BIGINT` | `19` | `0` | Signed 64-bit integer
range limit |
| **`NUMERIC`** | `Types.NUMERIC` | `38` | `9` | Standard BigQuery
NUMERIC specifications |
| **`BIGNUMERIC`** | `Types.NUMERIC` | `77` | `38` | Standard BigQuery
BIGNUMERIC specifications |
| **`DATE`** | `Types.DATE` | `10` | `0` | Display length of
`"YYYY-MM-DD"` |
| **`TIME`** | `Types.TIME` | `15` | `6` | Display length of
`"HH:MM:SS.ffffff"` (microseconds) |
| **`TIMESTAMP`** / **`DATETIME`** | `Types.TIMESTAMP` | `26` | `6` |
Display length of `"YYYY-MM-DD HH:MM:SS.ffffff"` |
| **`BOOL`** | `Types.BOOLEAN` | `1` | `0` | Single-digit bit/flag |
| **`FLOAT64`** | `Types.DOUBLE` | `15` | `0` | Double-precision
floating point precision limit |
2. **`BigQueryDatabaseMetaData`**:
- Aligned `STANDARD_TYPE_INFO` mappings for `TIMESTAMP`, `DATETIME`,
`DATE`, and `TIME` to match the fallback precision and scale values
reported by `BigQueryResultSetMetadata`.
- Added explanatory comments in the code justifying the
fallback/precision values.
### Testing
- Updated unit tests in BigQueryResultSetMetadataTest.java to verify
correct fallback values across all 13 dataset columns.1 parent 946dfb4 commit 51ba902
5 files changed
Lines changed: 163 additions & 182 deletions
File tree
- java-bigquery-jdbc/src
- main/java/com/google/cloud/bigquery/jdbc
- test/java/com/google/cloud/bigquery/jdbc
Lines changed: 2 additions & 65 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
| |||
2436 | 2435 | | |
2437 | 2436 | | |
2438 | 2437 | | |
2439 | | - | |
2440 | | - | |
2441 | | - | |
2442 | | - | |
2443 | | - | |
2444 | | - | |
2445 | | - | |
2446 | | - | |
2447 | | - | |
2448 | | - | |
2449 | | - | |
2450 | | - | |
2451 | | - | |
2452 | | - | |
2453 | | - | |
2454 | | - | |
2455 | | - | |
2456 | | - | |
2457 | | - | |
2458 | | - | |
2459 | | - | |
2460 | 2438 | | |
2461 | 2439 | | |
2462 | 2440 | | |
| |||
4833 | 4811 | | |
4834 | 4812 | | |
4835 | 4813 | | |
4836 | | - | |
4837 | | - | |
4838 | | - | |
4839 | | - | |
4840 | | - | |
4841 | | - | |
4842 | | - | |
4843 | | - | |
4844 | | - | |
4845 | | - | |
4846 | | - | |
4847 | | - | |
4848 | | - | |
4849 | | - | |
4850 | | - | |
4851 | | - | |
4852 | | - | |
4853 | | - | |
4854 | | - | |
4855 | | - | |
4856 | | - | |
4857 | | - | |
4858 | | - | |
4859 | | - | |
4860 | | - | |
4861 | | - | |
4862 | | - | |
4863 | | - | |
4864 | | - | |
4865 | | - | |
4866 | | - | |
4867 | | - | |
4868 | | - | |
4869 | | - | |
4870 | | - | |
4871 | | - | |
4872 | | - | |
4873 | | - | |
4874 | | - | |
4875 | | - | |
4876 | | - | |
4877 | 4814 | | |
4878 | 4815 | | |
4879 | 4816 | | |
4880 | 4817 | | |
4881 | 4818 | | |
4882 | | - | |
| 4819 | + | |
4883 | 4820 | | |
4884 | 4821 | | |
4885 | 4822 | | |
| |||
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
161 | 221 | | |
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
138 | 148 | | |
139 | 149 | | |
140 | 150 | | |
141 | 151 | | |
142 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
143 | 163 | | |
144 | 164 | | |
145 | 165 | | |
| |||
0 commit comments