Skip to content

Commit

Permalink
fix: Change BQ type DATE to map to proto type int32
Browse files Browse the repository at this point in the history
  • Loading branch information
allenc3 committed Jul 9, 2020
1 parent 65dd01d commit e70a5f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Expand Up @@ -44,7 +44,7 @@ public class BQTableSchemaToProtoDescriptor {
new ImmutableMap.Builder<Table.TableFieldSchema.Type, FieldDescriptorProto.Type>()
.put(Table.TableFieldSchema.Type.BOOL, FieldDescriptorProto.Type.TYPE_BOOL)
.put(Table.TableFieldSchema.Type.BYTES, FieldDescriptorProto.Type.TYPE_BYTES)
.put(Table.TableFieldSchema.Type.DATE, FieldDescriptorProto.Type.TYPE_INT64)
.put(Table.TableFieldSchema.Type.DATE, FieldDescriptorProto.Type.TYPE_INT32)
.put(Table.TableFieldSchema.Type.DATETIME, FieldDescriptorProto.Type.TYPE_INT64)
.put(Table.TableFieldSchema.Type.DOUBLE, FieldDescriptorProto.Type.TYPE_DOUBLE)
.put(Table.TableFieldSchema.Type.GEOGRAPHY, FieldDescriptorProto.Type.TYPE_BYTES)
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class BQTableSchemaToProtoDescriptorTest {
new ImmutableMap.Builder<Table.TableFieldSchema.Type, Descriptor>()
.put(Table.TableFieldSchema.Type.BOOL, BoolType.getDescriptor())
.put(Table.TableFieldSchema.Type.BYTES, BytesType.getDescriptor())
.put(Table.TableFieldSchema.Type.DATE, Int64Type.getDescriptor())
.put(Table.TableFieldSchema.Type.DATE, Int32Type.getDescriptor())
.put(Table.TableFieldSchema.Type.DATETIME, Int64Type.getDescriptor())
.put(Table.TableFieldSchema.Type.DOUBLE, DoubleType.getDescriptor())
.put(Table.TableFieldSchema.Type.GEOGRAPHY, BytesType.getDescriptor())
Expand Down Expand Up @@ -160,6 +160,12 @@ public void testStructComplex() throws Exception {
.setMode(Table.TableFieldSchema.Mode.REPEATED)
.setName("test_double")
.build();
final Table.TableFieldSchema test_date =
Table.TableFieldSchema.newBuilder()
.setType(Table.TableFieldSchema.Type.DATE)
.setMode(Table.TableFieldSchema.Mode.REQUIRED)
.setName("test_date")
.build();
final Table.TableFieldSchema ComplexLvl2 =
Table.TableFieldSchema.newBuilder()
.setType(Table.TableFieldSchema.Type.STRUCT)
Expand All @@ -182,8 +188,9 @@ public void testStructComplex() throws Exception {
.addFields(2, test_bytes)
.addFields(3, test_bool)
.addFields(4, test_double)
.addFields(5, ComplexLvl1)
.addFields(6, ComplexLvl2)
.addFields(5, test_date)
.addFields(6, ComplexLvl1)
.addFields(7, ComplexLvl2)
.build();
final Descriptor descriptor =
BQTableSchemaToProtoDescriptor.ConvertBQTableSchemaToProtoDescriptor(tableSchema);
Expand Down
5 changes: 3 additions & 2 deletions google-cloud-bigquerystorage/src/test/proto/jsonTest.proto
Expand Up @@ -8,8 +8,9 @@ message ComplexRoot {
required bytes test_bytes = 3;
optional bool test_bool = 4;
repeated double test_double = 5;
required ComplexLvl1 complexLvl1 = 6;
required ComplexLvl2 complexLvl2 = 7;
required int32 test_date = 6;
required ComplexLvl1 complexLvl1 = 7;
required ComplexLvl2 complexLvl2 = 8;
}

message ComplexLvl1 {
Expand Down

0 comments on commit e70a5f4

Please sign in to comment.