def __get_full_name(tlist: TokenList) -> Optional[str]: """ Return the full unquoted table name if valid, i.e., conforms to the following [[cluster.]schema.]table construct. :param tlist: The SQL tokens :returns: The valid full table name """ # Strip the alias if present. idx = len(tlist.tokens) if tlist.has_alias(): ws_idx, _ = tlist.token_next_by(t=Whitespace) if ws_idx != -1: idx = ws_idx tokens = tlist.tokens[:idx] if (len(tokens) in (1, 3, 5) and all( imt(token, t=[Name, String]) for token in tokens[0::2]) and all( imt(token, m=(Punctuation, ".")) for token in tokens[1::2])): return ".".join( [remove_quotes(token.value) for token in tokens[0::2]]) return None
def _get_table(tlist: TokenList) -> Optional[Table]: """ Return the table if valid, i.e., conforms to the [[catalog.]schema.]table construct. :param tlist: The SQL tokens :returns: The table if the name conforms """ # Strip the alias if present. idx = len(tlist.tokens) if tlist.has_alias(): ws_idx, _ = tlist.token_next_by(t=Whitespace) if ws_idx != -1: idx = ws_idx tokens = tlist.tokens[:idx] if (len(tokens) in (1, 3, 5) and all(imt(token, t=[Name, String]) for token in tokens[::2]) and all( imt(token, m=(Punctuation, ".")) for token in tokens[1::2])): return Table( *[remove_quotes(token.value) for token in tokens[::-2]]) return None