Commit 092ac4d
authored
refactor: centralize type mapping to fix metadata-path divergence (#174)
## Why
Column type information currently flows through three independent paths
— Arrow schema, `pg_catalog.format_type()`, and Spark — each with its
own per-site mapping logic. That scatter has caused repeated,
silently-diverging bugs: `pg_catalog` rows returning raw PostgreSQL OIDs
because `QueryMetadataUtil.dbTypeToSql` keyed on `int2`/`int4`/`int8`
aliases that Hyper never emits; `ResultSetMetaData` disagreeing with
`DatabaseMetaData.getColumns()` on type names and codes for the same
column; DECIMAL vs NUMERIC inconsistency between the two paths;
`getTypeInfo()` returning an empty result; engine-level concerns
(parameter binding, vector population) reaching into JDBC exception
types.
## Observable behavior changes
**New capabilities / bug fixes:**
- `DatabaseMetaData.getTypeInfo()` returns a real 18-column result
enumerated from `HyperTypeKind` (was empty before).
- Prepared-statement parameter Arrow round-trip: CHAR(1), CHAR(n), and
VARCHAR(n) now round-trip through Arrow losslessly via `hyper:type` /
`hyper:max_string_length` field metadata, matching the convention
Hyper's server already uses on the inbound side.
- `DatabaseMetaData.getColumns().COLUMN_SIZE` and `DECIMAL_DIGITS` are
now derived from the parsed type's declared precision/scale (e.g.
`numeric(10,5)` reports `COLUMN_SIZE=10, DECIMAL_DIGITS=5`; `char(1)`
reports `COLUMN_SIZE=1`) instead of being hardcoded to `255` / `2`.
- `DatabaseMetaData.getColumns().DATA_TYPE` is always a `java.sql.Types`
value (was a raw PG OID for unmapped types); unsupported types surface
as `Types.OTHER` with the raw name preserved via `HyperTypeKind.UNKNOWN`
rather than throwing.
- `DECIMAL_DIGITS` stays `0` for `FLOAT4` / `FLOAT8` (binary floats have
no meaningful decimal scale) instead of being hardcoded to `2`.
**Syntactic / naming changes:**
- `DatabaseMetaData.getColumns().TYPE_NAME` is consistently
JDBC-uppercase (`"BIGINT"`, `"INTEGER"`, `"DECIMAL"`, …) instead of a
mix of Hyper-lowercase and uppercase. `INTERVAL` and `JSON` show the
Hyper-uppercase form; unmodeled system-catalog types (e.g. `aclitem`)
show the raw Hyper name.
- Numeric/decimal unified to `DECIMAL` (both Arrow Decimal and Hyper
`numeric` map to `HyperTypeKind.DECIMAL` / `JDBCType.DECIMAL`).
## What's introduced
Introduce `HyperType`, a Hyper-native internal type model, and route
every Arrow, `pg_catalog`, prepared-statement, and Spark conversion
through it. The data layer lives under a new
`com.salesforce.datacloud.jdbc.protocol.data` package that has no JDBC
dependency, so engine-level callers can use it without a JDBC import;
the JDBC-bound helpers stay in
`com.salesforce.datacloud.jdbc.core.types.HyperTypes`. Translation to
`java.sql.JDBCType` / `Types` only happens at the JDBC API boundary.
**New in `protocol.data` (JDBC-free):**
- `HyperTypeKind` + `HyperType` value class with a visitor and native
`toHyperTypeName()`. `HyperTypeKind.UNKNOWN` preserves the raw Hyper
type name for system-catalog types the driver doesn't model (e.g.
`aclitem`).
- `PgCatalogTypeParser`, `ArrowToHyperTypeMapper`, `HyperTypeToArrow`
(format-boundary converters).
- `ColumnMetadata` with optional `typeName` override.
- `ParameterBinding` + `ParameterAccumulator` (replaces
`ParameterManager`); throws `IllegalArgumentException` so it is usable
without JDBC.
- `ArrowUtils`, `VectorPopulator` (moved from `.util`).
**`HyperTypes` stays in `core.types`** as the JDBC-bound boundary:
`toJdbcType*`, `fromJdbcTypeCode`, `toJavaClass`,
`getPrecision`/`getScale`/`getDisplaySize`,
`isSigned`/`isCaseSensitive`/`isNullable`, `needsDecimalDigits`,
`needsCharOctetLength`, `typeInfoRows`, plus the `isIntegerLike` /
`isStringLike` helpers that wrap exhaustive enum switches so callers can
do a family check without replicating the switch.
## Structural details
**Deleted:** `ColumnType`, `ArrowToColumnTypeMapper`, the
`QueryMetadataUtil.dbTypeToSql` + `isDecimalType`/`isCharType` helpers,
the `ArrowUtils.SQL_TYPE_TO_FIELD_TYPE` map.
**Migrated callers:** `ColumnMetadata` holds `HyperType`;
`DataCloudResultSetMetaData`, `StreamingResultSet`, `DataCloudArray`,
`DataCloudConnection.getSchemaForQueryId`, and
`ArrowUtils.toColumnMetaData` go through `ArrowToHyperTypeMapper` +
`HyperTypes`; `QueryMetadataUtil.constructColumnData` parses via
`PgCatalogTypeParser` and falls back to `HyperType.unknown(raw)` for
unmodeled system-catalog types; `SimpleResultSet` switches on
`HyperTypeKind` via the new helpers (and picks up TINYINT numeric
coercions and the `getFloat` wasNull/range-check fix that were planned
as Phase 0 work); `DataCloudPreparedStatement` wraps
`IllegalArgumentException` from `ParameterAccumulator` into
`SQLException`; `VectorPopulator` is keyed by `HyperTypeKind`; Spark
`TypeMapping` handles TINYINT, NUMERIC, CHAR, NULL, FLOAT, NCHAR,
NVARCHAR, LONGNVARCHAR.
**Follow-ups noted in code / comments (not in this PR):**
- `SimpleResultSet` is documented for removal once
`DataCloudMetadataResultSet` migrates to `StreamingResultSet` — one
result-set implementation instead of two.
- `QueryResultArrowStream.asArrowStreamReader`'s `RootAllocator`
lifetime needs a dedicated fix (it flows into `ArrowStreamReader`, which
doesn't close it).
- `TIME WITH TIME ZONE` Arrow round-trip is pinned as intended asymmetry
— offset honored on input but not preserved on output, matching Hyper's
read-side behavior. Proper round-trip would need either a synthetic
Arrow schema or Hyper-protocol coordination.1 parent d4b1dcf commit 092ac4d
47 files changed
Lines changed: 3134 additions & 1577 deletions
File tree
- jdbc-core/src
- main/java/com/salesforce/datacloud/jdbc
- core
- accessor/impl
- metadata
- model
- resultset
- types
- protocol/data
- util
- test/java/com/salesforce/datacloud/jdbc
- core
- metadata
- resultset
- types
- hyper
- protocol/data
- spark-datasource-core/src/main/scala/com/salesforce/datacloud/spark
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
284 | 290 | | |
285 | 291 | | |
286 | 292 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
753 | 755 | | |
754 | 756 | | |
755 | 757 | | |
756 | | - | |
| 758 | + | |
| 759 | + | |
757 | 760 | | |
758 | 761 | | |
759 | 762 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Lines changed: 53 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | | - | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | | - | |
| 63 | + | |
61 | 64 | | |
62 | | - | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | | - | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
72 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
91 | 96 | | |
92 | 97 | | |
93 | 98 | | |
94 | | - | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| |||
131 | 140 | | |
132 | 141 | | |
133 | 142 | | |
134 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
135 | 152 | | |
136 | 153 | | |
137 | 154 | | |
138 | 155 | | |
139 | | - | |
| 156 | + | |
140 | 157 | | |
141 | 158 | | |
142 | 159 | | |
143 | 160 | | |
144 | | - | |
| 161 | + | |
145 | 162 | | |
146 | 163 | | |
147 | 164 | | |
148 | 165 | | |
149 | | - | |
| 166 | + | |
150 | 167 | | |
151 | 168 | | |
152 | 169 | | |
153 | 170 | | |
154 | | - | |
| 171 | + | |
155 | 172 | | |
156 | 173 | | |
157 | 174 | | |
158 | 175 | | |
159 | | - | |
| 176 | + | |
160 | 177 | | |
161 | 178 | | |
162 | 179 | | |
163 | 180 | | |
164 | | - | |
| 181 | + | |
165 | 182 | | |
166 | 183 | | |
167 | 184 | | |
168 | 185 | | |
169 | | - | |
| 186 | + | |
170 | 187 | | |
171 | 188 | | |
172 | 189 | | |
173 | 190 | | |
174 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
175 | 199 | | |
176 | 200 | | |
177 | 201 | | |
178 | 202 | | |
179 | | - | |
| 203 | + | |
180 | 204 | | |
181 | 205 | | |
182 | 206 | | |
| |||
186 | 210 | | |
187 | 211 | | |
188 | 212 | | |
189 | | - | |
| 213 | + | |
190 | 214 | | |
191 | 215 | | |
192 | 216 | | |
193 | 217 | | |
194 | | - | |
| 218 | + | |
195 | 219 | | |
196 | 220 | | |
197 | 221 | | |
198 | 222 | | |
199 | | - | |
| 223 | + | |
200 | 224 | | |
201 | 225 | | |
202 | 226 | | |
| |||
216 | 240 | | |
217 | 241 | | |
218 | 242 | | |
219 | | - | |
| 243 | + | |
220 | 244 | | |
221 | 245 | | |
222 | 246 | | |
| |||
229 | 253 | | |
230 | 254 | | |
231 | 255 | | |
232 | | - | |
| 256 | + | |
233 | 257 | | |
234 | 258 | | |
235 | 259 | | |
236 | 260 | | |
237 | 261 | | |
238 | | - | |
| 262 | + | |
239 | 263 | | |
240 | 264 | | |
241 | 265 | | |
242 | | - | |
| 266 | + | |
243 | 267 | | |
244 | 268 | | |
245 | 269 | | |
| |||
307 | 331 | | |
308 | 332 | | |
309 | 333 | | |
310 | | - | |
| 334 | + | |
311 | 335 | | |
312 | 336 | | |
313 | 337 | | |
314 | 338 | | |
315 | 339 | | |
316 | | - | |
| 340 | + | |
317 | 341 | | |
318 | 342 | | |
319 | 343 | | |
320 | 344 | | |
321 | | - | |
| 345 | + | |
322 | 346 | | |
323 | 347 | | |
324 | 348 | | |
| |||
0 commit comments