Skip to content

Normalize TIMESTAMP_NTZ to TIMESTAMP in Thrift path for metadata consistency - #1182

Merged
gopalldb merged 15 commits into
databricks:mainfrom
gopalldb:sea-roll
Jan 19, 2026
Merged

gopalldb merged 15 commits into
databricks:mainfrom
gopalldb:sea-roll

Conversation

@gopalldb

Copy link
Copy Markdown
Collaborator

Summary

This PR adds TIMESTAMP_NTZ normalization in the Thrift path to ensure consistent metadata behavior across both SEA and Thrift API paths.

Background

PR #1177 moved Arrow metadata extraction earlier in the processing pipeline, which exposed an inconsistency: the Thrift path started returning the correct "TIMESTAMP_NTZ" from server metadata, while the SEA path was already normalizing it to "TIMESTAMP" for backward compatibility.

Changes

  • Added TIMESTAMP_NTZ → TIMESTAMP normalization in DatabricksResultSetMetaData.java Thrift constructor (lines 205-208)
  • This brings Thrift path behavior in line with existing SEA path normalization
  • Fixes test failure in PreparedStatementIntegrationTests.testGetMetaData_NoResultSet

Testing

  • ✅ Local test run: PreparedStatementIntegrationTests.testGetMetaData_NoResultSet passes
  • ✅ Metadata now consistent before and after executeQuery() for TIMESTAMP_NTZ columns
  • ✅ Both SEA and Thrift paths return "TIMESTAMP" for TIMESTAMP_NTZ columns

Related

🤖 Generated with Claude Code

gopalldb and others added 15 commits January 9, 2026 15:25
Problem:
The custom user agent from 'useragententry' parameter was not included
in the connector service feature flags request. This happened because
UserAgentManager.setUserAgent() was setting the custom user agent AFTER
triggering the client type determination (which fetches feature flags).

Root Cause:
In UserAgentManager.setUserAgent():
- Line 28 called getClientUserAgent() which triggered getClientType()
- getClientType() called DatabricksDriverFeatureFlagsContextFactory.getInstance()
- Feature flags were fetched WITHOUT the custom user agent
- Custom user agent was set afterwards (too late)

Solution:
Reordered UserAgentManager.setUserAgent() to set custom user agent
BEFORE calling getClientUserAgent():
1. Set base product
2. Set custom user agent FIRST via UserAgent.withOtherInfo()
3. THEN call getClientUserAgent() which triggers feature flags fetch

Result:
Custom user agent is now included in ALL HTTP requests including
the connector service request.

Testing:
- Added testCustomUserAgentIncludedBeforeClientTypeEvaluation() test
- Updated existing tests to be version-agnostic
- All UserAgentManagerTest tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Added buildUserAgentForConnectorService() to build separate UA for connector service
- Modified DatabricksDriverFeatureFlagsContext to use new method for feature flag requests
- Maintains proper order for backend requests: base -> client type -> custom
- Custom UA now included in both connector service and backend requests without circular dependency
- Updated test to verify proper order: client type before custom user agent
- Added DEBUG log when SEA circuit breaker is open
- Shows time remaining until circuit closes
- Helps users understand THRIFT fallback due to 429 rate limits
- Created parseCustomerUserAgent() helper method
- Eliminates code duplication in setUserAgent() and buildUserAgentForConnectorService()
- Added try-catch protection for UserAgent.sanitize() calls
- All tests pass (7/7)
Changed catch blocks to catch IllegalArgumentException instead of generic
Exception when calling UserAgent.sanitize(). This is the specific exception
thrown by sanitize() when it encounters invalid characters in user agent strings.

Addresses PR review comment.
Problem:
When executing queries that return 0 rows (e.g., WHERE 1=0), complex
types (ARRAY, MAP, STRUCT) showed only generic type names instead of
detailed type information:
- Before: ARRAY, MAP, STRUCT
- Expected: ARRAY<INT>, MAP<STRING,STRING>, STRUCT<field: TYPE>

Root Cause:
Arrow field metadata was only extracted inside the while(loadNextBatch())
loop. For queries with 0 rows, no batches are loaded, so the loop never
executes and metadata is never extracted.

Solution:
Extract metadata from VectorSchemaRoot immediately after obtaining it,
before the loadNextBatch() loop. The Arrow IPC format always sends the
schema message first (before any record batches), so field metadata is
available even when there are 0 rows.

Impact:
- Fixes metadata availability for both SQL Exec API and Thrift Server
- All 2,692 unit tests pass
- Verified with queries returning 0 rows - metadata now correctly shows
  detailed type information for complex types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Add testMetadataExtractionWithZeroRows() to ArrowResultChunkTest to
verify that Arrow field metadata is correctly extracted from
VectorSchemaRoot even when there are 0 rows in the result set.

This test complements the fix in AbstractArrowResultChunk.java where
metadata extraction was moved before the loadNextBatch() loop to
ensure metadata is available for queries returning 0 rows (e.g.,
WHERE 1=0).

Test coverage:
- Creates Arrow file with schema metadata but 0 rows
- Verifies getArrowMetadata() returns non-null metadata
- Verifies metadata contains detailed type information
  (ARRAY<INT>, MAP<STRING,STRING>) even with 0 rows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
The SEA path already converts TIMESTAMP_NTZ to TIMESTAMP for backward
compatibility. This change applies the same normalization in the Thrift
path to ensure consistent metadata behavior across both API paths.

