Last active
          May 1, 2021 07:52 
        
      - 
      
- 
        Save shreyasms17/cb9cfd8d5f8b972f1977050fb2fd4613 to your computer and use it in GitHub Desktop. 
    AutoFlatten extract_order
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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