Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doris_mcp_server/utils/schema_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,9 +1667,12 @@ async def get_table_schema_async(

if effective_catalog and effective_catalog != "internal":
safe_catalog = quote_identifier(effective_catalog, "catalog name")
query = f"DESCRIBE {safe_catalog}.{safe_db}.{safe_table}"
query = (
"SHOW FULL COLUMNS FROM "
f"{safe_catalog}.{safe_db}.{safe_table}"
)
else:
query = f"DESCRIBE {safe_db}.{safe_table}"
query = f"SHOW FULL COLUMNS FROM {safe_db}.{safe_table}"

# Execute async query
result = await self._execute_query_async(query, db_name)
Expand Down
16 changes: 15 additions & 1 deletion test/integration/test_real_doris_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def doris_sandbox() -> DorisSandbox:
f"""
CREATE TABLE {qualified_table} (
id BIGINT,
marker VARCHAR(64)
marker VARCHAR(64) COMMENT 'Integration marker'
)
DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 1
Expand Down Expand Up @@ -814,6 +814,20 @@ async def test_real_doris_tool_regression_paths(
assert basic_info_result.structured_content["row_count"] == 1
assert basic_info_result.structured_content["column_count"] == 2

schema_result = await client.call_tool(
"get_table_schema",
{
"table_name": doris_sandbox.table,
"db_name": doris_sandbox.settings.database,
},
)
assert schema_result.is_error is False
assert isinstance(schema_result.structured_content, dict)
schema_columns = schema_result.structured_content["result"]
assert next(
column for column in schema_columns if column["column_name"] == "marker"
)["comment"] == "Integration marker"

column_analysis_result = await client.call_tool(
"analyze_columns",
{
Expand Down
48 changes: 48 additions & 0 deletions test/utils/test_schema_extractor_doris_oauth_metadata_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,54 @@ async def _call_tool(method_name, args, connection_manager):
reset_auth_context(token)


@pytest.mark.parametrize(
("catalog_name", "expected_query"),
[
(None, "SHOW FULL COLUMNS FROM `db1`.`tbl1`"),
("internal", "SHOW FULL COLUMNS FROM `db1`.`tbl1`"),
("hive", "SHOW FULL COLUMNS FROM `hive`.`db1`.`tbl1`"),
],
)
@pytest.mark.asyncio
async def test_table_schema_uses_full_columns_and_preserves_comments(
catalog_name,
expected_query,
):
connection_manager = FakeConnectionManager(
rows=[
{
"Field": "customer_id",
"Type": "bigint",
"Null": "NO",
"Key": "YES",
"Default": None,
"Extra": "",
"Comment": "Customer identifier",
}
]
)
extractor = MetadataExtractor(db_name="db1", connection_manager=connection_manager)

schema = await extractor.get_table_schema_async(
"tbl1",
"db1",
catalog_name,
)

assert connection_manager.calls[0][1] == expected_query
assert schema == [
{
"column_name": "customer_id",
"data_type": "bigint",
"is_nullable": False,
"default_value": None,
"comment": "Customer identifier",
"key": "YES",
"extra": "",
}
]


@pytest.mark.parametrize(("tool_name", "method_name", "args"), METADATA_TOOL_CASES)
@pytest.mark.parametrize(
("error", "error_code", "status_code"),
Expand Down