def parse_ident(ident: Identifier) -> str: # Extract table name from possible schema.table naming token_list = ident.flatten() table_name = next(token_list).value try: # Determine if the table contains the schema # separated by a dot (format: 'schema.table') dot = next(token_list) if dot.match(Punctuation, '.'): table_name += dot.value table_name += next(token_list).value # And again, to match bigquery's 'database.schema.table' try: dot = next(token_list) if dot.match(Punctuation, '.'): table_name += dot.value table_name += next(token_list).value except StopIteration: # Do not insert database name if it's not specified pass elif default_schema: table_name = f'{default_schema}.{table_name}' except StopIteration: if default_schema: table_name = f'{default_schema}.{table_name}' table_name = table_name.replace('`', '') return table_name
def parse_ident(ident: Identifier) -> str: # Extract table name from possible schema.table naming token_list = ident.flatten() table_name = next(token_list).value try: # Determine if the table contains the schema # separated by a dot (format: 'schema.table') dot = next(token_list) if dot.match(Punctuation, '.'): table_name += dot.value table_name += next(token_list).value elif default_schema: table_name = f'{default_schema}.{table_name}' except StopIteration: if default_schema: table_name = f'{default_schema}.{table_name}' return table_name