Skip to content

feat(bigquery-jdbc): implement TypeRegistry and TypeDescriptor - #13947

Open
Neenu1995 wants to merge 9 commits into
mainfrom
feat/type-registry-phase-1
Open

feat(bigquery-jdbc): implement TypeRegistry and TypeDescriptor#13947
Neenu1995 wants to merge 9 commits into
mainfrom
feat/type-registry-phase-1

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

No description provided.

@Neenu1995
Neenu1995 requested review from a team as code owners July 29, 2026 16:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces BigQueryTypeRegistry and TypeDescriptor to handle bidirectional type mapping and coercion between JDBC, Java, and BigQuery. The review feedback highlights several key issues and improvements: a potential runtime exception in the TIMESTAMP coercer for Java 8 date/time types, precision loss when converting Number to BigDecimal using doubleValue(), and unused code involving DESCRIPTORS_BY_ORDINAL. Additionally, suggestions were made to expand conversion support for java.util.Date and Gson's JsonElement to make the registry more robust.

*/
final class BigQueryTypeRegistry {

private static final TypeDescriptor<?>[] DESCRIPTORS_BY_ORDINAL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The DESCRIPTORS_BY_ORDINAL array is declared and populated but never read anywhere in the class. It should be removed to clean up unused code.

Comment on lines +49 to +55
int maxOrdinal = 0;
for (StandardSQLTypeName type : StandardSQLTypeName.values()) {
if (type.ordinal() > maxOrdinal) {
maxOrdinal = type.ordinal();
}
}
DESCRIPTORS_BY_ORDINAL = new TypeDescriptor<?>[maxOrdinal + 1];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The initialization of DESCRIPTORS_BY_ORDINAL is unused and can be removed.

Comment on lines +261 to +263
if (DESCRIPTORS_BY_ORDINAL[descriptor.getBqType().ordinal()] == null) {
DESCRIPTORS_BY_ORDINAL[descriptor.getBqType().ordinal()] = descriptor;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The registration of DESCRIPTORS_BY_ORDINAL is unused and can be removed.

@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a type mapping and coercion system between JDBC, Java, and BigQuery types, consisting of BigQueryTimezoneUtility, BigQueryTypeRegistry, and TypeDescriptor. The feedback highlights several key areas for improvement: resolving a potential parsing bug in boxTimestamp for strings with timezone offsets, using legacy Calendar manipulation for java.sql.Time to handle DST correctly, preserving millisecond precision when converting to LocalTime, and removing the unused DESCRIPTORS_BY_ORDINAL array.


/**
* Returns the exact BigQuery StandardSQLTypeName for a given Java class. If no mapping is found,
* returns StandardSQLTypeName.STRING as a fallback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need a fallback? Shouldn't we implement all possible conversions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We need the STRING fallback to preserve backward compatibility and prevent crashing legacy applications that rely on the driver's old behavior of silently stringifying unmapped objects so the BigQuery backend can parse them.

@Neenu1995
Neenu1995 requested a review from logachev July 30, 2026 16:59
@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gcprun

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