MCPcopy Index your code
hub / github.com/dbcli/mycli / extract_table_identifiers

Function extract_table_identifiers

mycli/packages/sql_utils.py:173–198  ·  view source on GitHub ↗

yields tuples of (schema_name, table_name, table_alias)

(token_stream: Generator[Any, None, None])

Source from the content-addressed store, hash-verified

171
172
173def extract_table_identifiers(token_stream: Generator[Any, None, None]) -> Generator[tuple[str | None, str, str], None, None]:
174 """yields tuples of (schema_name, table_name, table_alias)"""
175
176 for item in token_stream:
177 if isinstance(item, IdentifierList):
178 for identifier in item.get_identifiers():
179 # Sometimes Keywords (such as FROM ) are classified as
180 # identifiers which don't have the get_real_name() method.
181 try:
182 schema_name = identifier.get_parent_name()
183 real_name = identifier.get_real_name()
184 except AttributeError:
185 continue
186 if real_name:
187 yield (schema_name, real_name, identifier.get_alias())
188 elif isinstance(item, Identifier):
189 real_name = item.get_real_name()
190 schema_name = item.get_parent_name()
191
192 if real_name:
193 yield (schema_name, real_name, item.get_alias())
194 else:
195 name = item.get_name()
196 yield (None, name, item.get_alias() or name)
197 elif isinstance(item, Function):
198 yield (None, item.get_name(), item.get_name())
199
200
201# extract_tables is inspired from examples in the sqlparse lib.

Calls 5

get_parent_nameMethod · 0.80
get_aliasMethod · 0.80
get_nameMethod · 0.80
get_identifiersMethod · 0.45
get_real_nameMethod · 0.45