<jupyter_start><jupyter_text>get connection<jupyter_code>import get_connections
connection_map = get_connections.main(domain='https://docker.looker.com:19999', url='/api/3.1/connections')
connection_map<jupyter_output><empty_output><jupyter_text>get explore<jupyter_code>with open('../../maps/explore-sample_model-sf__accounts.json', 'r') as f:
    explore = json.load(f)
explore<jupyter_output><empty_output><jupyter_text>get views<jupyter_code>d = dict()
view_dict = dict()
for view in os.listdir('../../maps'):
    if view.startswith('view'):
        view_dict[view.split('-')[2].split('.')[0]] = view
        with open(f'../../maps/{view}','r') as f:
            payload = json.load(f)
            d[payload['view_name']] = payload
[k,v] = zip(*d.items())
explore
connection_map
args = []
for view in v:
    args.append((view, explore, connection_map))
args<jupyter_output><empty_output><jupyter_text>type 1:  if 'view_type' == 'sql_table_name' - warehouse.database.table<jupyter_code>d['snowflake_sf__accounts']
view_type = d['snowflake_sf__accounts']['view_type']
source1 = d['snowflake_sf__accounts']['source_table']
source1<jupyter_output><empty_output><jupyter_text>type 2: if 'view_type' == 'sql_table_name'- database.table<jupyter_code>d['sfbase__cases']
view_type = d['sfbase__cases']
source = d['sfbase__cases']['source_table']
bool(len(source.split('.')) < 4)<jupyter_output><empty_output><jupyter_text>- look for explore and connection<jupyter_code>conn = explore['conn']
database = connection_map[conn]['database']
provider = connection_map[conn]['type'].split(' ')[0]
source2 = f'{provider}.{database}.{source}'
source2
bool(len(source2.split('.')) < 4)
# d['sfbase__contacts']
# d['sfbase__users']
# d['sfbase__accounts']<jupyter_output><empty_output><jupyter_text>type 3: if 'view_type' == 'extension'- extends<jupyter_code>d['sf__contacts']<jupyter_output><empty_output><jupyter_text>- get a mapping of file names and view names<jupyter_code>view_dict
new_target_file = view_dict[d['sf__contacts']['source_table']]
new_target_file
with open(f'../../maps/{new_target_file}', 'r') as f:
    source_payload = json.load(f)
source_payload
# d['sf__users']
# d['sf__cases']
# d['sf__accounts']<jupyter_output><empty_output><jupyter_text>type 4- derived table<jupyter_code>d['total_active_node_count']<jupyter_output><empty_output><jupyter_text>type 5- NDT  Bonus: chained extension<jupyter_code>view1 = {"view_name": "top_contacts",
    "source_table": "middle_contacts",
    "view_type": "extension"
    }
view2 = {"view_name": "middle_contacts",
    "source_table": "bottom_contacts",
    "view_type": "extension"
    }
view3 = {"view_name": "bottom_contacts",
    "source_table": "base_contacts",
    "view_type": "extension"
    }
view4 = {"view_name": "snowflake_sf__accounts",
    "source_table": "SEGMENT.SALESFORCE.ACCOUNTS",
    "view_type": "sql_table_name"}
view_dict = {'top_contacts': 'testing_top.json',
             'middle_contacts': 'testing_middle.json',
             'bottom_contacts': 'testing_bottom.json',
             'base_contacts': 'testing_base.json'
            }
def is_base_view(view_payload):
    return bool(view_payload['view_type'] == 'sql_table_name')
view_list = [view1, view2, view3, view4]
i = 0
while(is_base_view(view_list[i])):
    print(view_list[i])
    i += 1
is_base_view(view_list[3])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16804979253112035, 'fraction_numerical': 0.00978067575577949, 'mean_word_length': 6.336956521739131, 'pattern_counts': {'":': 12, '<': 43, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '516071', 'license': 'MIT', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1254, 'n_words': 177, 'path': 'src/notebooks/objectssssssssss_warehouse.ipynb', 'repo_name': 'vickykwan92/gazetteer', 'size': '3374'}