Skip to content

refactor(jdbc): migrate Read Path to BigQueryTypeRegistry - #14063

Open
Neenu1995 wants to merge 4 commits into
jdbc-phase4-registry-integrationfrom
jdbc-phase4-registry-read-path
Open

refactor(jdbc): migrate Read Path to BigQueryTypeRegistry#14063
Neenu1995 wants to merge 4 commits into
jdbc-phase4-registry-integrationfrom
jdbc-phase4-registry-read-path

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

This PR migrates the BigQuery JDBC read-path implementations (Arrow and Json) to utilize the newly introduced BigQueryTypeRegistry for unified type lookups and high-performance coercion.

@Neenu1995
Neenu1995 requested review from a team as code owners August 13, 2026 01:15

@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 refactors type conversion and mapping across the BigQuery JDBC driver by replacing BigQueryTypeCoercer and BigQueryJdbcTypeMappings with BigQueryTypeRegistry. This change requires several methods to declare throwing SQLException. The review feedback suggests keeping the parameter type as FieldValue in BigQueryJsonStruct to avoid redundant downcasts, catching Exception instead of RuntimeException in BigQueryBaseResultSet to properly handle SQLException during conversion, and removing redundant blank lines in BigQueryTypeRegistry.

Comment on lines +68 to 80
private Object getValue(Field currentSchema, Object currentValue) throws SQLException {
LOG.finestTrace("getValue");
if (isArray(currentSchema)) {
return new BigQueryJsonArray(currentSchema, currentValue, this.LOG.getJsonArrayLogger());
return new BigQueryJsonArray(
currentSchema, (FieldValue) currentValue, this.LOG.getJsonArrayLogger());
} else if (isStruct(currentSchema)) {
return new BigQueryJsonStruct(
currentSchema.getSubFields(), currentValue, this.LOG.getJsonStructLogger());
currentSchema.getSubFields(), (FieldValue) currentValue, this.LOG.getJsonStructLogger());
} else {
Class<?> targetClass =
BigQueryJdbcTypeMappings.standardSQLToJavaTypeMapping.get(
currentSchema.getType().getStandardType());
return BIGQUERY_TYPE_COERCER.coerceTo(targetClass, currentValue, this.LOG);
return BigQueryTypeRegistry.convert(
currentValue, currentSchema.getType().getStandardType(), null);
}
}

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

By keeping the parameter type of currentValue as FieldValue (as it was originally), we can avoid the need for explicit downcasts to FieldValue on lines 72 and 75. Since FieldValue is an Object, it can still be passed directly to BigQueryTypeRegistry.convert without any issues.

Suggested change
private Object getValue(Field currentSchema, Object currentValue) throws SQLException {
LOG.finestTrace("getValue");
if (isArray(currentSchema)) {
return new BigQueryJsonArray(currentSchema, currentValue, this.LOG.getJsonArrayLogger());
return new BigQueryJsonArray(
currentSchema, (FieldValue) currentValue, this.LOG.getJsonArrayLogger());
} else if (isStruct(currentSchema)) {
return new BigQueryJsonStruct(
currentSchema.getSubFields(), currentValue, this.LOG.getJsonStructLogger());
currentSchema.getSubFields(), (FieldValue) currentValue, this.LOG.getJsonStructLogger());
} else {
Class<?> targetClass =
BigQueryJdbcTypeMappings.standardSQLToJavaTypeMapping.get(
currentSchema.getType().getStandardType());
return BIGQUERY_TYPE_COERCER.coerceTo(targetClass, currentValue, this.LOG);
return BigQueryTypeRegistry.convert(
currentValue, currentSchema.getType().getStandardType(), null);
}
}
private Object getValue(Field currentSchema, FieldValue currentValue) throws SQLException {
LOG.finestTrace("getValue");
if (isArray(currentSchema)) {
return new BigQueryJsonArray(
currentSchema, currentValue, this.LOG.getJsonArrayLogger());
} else if (isStruct(currentSchema)) {
return new BigQueryJsonStruct(
currentSchema.getSubFields(), currentValue, this.LOG.getJsonStructLogger());
} else {
return BigQueryTypeRegistry.convert(
currentValue, currentSchema.getType().getStandardType(), null);
}
}

Comment on lines 301 to 303
} catch (RuntimeException e) {
throw createCoercionException(columnIndex, type, e);
}

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

Since BigQueryTypeRegistry.convert throws SQLException, catching only RuntimeException here will bypass this catch block when a conversion error occurs. Catching Exception ensures that both RuntimeException and SQLException are caught and properly wrapped with the column context via createCoercionException.

Suggested change
} catch (RuntimeException e) {
throw createCoercionException(columnIndex, type, e);
}
} catch (Exception e) {
throw createCoercionException(columnIndex, type, e);
}

Comment on lines 410 to +416
return String.class;

}
return DESCRIPTORS_BY_ORDINAL[ordinal].getDefaultJavaClass();
}


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

Remove the redundant blank lines introduced inside the if block and after the method to keep the code clean and consistent with standard formatting.

Suggested change
return String.class;
}
return DESCRIPTORS_BY_ORDINAL[ordinal].getDefaultJavaClass();
}
return String.class;
}
return DESCRIPTORS_BY_ORDINAL[ordinal].getDefaultJavaClass();
}

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.

1 participant