Skip to content

Instantly share code, notes, and snippets.

@shreyasms17
Created May 1, 2021 07:51
Show Gist options
  • Save shreyasms17/0b8b83a01ae28741a18d638b414d08e7 to your computer and use it in GitHub Desktop.
Save shreyasms17/0b8b83a01ae28741a18d638b414d08e7 to your computer and use it in GitHub Desktop.
AutoFlatten get_bottom_to_top
def get_bottom_to_top(self, order, all_cols_in_explode_cols):
'''
Description:
This function gets the mutually exclusive leaf fields in every array type column
:param order: [type: list] contains the fields in order in which array explode has to take place
:param all_cols_in_explode_cols: [type: set] contains all fields in array type fields
:return bottom_to_top: [type: dict] contains list of mutually exclusive leaf fields for every
array type / struct type (parent to array type) field
'''
bottom_to_top = {}
for column in reversed(order):
x_cols = set(filter(lambda x: x.startswith(column), list(all_cols_in_explode_cols)))
bottom_to_top[column] = list(x_cols)
all_cols_in_explode_cols = all_cols_in_explode_cols.difference(x_cols)
return bottom_to_top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment