from typing import Any
from athena_tools import _utils
TOOL_NAME = 'get_table_schema'
TOOL_DESCRIPTION = """
Get DDL (CREATE TABLE statement) for a specific table.
Shows full schema: columns, types, partitions, S3 location.
Use this to understand table structure before writing queries.
Use list_tables first to find table names.
""".strip()
TOOL_INPUT_SCHEMA = {
'type': 'object',
'properties': {
'table_name': {
'type': 'string',
'description': 'Athena table name (e.g. \'provider__actions_alpha\')',
}
},
'required': ['table_name'],
}
def execute(table_name: str) -> dict[str, Any]:
"""
Get DDL (CREATE TABLE statement) for specific table.
Args:
table_name: Athena table name (e.g. 'provider__actions_alpha')
Returns:
{
'table_name': 'provider__actions_alpha',
'ddl': 'CREATE EXTERNAL TABLE provider__actions_alpha (...)',
'column_count': 25
}
Raises:
ValueError: If table doesn't exist
"""
athena = _utils.get_athena_helper()
ddl = athena.get_table_ddl(table_name)
column_count = ddl.count('\n') - 5 if '\n' in ddl else 0
return {'table_name': table_name, 'ddl': ddl, 'column_count': column_count}