Skip to content

Commit

Permalink
generate_schema.py: Rename deduce_schema_for_line() to the more accur…
Browse files Browse the repository at this point in the history
…ate deduce_schema_for_record()
  • Loading branch information
bxparks committed Dec 5, 2020
1 parent 0325f69 commit 3d8989b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bigquery_schema_generator/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def deduce_schema(self, file, *, schema_map=None):

# Deduce the schema from this given data record.
if isinstance(json_object, dict):
self.deduce_schema_for_line(
self.deduce_schema_for_record(
json_object=json_object,
schema_map=schema_map,
)
Expand All @@ -212,7 +212,7 @@ def deduce_schema(self, file, *, schema_map=None):

return schema_map, self.error_logs

def deduce_schema_for_line(self, json_object, schema_map, base_path=None):
def deduce_schema_for_record(self, json_object, schema_map, base_path=None):
"""Figures out the BigQuery schema for the given 'json_object' and
updates 'schema_map' with the latest info. A 'schema_map' entry of type
'soft' is a provisional entry that can be overwritten by a subsequent
Expand Down Expand Up @@ -463,7 +463,7 @@ def merge_mode(self, old_schema_entry, new_schema_entry, base_path):

def get_schema_entry(self, key, value, base_path=None):
"""Determines the 'schema_entry' of the (key, value) pair. Calls
deduce_schema_for_line() recursively if the value is another object
deduce_schema_for_record() recursively if the value is another object
instead of a primitive (this will happen only for JSON input file).
'base_path' is the string representing the current path within the
Expand All @@ -480,14 +480,14 @@ def get_schema_entry(self, key, value, base_path=None):
# recursively figure out the RECORD
fields = OrderedDict()
if value_mode == 'NULLABLE':
self.deduce_schema_for_line(
self.deduce_schema_for_record(
json_object=value,
schema_map=fields,
base_path=new_base_path,
)
else:
for val in value:
self.deduce_schema_for_line(
self.deduce_schema_for_record(
json_object=val,
schema_map=fields,
base_path=new_base_path,
Expand Down

0 comments on commit 3d8989b

Please sign in to comment.