Skip to content

Commit

Permalink
Possible fix for fields starting with numerics
Browse files Browse the repository at this point in the history
  • Loading branch information
istreeter committed May 16, 2024
1 parent c1951fe commit b863ac7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object BigQuerySchemaUtils {

def fieldsMissingFromDescriptor(tableDescriptor: Descriptors.Descriptor, bqFields: FieldList): Boolean =
bqFields.asScala.exists { field =>
Option(tableDescriptor.findFieldByName(field.getName)) match {
tableDescriptor.getFields.asScala.find(_.getJsonName === field.getName) match {
case Some(fieldDescriptor) =>
val nullableMismatch = fieldDescriptor.isRequired && (field.getMode === BQField.Mode.NULLABLE)
nullableMismatch || nestedFieldMissingFromDescriptor(fieldDescriptor, field)
Expand All @@ -45,7 +45,7 @@ object BigQuerySchemaUtils {

def alterTableRequired(tableDescriptor: Descriptors.Descriptor, ddlFields: Vector[Field]): Vector[Field] =
ddlFields.filter { field =>
Option(tableDescriptor.findFieldByName(field.name)) match {
tableDescriptor.getFields.asScala.find(_.getJsonName === field.name) match {
case Some(fieldDescriptor) =>
val nullableMismatch = fieldDescriptor.isRequired && field.nullability.nullable
nullableMismatch || alterTableRequiredForNestedFields(fieldDescriptor, field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,46 @@ object AtomicDescriptor {
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_STRING)
.setName("event_id")
.setJsonName("event_id")

private def webPage: DescriptorProtos.FieldDescriptorProto.Builder = DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setTypeName("web_page_1")
.setName("unstruct_event_com_snowplowanalytics_snowplow_web_page_1")
.setJsonName("unstruct_event_com_snowplowanalytics_snowplow_web_page_1")

private def testContext: DescriptorProtos.FieldDescriptorProto.Builder = DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_REPEATED)
.setTypeName("test_1")
.setName("contexts_test_vendor_test_name_1")
.setJsonName("contexts_test_vendor_test_name_1")

private def testUnstruct: DescriptorProtos.FieldDescriptorProto.Builder = DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setTypeName("test_1")
.setName("unstruct_event_test_vendor_test_name_1")
.setJsonName("unstruct_event_test_vendor_test_name_1")

private def webPageId: DescriptorProtos.FieldDescriptorProto.Builder =
DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_STRING)
.setName("id")
.setJsonName("id")

private def myString: DescriptorProtos.FieldDescriptorProto.Builder =
DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_STRING)
.setName("my_string")
.setJsonName("my_string")

private def myInteger: DescriptorProtos.FieldDescriptorProto.Builder =
DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_INT64)
.setName("my_integer")
.setJsonName("my_integer")

private def webPageNestedType: DescriptorProtos.DescriptorProto.Builder =
DescriptorProtos.DescriptorProto.newBuilder
Expand All @@ -153,17 +160,20 @@ object AtomicDescriptor {
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setTypeName("ad_click_event_1")
.setName("unstruct_event_com_snowplowanalytics_snowplow_media_ad_click_event_1")
.setJsonName("unstruct_event_com_snowplowanalytics_snowplow_media_ad_click_event_1")

private def adClickContext: DescriptorProtos.FieldDescriptorProto.Builder = DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_REPEATED)
.setTypeName("ad_click_event_1")
.setName("contexts_com_snowplowanalytics_snowplow_media_ad_click_event_1")
.setJsonName("contexts_com_snowplowanalytics_snowplow_media_ad_click_event_1")

private def adClickEventPercentProgress: DescriptorProtos.FieldDescriptorProto.Builder =
DescriptorProtos.FieldDescriptorProto.newBuilder
.setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_INT64)
.setName("percent_progress")
.setJsonName("percent_progress")

private def adClickEventNestedType: DescriptorProtos.DescriptorProto.Builder =
DescriptorProtos.DescriptorProto.newBuilder
Expand Down

0 comments on commit b863ac7

Please sign in to comment.