1616
1717package com .google .cloud .bigquery .storage .v1 .it ;
1818
19+ import static com .google .cloud .bigquery .storage .v1 .it .util .Helper .TIMESTAMP_COLUMN_NAME ;
20+ import static com .google .cloud .bigquery .storage .v1 .it .util .Helper .TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME ;
1921import static com .google .common .truth .Truth .assertThat ;
2022import static org .junit .Assert .assertEquals ;
2123import static org .junit .Assert .assertFalse ;
@@ -123,19 +125,19 @@ public class ITBigQueryStorageWriteClientTest {
123125 // The data will be padded to fit into the higher precision columns.
124126 public static final Object [][] INPUT_ARROW_WRITE_TIMESTAMPS =
125127 new Object [][] {
126- {1735734896123456L /* 2025-01-01T12:34:56.123456Z */ , 1735734896123456789L },
127- {1580646896123456L /* 2020-02-02T12:34:56.123456Z */ , 1580646896123456789L },
128- {636467696123456L /* 1990-03-03T12:34:56.123456Z */ , 636467696123456789L },
129- {165846896123456L /* 1975-04-04T12:34:56.123456Z */ , 165846896123456789L }
128+ {1735734896123456L /* 2025-01-01T12:34:56.123456Z */ , 1735734896123456789L },
129+ {1580646896123456L /* 2020-02-02T12:34:56.123456Z */ , 1580646896123456789L },
130+ {636467696123456L /* 1990-03-03T12:34:56.123456Z */ , 636467696123456789L },
131+ {165846896123456L /* 1975-04-04T12:34:56.123456Z */ , 165846896123456789L }
130132 };
131133
132134 // Arrow's higher precision column is padded with extra 0's.
133135 public static final Object [][] EXPECTED_ARROW_WRITE_TIMESTAMPS =
134136 new Object [][] {
135- {1735734896123456L /* 2025-01-01T12:34:56.123456Z */ , "2025-01-01T12:34:56.123456789000Z" },
136- {1580646896123456L /* 2020-02-02T12:34:56.123456Z */ , "2020-02-02T12:34:56.123456789000Z" },
137- {636467696123456L /* 1990-03-03T12:34:56.123456Z */ , "1990-03-03T12:34:56.123456789000Z" },
138- {165846896123456L /* 1975-04-04T12:34:56.123456Z */ , "1975-04-04T12:34:56.123456789000Z" }
137+ {1735734896123456L /* 2025-01-01T12:34:56.123456Z */ , "2025-01-01T12:34:56.123456789000Z" },
138+ {1580646896123456L /* 2020-02-02T12:34:56.123456Z */ , "2020-02-02T12:34:56.123456789000Z" },
139+ {636467696123456L /* 1990-03-03T12:34:56.123456Z */ , "1990-03-03T12:34:56.123456789000Z" },
140+ {165846896123456L /* 1975-04-04T12:34:56.123456Z */ , "1975-04-04T12:34:56.123456789000Z" }
139141 };
140142
141143 public static class StringWithSecondsNanos {
@@ -2296,14 +2298,12 @@ public void testLargeRequest() throws IOException, InterruptedException, Executi
22962298
22972299 @ Test
22982300 public void timestamp_arrowWrite () throws IOException {
2299- String timestampFieldName = "timestamp" ;
2300- String timestampHigherPrecisionFieldName = "timestampHigherPrecision" ;
23012301 com .google .cloud .bigquery .Schema bigqueryTableSchema =
23022302 com .google .cloud .bigquery .Schema .of (
2303- Field .newBuilder (timestampFieldName , StandardSQLTypeName .TIMESTAMP )
2303+ Field .newBuilder (TIMESTAMP_COLUMN_NAME , StandardSQLTypeName .TIMESTAMP )
23042304 .setMode (Mode .NULLABLE )
23052305 .build (),
2306- Field .newBuilder (timestampHigherPrecisionFieldName , StandardSQLTypeName .TIMESTAMP )
2306+ Field .newBuilder (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME , StandardSQLTypeName .TIMESTAMP )
23072307 .setMode (Mode .NULLABLE )
23082308 .setTimestampPrecision (12L )
23092309 .build ());
@@ -2318,13 +2318,13 @@ public void timestamp_arrowWrite() throws IOException {
23182318 List <org .apache .arrow .vector .types .pojo .Field > fields =
23192319 ImmutableList .of (
23202320 new org .apache .arrow .vector .types .pojo .Field (
2321- timestampFieldName ,
2321+ TIMESTAMP_COLUMN_NAME ,
23222322 FieldType .nullable (
23232323 new ArrowType .Timestamp (
23242324 org .apache .arrow .vector .types .TimeUnit .MICROSECOND , "UTC" )),
23252325 null ),
23262326 new org .apache .arrow .vector .types .pojo .Field (
2327- timestampHigherPrecisionFieldName ,
2327+ TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME ,
23282328 FieldType .nullable (
23292329 new ArrowType .Timestamp (
23302330 org .apache .arrow .vector .types .TimeUnit .NANOSECOND , "UTC" )),
@@ -2340,9 +2340,9 @@ public void timestamp_arrowWrite() throws IOException {
23402340 .build ()) {
23412341 try (VectorSchemaRoot root = VectorSchemaRoot .create (arrowSchema , allocator )) {
23422342 TimeStampMicroTZVector timestampVector =
2343- (TimeStampMicroTZVector ) root .getVector (timestampFieldName );
2343+ (TimeStampMicroTZVector ) root .getVector (TIMESTAMP_COLUMN_NAME );
23442344 TimeStampNanoTZVector timestampHigherPrecisionVector =
2345- (TimeStampNanoTZVector ) root .getVector (timestampHigherPrecisionFieldName );
2345+ (TimeStampNanoTZVector ) root .getVector (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME );
23462346 timestampVector .allocateNew (numRows );
23472347 timestampHigherPrecisionVector .allocateNew (numRows );
23482348
@@ -2370,30 +2370,29 @@ public void timestamp_arrowWrite() throws IOException {
23702370 ServiceOptions .getDefaultProjectId (), DATASET , tableName );
23712371 List <GenericData .Record > rows = Helper .readAllRows (readClient , parentProjectId , table , null );
23722372 List <Long > timestamps =
2373- rows .stream ().map (x -> (Long ) x .get (timestampFieldName )).collect (Collectors .toList ());
2373+ rows .stream ().map (x -> (Long ) x .get (TIMESTAMP_COLUMN_NAME )).collect (Collectors .toList ());
23742374 List <String > timestampHigherPrecision =
23752375 rows .stream ()
2376- .map (x -> x .get (timestampHigherPrecisionFieldName ).toString ())
2376+ .map (x -> x .get (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME ).toString ())
23772377 .collect (Collectors .toList ());
2378- assertEquals (timestamps .size (), Helper .EXPECTED_TIMESTAMPS .length );
2379- assertEquals (timestampHigherPrecision .size (), Helper .EXPECTED_TIMESTAMPS .length );
2378+ assertEquals (timestamps .size (), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION .length );
2379+ assertEquals (
2380+ timestampHigherPrecision .size (), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION .length );
23802381 for (int i = 0 ; i < timestampHigherPrecision .size (); i ++) {
2381- assertEquals (timestamps .get (i ), Helper .EXPECTED_TIMESTAMPS [i ][0 ]);
2382+ assertEquals (timestamps .get (i ), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION [i ][0 ]);
23822383 assertEquals (timestampHigherPrecision .get (i ), EXPECTED_ARROW_WRITE_TIMESTAMPS [i ][1 ]);
23832384 }
23842385 }
23852386
23862387 @ Test
23872388 public void timestamp_protobufWrite ()
23882389 throws IOException , DescriptorValidationException , InterruptedException {
2389- String timestampFieldName = "timestamp" ;
2390- String timestampHigherPrecisionFieldName = "timestampHigherPrecision" ;
23912390 com .google .cloud .bigquery .Schema bqTableSchema =
23922391 com .google .cloud .bigquery .Schema .of (
2393- Field .newBuilder (timestampFieldName , StandardSQLTypeName .TIMESTAMP )
2392+ Field .newBuilder (TIMESTAMP_COLUMN_NAME , StandardSQLTypeName .TIMESTAMP )
23942393 .setMode (Mode .NULLABLE )
23952394 .build (),
2396- Field .newBuilder (timestampHigherPrecisionFieldName , StandardSQLTypeName .TIMESTAMP )
2395+ Field .newBuilder (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME , StandardSQLTypeName .TIMESTAMP )
23972396 .setMode (Mode .NULLABLE )
23982397 .setTimestampPrecision (12L )
23992398 .build ());
@@ -2406,13 +2405,13 @@ public void timestamp_protobufWrite()
24062405
24072406 TableFieldSchema testTimestamp =
24082407 TableFieldSchema .newBuilder ()
2409- .setName (timestampFieldName )
2408+ .setName (TIMESTAMP_COLUMN_NAME )
24102409 .setType (TableFieldSchema .Type .TIMESTAMP )
24112410 .setMode (TableFieldSchema .Mode .NULLABLE )
24122411 .build ();
24132412 TableFieldSchema testTimestampHighPrecision =
24142413 TableFieldSchema .newBuilder ()
2415- .setName (timestampHigherPrecisionFieldName )
2414+ .setName (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME )
24162415 .setTimestampPrecision (Int64Value .newBuilder ().setValue (12 ).build ())
24172416 .setType (TableFieldSchema .Type .TIMESTAMP )
24182417 .setMode (TableFieldSchema .Mode .NULLABLE )
@@ -2429,8 +2428,8 @@ public void timestamp_protobufWrite()
24292428 JSONArray jsonArray = new JSONArray ();
24302429 for (Object [] timestampData : Helper .INPUT_TIMESTAMPS ) {
24312430 JSONObject row = new JSONObject ();
2432- row .put (timestampFieldName , timestampData [0 ]);
2433- row .put (timestampHigherPrecisionFieldName , timestampData [1 ]);
2431+ row .put (TIMESTAMP_COLUMN_NAME , timestampData [0 ]);
2432+ row .put (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME , timestampData [1 ]);
24342433 jsonArray .put (row );
24352434 }
24362435 ApiFuture <AppendRowsResponse > future = jsonStreamWriter .append (jsonArray );
@@ -2443,16 +2442,18 @@ public void timestamp_protobufWrite()
24432442 ServiceOptions .getDefaultProjectId (), DATASET , tableName );
24442443 List <GenericData .Record > rows = Helper .readAllRows (readClient , parentProjectId , table , null );
24452444 List <Long > timestamps =
2446- rows .stream ().map (x -> (Long ) x .get (timestampFieldName )).collect (Collectors .toList ());
2445+ rows .stream ().map (x -> (Long ) x .get (TIMESTAMP_COLUMN_NAME )).collect (Collectors .toList ());
24472446 List <String > timestampHigherPrecision =
24482447 rows .stream ()
2449- .map (x -> x .get (timestampHigherPrecisionFieldName ).toString ())
2448+ .map (x -> x .get (TIMESTAMP_HIGHER_PRECISION_COLUMN_NAME ).toString ())
24502449 .collect (Collectors .toList ());
2451- assertEquals (timestamps .size (), Helper .EXPECTED_TIMESTAMPS .length );
2452- assertEquals (timestampHigherPrecision .size (), Helper .EXPECTED_TIMESTAMPS .length );
2450+ assertEquals (timestamps .size (), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION .length );
2451+ assertEquals (
2452+ timestampHigherPrecision .size (), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION .length );
24532453 for (int i = 0 ; i < timestamps .size (); i ++) {
2454- assertEquals (timestamps .get (i ), Helper .EXPECTED_TIMESTAMPS [i ][0 ]);
2455- assertEquals (timestampHigherPrecision .get (i ), Helper .EXPECTED_TIMESTAMPS [i ][1 ]);
2454+ assertEquals (timestamps .get (i ), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION [i ][0 ]);
2455+ assertEquals (
2456+ timestampHigherPrecision .get (i ), Helper .EXPECTED_TIMESTAMPS_ISO_HIGHER_PRECISION [i ][1 ]);
24562457 }
24572458 }
24582459}
0 commit comments