mirror of
https://github.com/apache/superset.git
synced 2026-05-07 08:54:23 +00:00
fix(mcp): support explicit query_mode in TableChartConfig (#39412)
This commit is contained in:
committed by
GitHub
parent
e5b3a9c25d
commit
2e0d482ccf
@@ -109,6 +109,44 @@ class TestTableChartConfig:
|
||||
columns=[ColumnRef(name="product")],
|
||||
)
|
||||
|
||||
def test_explicit_raw_query_mode_accepted(self) -> None:
|
||||
"""Test that TableChartConfig accepts explicit query_mode='raw'."""
|
||||
config = TableChartConfig(
|
||||
chart_type="table",
|
||||
query_mode="raw",
|
||||
columns=[ColumnRef(name="product"), ColumnRef(name="category")],
|
||||
)
|
||||
assert config.query_mode == "raw"
|
||||
assert len(config.columns) == 2
|
||||
|
||||
def test_explicit_aggregate_query_mode_accepted(self) -> None:
|
||||
"""Test that TableChartConfig accepts explicit query_mode='aggregate'."""
|
||||
config = TableChartConfig(
|
||||
chart_type="table",
|
||||
query_mode="aggregate",
|
||||
columns=[ColumnRef(name="sales", aggregate="SUM")],
|
||||
)
|
||||
assert config.query_mode == "aggregate"
|
||||
|
||||
def test_default_query_mode_is_none(self) -> None:
|
||||
"""Test that default query_mode is None (auto-detect)."""
|
||||
config = TableChartConfig(
|
||||
chart_type="table",
|
||||
columns=[ColumnRef(name="product")],
|
||||
)
|
||||
assert config.query_mode is None
|
||||
|
||||
def test_invalid_query_mode_rejected(self) -> None:
|
||||
"""Test that invalid query_mode values are rejected."""
|
||||
from pydantic import ValidationError
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
TableChartConfig(
|
||||
chart_type="table",
|
||||
query_mode="invalid",
|
||||
columns=[ColumnRef(name="product")],
|
||||
)
|
||||
|
||||
|
||||
class TestXYChartConfig:
|
||||
"""Test XYChartConfig validation."""
|
||||
|
||||
@@ -390,6 +390,62 @@ class TestMapTableConfig:
|
||||
assert result["metrics"] == ["total_revenue", "avg_order_value"]
|
||||
assert "all_columns" not in result
|
||||
|
||||
def test_map_table_config_explicit_raw_mode(self) -> None:
|
||||
"""Test that explicit query_mode='raw' forces raw mode."""
|
||||
config = TableChartConfig(
|
||||
chart_type="table",
|
||||
query_mode="raw",
|
||||
columns=[
|
||||
ColumnRef(name="product"),
|
||||
ColumnRef(name="category"),
|
||||
],
|
||||
)
|
||||
|
||||
result = map_table_config(config)
|
||||
|
||||
assert result["viz_type"] == "table"
|
||||
assert result["query_mode"] == "raw"
|
||||
assert result["all_columns"] == ["product", "category"]
|
||||
assert result["columns"] == ["product", "category"]
|
||||
assert "metrics" not in result
|
||||
|
||||
def test_map_table_config_explicit_raw_mode_ignores_aggregates(self) -> None:
|
||||
"""Test that explicit query_mode='raw' ignores aggregate settings on columns."""
|
||||
config = TableChartConfig(
|
||||
chart_type="table",
|
||||
query_mode="raw",
|
||||
columns=[
|
||||
ColumnRef(name="product"),
|
||||
ColumnRef(name="sales", aggregate="SUM"),
|
||||
],
|
||||
)
|
||||
|
||||
result = map_table_config(config)
|
||||
|
||||
assert result["query_mode"] == "raw"
|
||||
# Both columns treated as raw; aggregate setting on "sales" is ignored
|
||||
assert result["all_columns"] == ["product", "sales"]
|
||||
assert result["columns"] == ["product", "sales"]
|
||||
assert "metrics" not in result
|
||||
|
||||
def test_map_table_config_explicit_aggregate_mode(self) -> None:
|
||||
"""Test that explicit query_mode='aggregate' uses inference logic."""
|
||||
config = TableChartConfig(
|
||||
chart_type="table",
|
||||
query_mode="aggregate",
|
||||
columns=[
|
||||
ColumnRef(name="product"),
|
||||
ColumnRef(name="revenue", aggregate="SUM"),
|
||||
],
|
||||
)
|
||||
|
||||
result = map_table_config(config)
|
||||
|
||||
assert result["query_mode"] == "aggregate"
|
||||
assert len(result["metrics"]) == 1
|
||||
assert result["metrics"][0]["aggregate"] == "SUM"
|
||||
assert "product" in result["groupby"]
|
||||
|
||||
|
||||
class TestAddAdhocFilters:
|
||||
"""Test _add_adhoc_filters helper function"""
|
||||
|
||||
Reference in New Issue
Block a user