Skip to content

Instantly share code, notes, and snippets.

@shreyasms17
Last active May 1, 2021 07:52
Show Gist options
  • Save shreyasms17/cb9cfd8d5f8b972f1977050fb2fd4613 to your computer and use it in GitHub Desktop.
Save shreyasms17/cb9cfd8d5f8b972f1977050fb2fd4613 to your computer and use it in GitHub Desktop.
AutoFlatten extract_order
def extract_order(self, structure):
'''
Description:
This function does a BFS traversal to obtain the order in which
the array type fields are to be exploded
:param structure: [type: dict] contains the hierarchical mapping for array fields
:return order: [type: list] contains the fields in order in which array explode has to take place
'''
q = [('', structure['json'])]
order = []
while q:
key, a = q.pop(0)
for x in a.keys():
order.append(f"{key}.{x}")
q.append((f"{key}.{x}", a[x]))
return order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment