You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by jb...@apache.org on 2026/09/29 04:16:57 UTC
(polaris) branch main updated: Fix a non-array datasets field bypassing semantic model source validation (#5640)
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 679b3b2b1e Fix a non-array datasets field bypassing semantic model source validation (#5640)
679b3b2b1e is described below
commit 679b3b2b1ef09af8f2a2a685554757e5e0e7ae2b
Author: Ayush Saxena <ay...@apache.org>
AuthorDate: Tue Sep 29 09:46:51 2026 +0530
Fix a non-array datasets field bypassing semantic model source validation (#5640)
resolveAndValidateSources returned early when 'datasets' was present but not
an array, so a document sending it in another shape skipped every
dataset.source check and persisted references that were never resolved. The
method's javadoc states the opposite: that validating sources here prevents
clients from persisting dangling references.
A missing 'datasets' still returns early, since there is nothing to validate.
One that is present and not an array now fails with 400, matching how the
neighbouring checks in this method reject wrong-typed input.
---
CHANGELOG.md | 2 ++
.../semanticmodel/SemanticModelCatalog.java | 12 +++++---
.../semanticmodel/SemanticModelCatalogTest.java | 32 ++++++++++++++++++++++
3 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 21694a77f3..42bbe7ec1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -153,6 +153,8 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
### Fixes
+- Semantic models: a `datasets` field that is not a JSON array now returns `400 Bad Request`
+ instead of being silently skipped, which bypassed every `dataset.source` check.
- Re-creating an existing namespace now returns `409 Conflict` instead of `403 Forbidden` when
`OPTIMIZED_SIBLING_CHECK` is on. Namespace creation checks for an existing namespace before
validating locations, as table and view creation already do, so the existing namespace's own
diff --git a/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalog.java b/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalog.java
index b9fd016701..a87fd868f1 100644
--- a/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalog.java
+++ b/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalog.java
@@ -305,9 +305,10 @@ public class SemanticModelCatalog {
* Resolves and validates every {@code dataset.source} in the parsed Ossie document against the
* current catalog. Unlike engine-specific view SQL, {@code dataset.source} is a structured
* catalog identifier, so validating it here prevents every client from persisting dangling
- * references. Every dataset must define a string {@code source}; a missing or non-string source,
- * or one that does not resolve to a {@code TABLE_LIKE} entity, fails with 400 and a JSON-Pointer
- * to the offending dataset.
+ * references. A {@code datasets} field that is present but not an array fails with 400, so the
+ * per-dataset checks cannot be bypassed by sending it in another shape. Every dataset must define
+ * a string {@code source}; a missing or non-string source, or one that does not resolve to a
+ * {@code TABLE_LIKE} entity, fails with 400 and a JSON-Pointer to the offending dataset.
*/
private void resolveAndValidateSources(JsonNode semanticModel) {
if (!semanticModel.isObject()) {
@@ -315,9 +316,12 @@ public class SemanticModelCatalog {
}
JsonNode datasets = semanticModel.get("datasets");
- if (datasets == null || !datasets.isArray()) {
+ if (datasets == null) {
return;
}
+ if (!datasets.isArray()) {
+ throw new BadRequestException("Field 'semantic_model.datasets' must be a JSON array");
+ }
for (int datasetIdx = 0; datasetIdx < datasets.size(); datasetIdx++) {
String pointer = String.format("/semantic_model/datasets/%d/source", datasetIdx);
JsonNode source = datasets.get(datasetIdx).get("source");
diff --git a/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogTest.java b/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogTest.java
index 1e15877642..f9180f6767 100644
--- a/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogTest.java
+++ b/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogTest.java
@@ -186,6 +186,28 @@ class SemanticModelCatalogTest {
.hasMessageContaining("must be a JSON object");
}
+ @Test
+ void createRejectsObjectFormDatasets() {
+ // An object here would otherwise skip every dataset.source check, persisting a model whose
+ // sources were never resolved.
+ String objectDatasets = "{\"name\":\"m\",\"datasets\":{\"d\":{\"source\":\"does.not.exist\"}}}";
+ assertThatThrownBy(() -> catalog.createSemanticModel(IDENTIFIER, doc(objectDatasets)))
+ .isInstanceOf(BadRequestException.class)
+ .hasMessageContaining("'semantic_model.datasets' must be a JSON array");
+ }
+
+ @Test
+ void createAcceptsModelWithoutDatasets() {
+ when(metaStoreManager.generateNewEntityId(any())).thenReturn(new GenerateEntityIdResult(10L));
+ when(metaStoreManager.createEntityIfNotExists(any(), any(), any()))
+ .thenAnswer(SemanticModelCatalogTest::echoPersistedEntity);
+
+ String noDatasets = "{\"name\":\"m\"}";
+
+ assertThatCode(() -> catalog.createSemanticModel(IDENTIFIER, doc(noDatasets)))
+ .doesNotThrowAnyException();
+ }
+
@Test
void createRejectsDatasetWithoutSource() {
String noSource = "{\"name\":\"m\",\"datasets\":[{\"name\":\"d\"}]}";
@@ -248,6 +270,16 @@ class SemanticModelCatalogTest {
assertThat(response.getDocument().getSemanticModel()).isEqualTo(VALID_MODEL_JSON);
}
+ @Test
+ void updateRejectsObjectFormDatasets() {
+ // update shares resolveAndValidateSources with create, so the shape is rejected there too.
+ stubExistingModel(3);
+ String objectDatasets = "{\"name\":\"m\",\"datasets\":{\"d\":{\"source\":\"does.not.exist\"}}}";
+ assertThatThrownBy(() -> catalog.updateSemanticModel(IDENTIFIER, doc(objectDatasets), "3"))
+ .isInstanceOf(BadRequestException.class)
+ .hasMessageContaining("'semantic_model.datasets' must be a JSON array");
+ }
+
@Test
void dropRemovesModel() {
stubExistingModel(1);