This fixes test failures in PreparedStatementIntegrationTests that were
exposed when Arrow metadata extraction was moved earlier in the processing
pipeline.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
? arrowMetadata.get(columnIndex)
: getTypeTextFromTypeDesc(columnDesc.getTypeDesc());

// Normalize TIMESTAMP_NTZ to TIMESTAMP for consistency with SEA path

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add a link in comments to the SEA path where it is being done

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the same file :)

@gopalldb
gopalldb merged commit 87b5527 into databricks:main Jan 19, 2026
12 of 13 checks passed
msrathore-db added a commit to msrathore-db/databricks-jdbc that referenced this pull request Jun 30, 2026
ResultSetMetaData.getColumnTypeName() returned "TIMESTAMP" for
TIMESTAMP_NTZ columns (e.g. SELECT MIN(ntz_col) ...), a regression from
3.0.7. The SEA path normalized the type text to "TIMESTAMP" since launch,
and databricks#1182 added the same normalization to the Thrift path; combined with
the default protocol moving to SEA, every default connection lost the NTZ
type name.

The driver now preserves "TIMESTAMP_NTZ" across the SEA, Thrift, and
describe-query metadata paths by default. getColumnType() continues to
report java.sql.Types.TIMESTAMP, since TIMESTAMP_NTZ is a timestamp
without timezone.

Because the legacy (Simba) driver reports "TIMESTAMP" for NTZ columns,
the previous behavior is preserved behind a new connection property,
EnableTimestampNtzTypeName (default 1). Set EnableTimestampNtzTypeName=0
to restore the legacy/Simba type name.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <[email protected]>
msrathore-db added a commit that referenced this pull request Jul 7, 2026
## Description

Fixes
[#1495](#1495):
`ResultSetMetaData.getColumnTypeName()` returns `TIMESTAMP` instead of
`TIMESTAMP_NTZ` for `TIMESTAMP_NTZ` columns (e.g. `SELECT MIN(ntz_col)
...`). This was a regression from 3.0.7.

**Root cause.** The driver rewrites the `TIMESTAMP_NTZ` type text to
`TIMESTAMP` in three metadata-construction paths in
`DatabricksResultSetMetaData`:
- The **SEA** path has done this since the OSS launch
(`columnInfo.setTypeText(TIMESTAMP)`), to "maintain parity with thrift
output".
- The **Thrift** path got the same normalization in #1182 ("for
consistency with SEA path"), first released in v3.2.1.
- The **describe-query** path also normalized.

Because the `ColumnInfoTypeName` SDK enum has no `TIMESTAMP_NTZ` value,
`getTypeName()` is `null` for NTZ; the code correctly maps it to the
`TIMESTAMP` enum (so `getColumnType()` → `Types.TIMESTAMP`), but it also
clobbered the human-readable `typeText` that `getColumnTypeName()`
returns. Combined with the effective default protocol moving to SEA,
every default connection lost the NTZ type name. In 3.0.7 the default
was Thrift, which did not normalize, so it returned `TIMESTAMP_NTZ`.

**Fix.** The driver now **preserves `TIMESTAMP_NTZ`** across all three
paths by default. `getColumnType()` still reports
`java.sql.Types.TIMESTAMP`, since `TIMESTAMP_NTZ` is a timestamp without
timezone.

The legacy (Simba) driver reports `TIMESTAMP` for NTZ columns, so the
previous behavior is preserved behind a new connection property:

| `EnableTimestampNtzTypeName` | `getColumnTypeName()` for NTZ |
`getColumnType()` |
|---|---|---|
| `1` (default) | `TIMESTAMP_NTZ` | `Types.TIMESTAMP` |
| `0` (legacy / Simba parity) | `TIMESTAMP` | `Types.TIMESTAMP` |

## Testing

Verified live against a SQL warehouse with `SELECT MIN(ntz_col),
MAX(ntz_col), ntz_col ... GROUP BY ntz_col`:

| Path | Default (`=1`) | `EnableTimestampNtzTypeName=0` |
|---|---|---|
| SEA (default) | `TIMESTAMP_NTZ` | `TIMESTAMP` |
| Thrift (`usethriftclient=1`) | `TIMESTAMP_NTZ` | `TIMESTAMP` |

For reference, the legacy Simba 2.8.1 driver returns `TIMESTAMP` for the
same query — which the `=0` mode matches.

Unit/integration tests (`mvn -pl jdbc-core test`):
- `DatabricksResultSetMetaDataTest` — updated NTZ assertions for the new
default; added `testColumnsWithTimestampNTZ_legacyTypeNameDisabled`
covering `=0`.
- `PreparedStatementIntegrationTests#testGetMetaData_NoResultSet` (the
fakeservice test #1182 was tied to), `DatabricksConnectionContextTest`,
`DatabricksTypeUtilTest` all pass. Spotless clean.

## Additional Notes to the Reviewer

This intentionally re-scopes the normalization introduced in #1182
behind the new `EnableTimestampNtzTypeName` flag rather than removing it
— the legacy behavior is still reachable via
`EnableTimestampNtzTypeName=0`. The metadata stays internally consistent
(pre-execute vs post-execute) in either mode, which is what
`testGetMetaData_NoResultSet` guards. cc @gopalldb (author of #1182).

This pull request and its description were written by Isaac.

---------

Signed-off-by: Madhavendra Rathore <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants