Skip to content

Instantly share code, notes, and snippets.

@shreyasms17
Last active May 1, 2021 07:52
Show Gist options
  • Save shreyasms17/95e4eeee2334a2d2dfaa7891cf533f25 to your computer and use it in GitHub Desktop.
Save shreyasms17/95e4eeee2334a2d2dfaa7891cf533f25 to your computer and use it in GitHub Desktop.
AutoFlatten get_structure
def get_structure(self, col_list):
'''
Description:
This function gets the structure to the traversal to array field in the schema
:param col_list: [type: list] contains list of fields that are to be exploded
:return structure: [type: dict] contains the hierarchical mapping for array fields
'''
structure = {'json' : {}}
for val in col_list:
arr = val.split('.')
a = structure['json']
for i in range(1,len(arr)):
if not a.__contains__(arr[i]):
a[arr[i]] = {}
a = a[arr[i]]
return structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment