5050 types .TableFieldSchema .Type .JSON : descriptor_pb2 .FieldDescriptorProto .TYPE_STRING ,
5151 # INTERVAL is represented as a string
5252 types .TableFieldSchema .Type .INTERVAL : descriptor_pb2 .FieldDescriptorProto .TYPE_STRING ,
53- # STRUCT and RANGE use TYPE_MESSAGE and are handled specially
54- types .TableFieldSchema .Type .STRUCT : descriptor_pb2 .FieldDescriptorProto .TYPE_MESSAGE ,
55- types .TableFieldSchema .Type .RANGE : descriptor_pb2 .FieldDescriptorProto .TYPE_MESSAGE ,
5653}
5754
5855
@@ -154,11 +151,11 @@ def _convert_bq_table_schema_to_proto_descriptor_impl(
154151 field_number = 1
155152
156153 for bq_field in table_schema .fields :
157- # Sanitize the field name for use in scope
158- scope_name = _sanitize_field_name (bq_field .name )
159- current_scope = f"{ scope } __{ scope_name } "
160-
161154 if bq_field .type_ == types .TableFieldSchema .Type .STRUCT :
155+ # Sanitize the field name for use in scope
156+ scope_name = _sanitize_field_name (bq_field .name )
157+ current_scope = f"{ scope } __{ scope_name } "
158+
162159 # Recursively convert nested struct
163160 nested_schema = types .TableSchema (fields = list (bq_field .fields ))
164161 nested_descriptor , deeply_nested = _convert_bq_table_schema_to_proto_descriptor_impl (
@@ -172,6 +169,10 @@ def _convert_bq_table_schema_to_proto_descriptor_impl(
172169 fields .append (field )
173170
174171 elif bq_field .type_ == types .TableFieldSchema .Type .RANGE :
172+ # Sanitize the field name for use in scope
173+ scope_name = _sanitize_field_name (bq_field .name )
174+ current_scope = f"{ scope } __{ scope_name } "
175+
175176 # Validate RANGE element type
176177 if not bq_field .range_element_type or not bq_field .range_element_type .type_ :
177178 raise ValueError (
@@ -217,7 +218,7 @@ def _convert_bq_table_schema_to_proto_descriptor_impl(
217218
218219 else :
219220 # Primitive field
220- field = _convert_bq_field_to_proto_field (bq_field , field_number , current_scope )
221+ field = _convert_bq_field_to_proto_field (bq_field , field_number , "" )
221222 fields .append (field )
222223
223224 field_number += 1
0 commit comments