from typing import Any
from athena_tools import _utils
TOOL_NAME = 'list_tables'
TOOL_DESCRIPTION = """
List Athena tables in current database (sandbox/replica).
Shows table names, S3 locations, partition keys.
Useful for discovering what data is available before querying.
Optional regex filter to match specific table patterns.
""".strip()
TOOL_INPUT_SCHEMA = {
'type': 'object',
'properties': {
'name_filter': {
'type': 'string',
'description': (
'Optional regex to filter table names '
'(e.g. \'provider__.*\' for provider tables)'
),
}
},
}
def execute(name_filter: str = '') -> dict[str, Any]:
"""
List Athena table names (simple names only, not metadata).
Args:
name_filter: Optional regex pattern to filter table names.
Empty string = no filter (all tables).
Returns:
{
'tables': ['table1', 'table2', ...],
'count': 123,
'filter_applied': 'provider.*'
}
Example:
>>> execute()
{'tables': ['provider__actions_alpha', ...], 'count': 123}
>>> execute(name_filter='provider.*project')
{'tables': ['provider__projects_alpha', ...], 'count': 5}
"""
helper = _utils.get_athena_helper()
table_names = helper.list_table_names(name_filter_regex=name_filter)
return {
'tables': table_names,
'count': len(table_names),
'filter_applied': name_filter if name_filter else None,
}