feat(bigquery-jdbc): support picosecond timestamps in Arrow Storage Read API and nested types - #14332
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for picosecond timestamp precision when retrieving Arrow data in the BigQuery JDBC driver. It propagates the enableTimestampPicos flag through BigQueryArrowArray, BigQueryArrowResultSet, and BigQueryArrowStruct, configures the Arrow serialization options in BigQueryStatement, and formats timestamps with high precision when enabled. Comprehensive unit tests are also added to verify this behavior. The review feedback suggests improving the robustness of getRangeElementType in BigQueryArrowResultSet by standardizing the type name to uppercase and adding a null check to prevent a potential NullPointerException when range bounds are unbounded.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for picosecond timestamp precision when reading Arrow data in the BigQuery JDBC driver. It propagates the 'enableTimestampPicos' flag across Arrow-related classes (BigQueryArrowArray, BigQueryArrowResultSet, BigQueryArrowStruct), configures ArrowSerializationOptions in BigQueryStatement, and updates BigQueryTemporalUtility to format timestamps with up to 12 fractional digits. The review feedback suggests making the range element type resolution more robust by converting the type string to uppercase before parsing, and warns about potential memory leaks in the unit tests due to unclosed RootAllocator and VectorSchemaRoot instances.
…ead API and nested types
0fdf436 to
7235227
Compare
| this.toIndexExclusive = toIndexExclusive; | ||
| this.nestedRowIndex = fromIndex - 1; | ||
| this.ownedTask = ownedTask; | ||
| this.enableTimestampPicos = |
There was a problem hiding this comment.
In what instances statement can be null? Feels weird that we explicitly pass enableTimestampPicos, but instantly override it. Should it be responsibility of the object instantiating this?
There was a problem hiding this comment.
So, statement can be null in getNestedResultSet(...) (used when an Array column is unnested into a child ResultSet via Array.getResultSet(), where no statement object is present) and in the no-arg constructor.
But yeah I guess doing it in constructor is awkward, moved it to of(...) method
| value = LocalDate.ofEpochDay(((Integer) value).longValue()); | ||
| } | ||
| } | ||
| if (value instanceof Text) { |
There was a problem hiding this comment.
Why special case for Text here? Is it related to picoseconds in some way?
There was a problem hiding this comment.
Yes, so in Storage Read API:
- standard timestamps (<= 6 digits) are transmitted in Arrow as 64-bit integers (
TimeStampMicroVector). - picosecond timestamps are transmitted as as
VarCharVectors
So, calling VarCharVector.getObject() returns an org.apache.arrow.vector.util.Text and we convert that to String
b/544839155
This PR enables picosecond precision (
TIMESTAMP(12)) support across the BigQuery Storage Read API (Arrow stream) and nested data structures (ARRAY,STRUCT, andRANGE) whenEnableTimestampPicos=true.Key Changes
TableReadOptions.arrowSerializationOptionswithTIMESTAMP_PRECISION_PICOSinBigQueryStatementwhenEnableTimestampPicosis active.enableTimestampPicosintoBigQueryArrowResultSet, formatting picosecond timestamps directly to 12 fractional digits for column retrieval.Textinstances toStringacross hot paths to prevent downstreamBigQueryTypeRegistryconversion failures.RANGEand nestedRANGEbounds using schema-derived element types and precision flags.BigQueryArrowArrayandBigQueryArrowStruct.getTargetClass()inBigQueryArrowArrayto returnString.classwhen picoseconds are enabled, preventingArray.newInstancemismatch exceptions.BigQueryArrowResultSet,BigQueryArrowArrayOfPrimitives,BigQueryArrowStruct, andBigQueryStatement.