def create_account_mapping_sql()

in cid/helpers/account_map.py [0:0]


    def create_account_mapping_sql(self, name) -> str:
        """ Returns account mapping Athena query """
        template_str = '''CREATE OR REPLACE VIEW  ${athena_view_name} AS
            SELECT
                *
            FROM
                ( VALUES ${rows} )
            ignored_table_name (account_id, account_name, parent_account_id, account_status, account_email)
        '''
        
        while not self.accounts and self._metadata_source != 'dummy':
            self.select_metadata_collection_method()
            
        if self._metadata_source == 'dummy':
            compiled_query = self.get_dummy_account_mapping_sql(name)        
        else:
            template = Template(template_str)
            accounts_sql = list()
            for account in self.accounts:
                acc = account.copy()
                account_name = acc.pop('account_name').replace("'", "''")
                accounts_sql.append(
                    """ROW ('{account_id}', '{account_name}:{account_id}', '{parent_account_id}', '{account_status}', '{account_email}')""".format(account_name=account_name, **acc))
            
            # Fill in TPLs
            columns_tpl = dict()
            parameters = {
                'athena_view_name': name,
                'rows': ','.join(accounts_sql)
            }
            columns_tpl.update(**parameters)
            compiled_query = template.safe_substitute(columns_tpl)

        return compiled_query