Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#14846] feat(mcp-server): Support Semantic Model source lookup (#14847)

mchadesb6406f6facf6
diff --git a/docs/gravitino-mcp-server.md b/docs/gravitino-mcp-server.md
index f466fe9612..d748cf378a 100644
--- a/docs/gravitino-mcp-server.md
+++ b/docs/gravitino-mcp-server.md
@@ -141,6 +141,7 @@ Gravitino MCP server supports the following tools, and you could export tool by
| `list_of_semantic_models` | List the Semantic Models the caller can access in a schema. | `semantic_model` |
| `list_metrics` | List visible metric identifiers across Semantic Models in a schema. | `semantic_model` |
| `list_metric_infos` | List complete visible metrics across Semantic Models in a schema. | `semantic_model` |
+| `list_semantic_model_datasets` | List visible datasets directly associated with a source table or view. | `semantic_model` |
| `load_semantic_model` | Load a Semantic Model's metadata and definition. | `semantic_model` |
| `create_semantic_model` | Create a Semantic Model from a native REST definition. | `semantic_model` |
| `alter_semantic_model` | Apply Semantic Model updates atomically. | `semantic_model` |
@@ -148,7 +149,7 @@ Gravitino MCP server supports the following tools, and you could export tool by
### Semantic Models
-Semantic Model tools manage schema-scoped semantic metadata through the Gravitino REST API.
+Semantic Model tools manage semantic metadata and discover source associations through the Gravitino REST API.
For concepts and source requirements, see [Semantic Models](./semantic-models.md). For governance
and Ossie import/export, see [Manage Semantic Model Metadata](./manage-semantic-model-metadata-using-gravitino.md).
Use the `semantic_model` tag with `--include-tool-tags` to expose these tools.
@@ -175,6 +176,32 @@ Both modes follow containing-model visibility and sort by model identifier, then
case-sensitive metric name. An empty result is `[]`; failures propagate as tool
errors. These tools discover definitions and do not execute metric queries.
+`list_semantic_model_datasets` discovers datasets directly associated with a
+table or view using one REST request. Pass `source_type` (`table` or `view`),
+the source's `catalog_name`, `schema_name`, and `source_name`, and optionally `metalake`:
+
+```json
+{"metalake": "prod", "source_type": "table", "catalog_name": "sales", "schema_name": "raw", "source_name": "orders"}
+```
+
+Source `catalog_name`, `schema_name`, and `source_name` must not contain literal
+dots: the REST source lookup route uses `catalog.schema.name` without component
+escaping. The tool rejects these inputs before sending a request.
+
+The result is a JSON array of identifiers with `namespace`
+`[metalake, catalog, schema, semanticModel]` and the exact dataset `name`. Results
+may span catalogs and schemas in the selected metalake. Keep each component
+separate: a dataset name such as `orders.raw` contains a literal dot. The namespace
+components identify the containing Semantic Model. Server ordering is preserved:
+namespace components first, then dataset name, using case-sensitive UTF-16 ordering.
+
+The caller must be able to access the source metadata; Gravitino returns datasets
+only from models the caller can load. No visible matches returns `[]`; missing or
+inaccessible sources and other failures raise tool errors. Associations reflect the
+latest model definition write, including explicit replacement, and do not describe
+transitive dependencies or guarantee that a model can execute. An empty result is
+not evidence that a source can be safely changed or deleted.
+
For example, call `create_semantic_model` with the following arguments after the
`sales.mart.orders` source table exists in the selected metalake:
diff --git a/mcp-server/mcp_server/client/plain/plain_rest_client_semantic_model_operation.py b/mcp-server/mcp_server/client/plain/plain_rest_client_semantic_model_operation.py
index b57c7472d8..c0fe6d05e5 100644
--- a/mcp-server/mcp_server/client/plain/plain_rest_client_semantic_model_operation.py
+++ b/mcp-server/mcp_server/client/plain/plain_rest_client_semantic_model_operation.py
@@ -49,6 +49,30 @@ class PlainRESTClientSemanticModelOperation(SemanticModelOperation):
)
return extract_list_from_response(response, "identifiers")
+ async def list_semantic_model_datasets(
+ self,
+ source_type: str,
+ catalog_name: str,
+ schema_name: str,
+ source_name: str,
+ ) -> str:
+ encoded_names = [
+ encode_path_segment(name)
+ for name in (catalog_name, schema_name, source_name)
+ ]
+ # The REST fullName format has no escape for dots within a component.
+ if any("." in name for name in encoded_names):
+ raise ValueError(
+ "Source lookup does not support dots in catalog, schema, or table/view names"
+ )
+ full_name = ".".join(encoded_names)
+ response = await self.rest_client.get(
+ f"/api/metalakes/{encode_path_segment(self.metalake_name)}"
+ f"/objects/{encode_path_segment(source_type)}/{full_name}"
+ "/semantic-model-datasets"
+ )
+ return extract_list_from_response(response, "identifiers")
+
async def list_metric_infos(
self, catalog_name: str, schema_name: str
) -> str:
diff --git a/mcp-server/mcp_server/client/semantic_model_operation.py b/mcp-server/mcp_server/client/semantic_model_operation.py
index 9d3572f2a4..dd958be727 100644
--- a/mcp-server/mcp_server/client/semantic_model_operation.py
+++ b/mcp-server/mcp_server/client/semantic_model_operation.py
@@ -20,7 +20,7 @@ from typing import Optional
class SemanticModelOperation(ABC):
- """Operations on schema-scoped Gravitino Semantic Models."""
+ """Operations on Gravitino Semantic Models and their source associations."""
@abstractmethod
async def list_of_semantic_models(
@@ -29,6 +29,17 @@ class SemanticModelOperation(ABC):
"""Return Semantic Model identifiers as a JSON array."""
pass
+ @abstractmethod
+ async def list_semantic_model_datasets(
+ self,
+ source_type: str,
+ catalog_name: str,
+ schema_name: str,
+ source_name: str,
+ ) -> str:
+ """Return visible dataset identifiers associated with a table or view."""
+ pass
+
@abstractmethod
async def list_metrics(self, catalog_name: str, schema_name: str) -> str:
"""Return visible metric identifiers with full REST namespaces as JSON."""
diff --git a/mcp-server/mcp_server/tools/semantic_model.py b/mcp-server/mcp_server/tools/semantic_model.py
index 58eb1e50dc..972a491132 100644
--- a/mcp-server/mcp_server/tools/semantic_model.py
+++ b/mcp-server/mcp_server/tools/semantic_model.py
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-from typing import Optional
+from typing import Literal, Optional
from fastmcp import Context, FastMCP
from mcp.types import ToolAnnotations
@@ -137,6 +137,51 @@ def load_semantic_model_tools(mcp: FastMCP):
catalog_name, schema_name, semantic_model_name
)
+ @mcp.tool(
+ tags={"semantic_model"},
+ annotations=ToolAnnotations(
+ readOnlyHint=True, destructiveHint=False, idempotentHint=True
+ ),
+ )
+ async def list_semantic_model_datasets(
+ ctx: Context,
+ source_type: Literal["table", "view"],
+ catalog_name: str,
+ schema_name: str,
+ source_name: str,
+ ) -> str:
+ """List visible Semantic Model datasets directly associated with a source.
+
+ Requires access to the source metadata. Results may span catalogs and
+ schemas in the selected metalake and include only models the caller can
+ load. Preserves the server's component-wise, case-sensitive UTF-16 order.
+
+ Source catalog, schema, and table/view names must not contain literal
+ dots. The REST source lookup route uses catalog.schema.name without
+ component escaping; these inputs are rejected before sending a request.
+
+ Associations reflect the latest definition write, not model execution
+ validity or transitive dependencies. An empty result does not establish
+ that changing or deleting the source is safe.
+
+ Args:
+ ctx: The request context.
+ source_type: The source kind, either table or view.
+ catalog_name: Name of the source catalog.
+ schema_name: Name of the source schema.
+ source_name: Name of the source table or view.
+
+ Returns:
+ A JSON array of identifiers with namespace
+ [metalake, catalog, schema, semanticModel] and the exact dataset
+ name, including any literal dots. No visible matches returns [];
+ failed requests raise tool errors.
+ """
+ client = ctx.request_context.lifespan_context.rest_client()
+ return await client.as_semantic_model_operation().list_semantic_model_datasets(
+ source_type, catalog_name, schema_name, source_name
+ )
+
@mcp.tool(tags={"semantic_model"})
# pylint: disable=too-many-positional-arguments
async def create_semantic_model(
diff --git a/mcp-server/tests/integration/test_semantic_model_source_lookup.py b/mcp-server/tests/integration/test_semantic_model_source_lookup.py
new file mode 100644
index 0000000000..e42101400a
--- /dev/null
+++ b/mcp-server/tests/integration/test_semantic_model_source_lookup.py
@@ -0,0 +1,281 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Discover source-associated datasets through real MCP and Gravitino servers."""
+
+import asyncio
+import json
+from uuid import uuid4
+
+import httpx
+import pytest
+from fastmcp import Client
+from fastmcp.client.transports import StreamableHttpTransport
+from fastmcp.exceptions import ToolError
+
+from tests.integration.gravitino_setup import basic_auth_header
+
+# Pytest injects fixtures by argument name.
+# pylint: disable=redefined-outer-name
+
+_ALIASES = ("Orders.raw", "orders.raw", "\U00010000", "\ue000")
+
+
+class SourceLookupFixture:
+ """Own source objects, cross-catalog models, and grants for one test."""
+
+ def __init__(self, env, rest_client):
+ self.env = env
+ self.rest_client = rest_client
+ self.metalake = "source_mcp_" + uuid4().hex
+ self.base = f"/api/metalakes/{self.metalake}"
+
+ def request(self, method, path, body=None):
+ response = self.rest_client.request(method, path, json=body)
+ response.raise_for_status()
+ return response.json()
+
+ def provision(self, warehouse):
+ for name, provider, properties in (
+ (
+ "sources",
+ "lakehouse-iceberg",
+ {
+ "catalog-backend": "jdbc",
+ "warehouse": warehouse.as_uri(),
+ "uri": f"jdbc:h2:mem:{self.metalake};DB_CLOSE_DELAY=-1;MODE=MYSQL",
+ "jdbc-driver": "org.h2.Driver",
+ "jdbc-initialize": "true",
+ },
+ ),
+ ("models", "lakehouse-generic", {}),
+ ):
+ self.request(
+ "POST",
+ self.base + "/catalogs",
+ {
+ "name": name,
+ "type": "RELATIONAL",
+ "provider": provider,
+ "properties": properties,
+ },
+ )
+ for catalog, schema in (
+ ("sources", "raw"),
+ ("models", "semantic"),
+ ("models", "other"),
+ ):
+ self.request(
+ "POST",
+ self.base + f"/catalogs/{catalog}/schemas",
+ {"name": schema, "properties": {}},
+ )
+ source_path = self.base + "/catalogs/sources/schemas/raw"
+ for name in ("orders", "unused"):
+ self.request(
+ "POST",
+ source_path + "/tables",
+ {
+ "name": name,
+ "columns": [{"name": "amount", "type": "long"}],
+ "properties": {},
+ },
+ )
+ self.request(
+ "POST",
+ source_path + "/views",
+ {
+ "name": "order_view",
+ "columns": [{"name": "amount", "type": "long"}],
+ "representations": [
+ {
+ "type": "sql",
+ "dialect": "trino",
+ "sql": "SELECT amount FROM sources.raw.orders",
+ }
+ ],
+ "defaultCatalog": "sources",
+ "defaultSchema": "raw",
+ "properties": {},
+ },
+ )
+ for schema, model, source, aliases in (
+ ("semantic", "a", "orders", tuple(reversed(_ALIASES))),
+ ("other", "b", "orders", ("cross_schema",)),
+ ("semantic", "hidden", "orders", ("hidden",)),
+ ("semantic", "from_view", "order_view", ("view.raw",)),
+ ):
+ self.request(
+ "POST",
+ self.base
+ + f"/catalogs/models/schemas/{schema}/semantic-models",
+ {
+ "name": model,
+ "definition": {
+ "datasets": [
+ {
+ "name": alias,
+ "source": {
+ "namespace": ["sources", "raw"],
+ "name": source,
+ },
+ }
+ for alias in aliases
+ ]
+ },
+ },
+ )
+
+ def call(
+ self, source_type="table", source_name="orders", principal="admin"
+ ):
+ async def invoke():
+ transport = StreamableHttpTransport(
+ url=self.env["mcp_url"],
+ headers={"Authorization": basic_auth_header(principal)},
+ )
+ async with Client(transport) as client:
+ result = await client.call_tool(
+ "list_semantic_model_datasets",
+ {
+ "metalake": self.metalake,
+ "source_type": source_type,
+ "catalog_name": "sources",
+ "schema_name": "raw",
+ "source_name": source_name,
+ },
+ )
+ return json.loads(result.content[0].text)
+
+ return asyncio.run(invoke())
+
+ def identifier(self, schema, model, alias):
+ return {
+ "namespace": [self.metalake, "models", schema, model],
+ "name": alias,
+ }
+
+ def change_privilege(self, action, object_type, name, privilege):
+ self.request(
+ "PUT",
+ self.base
+ + f"/permissions/roles/source_reader/{object_type}/{name}/{action}",
+ {"privileges": [{"name": privilege, "condition": "ALLOW"}]},
+ )
+
+
+def source_fixture(integration_env, tmp_path):
+ with httpx.Client(
+ base_url=integration_env["gravitino_uri"],
+ timeout=30.0,
+ headers={"Authorization": basic_auth_header("admin")},
+ ) as client:
+ fixture = SourceLookupFixture(integration_env, client)
+ fixture.request(
+ "POST",
+ "/api/metalakes",
+ {"name": fixture.metalake, "properties": {}},
+ )
+ try:
+ fixture.provision(tmp_path)
+ yield fixture
+ finally:
+ fixture.request("DELETE", fixture.base + "?force=true")
+
+
+class TestSemanticModelSourceLookup:
+ """Verify direct source discovery and per-caller visibility over HTTP."""
+
+ @pytest.mark.parametrize("source_type", ("table", "view"))
+ def test_identifiers_order_and_rest_parity(
+ self, source_fixture, source_type
+ ):
+ fixture = source_fixture
+ if source_type == "table":
+ source_name = "orders"
+ expected = [fixture.identifier("other", "b", "cross_schema")]
+ expected += [
+ fixture.identifier("semantic", "a", alias) for alias in _ALIASES
+ ]
+ expected += [fixture.identifier("semantic", "hidden", "hidden")]
+ else:
+ source_name = "order_view"
+ expected = [fixture.identifier("semantic", "from_view", "view.raw")]
+ actual = fixture.call(source_type, source_name)
+ assert actual == expected
+ response = fixture.request(
+ "GET",
+ fixture.base
+ + f"/objects/{source_type}/sources.raw.{source_name}/semantic-model-datasets",
+ )
+ assert actual == response["identifiers"]
+
+ def test_model_visibility_parent_access_and_source_denial(
+ self, source_fixture
+ ):
+ fixture = source_fixture
+ fixture.request(
+ "POST", fixture.base + "/users", {"name": "source_reader"}
+ )
+ fixture.request(
+ "POST",
+ fixture.base + "/roles",
+ {"name": "source_reader", "properties": {}, "securableObjects": []},
+ )
+ fixture.request(
+ "PUT",
+ fixture.base + "/permissions/users/source_reader/grant",
+ {"roleNames": ["source_reader"]},
+ )
+ for object_type, name, privilege in (
+ ("catalog", "sources", "USE_CATALOG"),
+ ("schema", "sources.raw", "USE_SCHEMA"),
+ ("table", "sources.raw.orders", "SELECT_TABLE"),
+ ("catalog", "models", "USE_CATALOG"),
+ ("schema", "models.semantic", "USE_SCHEMA"),
+ ):
+ fixture.change_privilege("grant", object_type, name, privilege)
+ assert fixture.call(principal="source_reader") == []
+ fixture.change_privilege(
+ "grant", "semantic_model", "models.semantic.a", "USE_SEMANTIC_MODEL"
+ )
+ expected = [
+ fixture.identifier("semantic", "a", alias) for alias in _ALIASES
+ ]
+ assert fixture.call(principal="source_reader") == expected
+ fixture.change_privilege(
+ "revoke", "schema", "models.semantic", "USE_SCHEMA"
+ )
+ assert fixture.call(principal="source_reader") == []
+ fixture.change_privilege(
+ "grant", "schema", "models.semantic", "USE_SCHEMA"
+ )
+ assert fixture.call(principal="source_reader") == expected
+ fixture.change_privilege(
+ "revoke", "table", "sources.raw.orders", "SELECT_TABLE"
+ )
+ with pytest.raises(ToolError, match="ForbiddenException"):
+ fixture.call(principal="source_reader")
+
+ def test_empty_result_and_missing_sources(self, source_fixture):
+ assert source_fixture.call(source_name="unused") == []
+ for source_type in ("table", "view"):
+ with pytest.raises(
+ ToolError, match="NoSuchMetadataObjectException"
+ ):
+ source_fixture.call(source_type, "missing")
diff --git a/mcp-server/tests/unit/tools/mock_operation.py b/mcp-server/tests/unit/tools/mock_operation.py
index 8c0c6fe6fa..e399fd2a9f 100644
--- a/mcp-server/tests/unit/tools/mock_operation.py
+++ b/mcp-server/tests/unit/tools/mock_operation.py
@@ -494,6 +494,15 @@ class MockViewOperation(ViewOperation):
class MockSemanticModelOperation(SemanticModelOperation):
+ async def list_semantic_model_datasets(
+ self,
+ source_type: str,
+ catalog_name: str,
+ schema_name: str,
+ source_name: str,
+ ) -> str:
+ return "[]"
+
async def list_metrics(self, catalog_name: str, schema_name: str) -> str:
return "[]"
diff --git a/mcp-server/tests/unit/tools/test_semantic_model.py b/mcp-server/tests/unit/tools/test_semantic_model.py
index e5ec52e703..d1a8e03679 100644
--- a/mcp-server/tests/unit/tools/test_semantic_model.py
+++ b/mcp-server/tests/unit/tools/test_semantic_model.py
@@ -37,6 +37,11 @@ from tests.unit.tools import MockOperation
_NAMESPACE = {"catalog_name": "sales", "schema_name": "mart"}
_MODEL_ARGS = {**_NAMESPACE, "semantic_model_name": "sales_model"}
+_SOURCE_ARGS = {
+ **_NAMESPACE,
+ "source_type": "table",
+ "source_name": "orders",
+}
_MODELS_PATH = (
"/api/metalakes/test_metalake/catalogs/sales/schemas/mart/semantic-models"
)
@@ -167,6 +172,174 @@ class TestSemanticModelTool(unittest.IsolatedAsyncioTestCase):
self.assertEqual(1, len(self.requests))
self._assert_request("GET", _METRICS_PATH + "?details=false")
+ async def test_source_lookup_preserves_identifiers_and_server_order(self):
+ namespace = ["test_metalake", "models", "semantic", "a"]
+ identifiers = [
+ {"namespace": namespace, "name": name}
+ for name in ("Orders.raw", "orders.raw", "\U00010000", "\ue000")
+ ] + [
+ {
+ "namespace": ["test_metalake", "other", "schema", "model"],
+ "name": "orders.raw",
+ }
+ ]
+ for source_type in ("table", "view"):
+ with self.subTest(source_type=source_type):
+ self.requests.clear()
+ self.response = {"code": 0, "identifiers": identifiers}
+ result = await self._call(
+ "list_semantic_model_datasets",
+ {**_SOURCE_ARGS, "source_type": source_type},
+ )
+ self.assertEqual(identifiers, result)
+ self.assertEqual(1, len(self.requests))
+ self._assert_request(
+ "GET",
+ f"/api/metalakes/test_metalake/objects/{source_type}/"
+ "sales.mart.orders/semantic-model-datasets",
+ )
+
+ async def test_source_lookup_empty_results(self):
+ self.response = {"code": 0, "identifiers": []}
+ for source_type in ("table", "view"):
+ with self.subTest(source_type=source_type):
+ self.assertEqual(
+ [],
+ await self._call(
+ "list_semantic_model_datasets",
+ {**_SOURCE_ARGS, "source_type": source_type},
+ ),
+ )
+
+ async def test_source_lookup_path_encoding_and_request_scope(self):
+ self.response = {"code": 0, "identifiers": []}
+ for source_type in ("table", "view"):
+ with self.subTest(source_type=source_type):
+ with patch(
+ "mcp_server.core.context._get_request_authorization",
+ return_value="Bearer request-test-token",
+ ):
+ await self._call(
+ "list_semantic_model_datasets",
+ {
+ "metalake": "ml/雪",
+ "source_type": source_type,
+ "catalog_name": "cat?",
+ "schema_name": "sch #+%",
+ "source_name": "orders/雪",
+ },
+ )
+ request = self.requests[-1]
+ self.assertEqual(
+ f"/api/metalakes/ml%2F%E9%9B%AA/objects/{source_type}/"
+ "cat%3F.sch%20%23%2B%25.orders%2F%E9%9B%AA/semantic-model-datasets",
+ request.url.raw_path.decode(),
+ )
+ self.assertEqual(
+ "Bearer request-test-token",
+ request.headers["Authorization"],
+ )
+ await self._call("list_semantic_model_datasets", _SOURCE_ARGS)
+ self._assert_request(
+ "GET",
+ "/api/metalakes/test_metalake/objects/table/"
+ "sales.mart.orders/semantic-model-datasets",
+ )
+
+ async def test_source_lookup_rejects_invalid_source_types(self):
+ for source_type in ("", "TABLE", "catalog", "table/view", None):
+ with self.subTest(source_type=source_type):
+ with self.assertRaisesRegex(ToolError, "source_type"):
+ await self._call(
+ "list_semantic_model_datasets",
+ {**_SOURCE_ARGS, "source_type": source_type},
+ )
+ self.assertEqual([], self.requests)
+
+ async def test_source_lookup_rejects_ambiguous_path_names(self):
+ for argument in (
+ "metalake",
+ "catalog_name",
+ "schema_name",
+ "source_name",
+ ):
+ invalid_names = (
+ (".", "..") if argument == "metalake" else ("", ".", "..")
+ )
+ for name in invalid_names:
+ with self.subTest(argument=argument, name=name):
+ with self.assertRaisesRegex(ToolError, "REST path names"):
+ await self._call(
+ "list_semantic_model_datasets",
+ {**_SOURCE_ARGS, argument: name},
+ )
+ self.assertEqual([], self.requests)
+
+ async def test_source_lookup_rejects_dots_in_source_components(self):
+ for source_type in ("table", "view"):
+ for argument in ("catalog_name", "schema_name", "source_name"):
+ with self.subTest(source_type=source_type, argument=argument):
+ with self.assertRaisesRegex(
+ ToolError, "Source lookup does not support dots"
+ ):
+ await self._call(
+ "list_semantic_model_datasets",
+ {
+ **_SOURCE_ARGS,
+ "source_type": source_type,
+ argument: "name.with.dot",
+ },
+ )
+ self.assertEqual([], self.requests)
+
+ async def test_source_lookup_propagates_rest_failures(self):
+ for source_type in ("table", "view"):
+ for status, code, error_type in (
+ (400, 1001, "IllegalArgumentException"),
+ (401, 1011, "UnauthorizedException"),
+ (403, 1008, "ForbiddenException"),
+ (404, 1003, "NoSuchMetadataObjectException"),
+ (404, 1003, "NotFoundException"),
+ (500, 1002, "RuntimeException"),
+ ):
+ with self.subTest(source_type=source_type, status=status):
+ self.status = status
+ self.response = {
+ "code": code,
+ "type": error_type,
+ "message": "Source lookup rejected",
+ "identifiers": [],
+ }
+ with self.assertRaisesRegex(ToolError, error_type):
+ await self._call(
+ "list_semantic_model_datasets",
+ {**_SOURCE_ARGS, "source_type": source_type},
+ )
+
+ async def test_source_lookup_rejects_invalid_responses(self):
+ for body in (
+ [],
+ {},
+ {"identifiers": []},
+ {"code": 0},
+ {"code": 0, "identifiers": None},
+ {"code": 0, "identifiers": {}},
+ {"code": 0, "identifiers": "[]"},
+ b"not JSON",
+ ):
+ with self.subTest(body=body):
+ self.response = body
+ with self.assertRaisesRegex(
+ ToolError, "Invalid Gravitino response"
+ ):
+ await self._call(
+ "list_semantic_model_datasets", _SOURCE_ARGS
+ )
+ self.status = 502
+ self.response = {"code": 0, "identifiers": []}
+ with self.assertRaisesRegex(ToolError, "502"):
+ await self._call("list_semantic_model_datasets", _SOURCE_ARGS)
+
async def test_metric_infos_preserve_complete_metrics_and_numbers(self):
metric = {
"name": "Revenue",
@@ -565,6 +738,7 @@ class TestSemanticModelTool(unittest.IsolatedAsyncioTestCase):
"list_of_semantic_models",
"list_metrics",
"list_metric_infos",
+ "list_semantic_model_datasets",
"load_semantic_model",
"create_semantic_model",
"alter_semantic_model",
@@ -583,12 +757,22 @@ class TestSemanticModelTool(unittest.IsolatedAsyncioTestCase):
"list_of_semantic_models",
"list_metrics",
"list_metric_infos",
+ "list_semantic_model_datasets",
"load_semantic_model",
):
tool = tools[name]
self.assertTrue(tool.annotations.readOnlyHint)
self.assertTrue(tool.annotations.idempotentHint)
self.assertFalse(tool.annotations.destructiveHint)
+ source_tool = tools["list_semantic_model_datasets"]
+ self.assertEqual(
+ {"source_type", "catalog_name", "schema_name", "source_name"},
+ set(source_tool.inputSchema["required"]),
+ )
+ self.assertEqual(
+ ["table", "view"],
+ source_tool.inputSchema["properties"]["source_type"]["enum"],
+ )
self.assertEqual(
set(tools["create_semantic_model"].inputSchema["required"]),
{"catalog_name", "schema_name", "name", "definition"},
@@ -610,6 +794,7 @@ class TestSemanticModelToolWithMockOperation(unittest.IsolatedAsyncioTestCase):
("list_of_semantic_models", _NAMESPACE, []),
("list_metrics", _NAMESPACE, []),
("list_metric_infos", _NAMESPACE, []),
+ ("list_semantic_model_datasets", _SOURCE_ARGS, []),
("load_semantic_model", model_args, model),
(
"create_semantic_model",