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 11:24:25 UTC

(polaris) branch main updated: Omit null LOAD_TABLE_RESPONSE on conditional loadTable after-event (#5638)

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 098a7b5575 Omit null LOAD_TABLE_RESPONSE on conditional loadTable after-event (#5638)
098a7b5575 is described below

commit 098a7b557555a5f7616917d4fac7a5f8216f9e7c
Author: vignesh_A <16...@users.noreply.github.com>
AuthorDate: Tue Sep 29 16:54:20 2026 +0530

    Omit null LOAD_TABLE_RESPONSE on conditional loadTable after-event (#5638)
---
 CHANGELOG.md                                       |   3 +
 .../IcebergRestCatalogEventServiceDelegator.java   |  17 ++-
 .../listeners/PolarisPersistenceEventListener.java |   4 +
 ...tCatalogEventServiceDelegatorLoadTableTest.java | 159 +++++++++++++++++++++
 .../PolarisPersistenceEventListenerTest.java       |  23 +++
 5 files changed, 200 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 314c42779b..30e325fa89 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -156,6 +156,9 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
 
 - 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.
+- Conditional `loadTable` (`If-None-Match` → HTTP 304) no longer attaches a null
+  `LOAD_TABLE_RESPONSE` to the `AFTER_LOAD_TABLE` event. The persistence event listener also
+  skips null attribute values instead of failing while pruning them.
 - 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/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegator.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegator.java
index f3e32bcea8..089306278b 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegator.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegator.java
@@ -437,16 +437,21 @@ public class IcebergRestCatalogEventServiceDelegator
             realmContext,
             securityContext);
     if (polarisEventDispatcher.hasListeners(PolarisEventType.AFTER_LOAD_TABLE)) {
+      // Conditional GET (If-None-Match match) returns 304 notModified() with no entity. Do not
+      // cast/store a null LOAD_TABLE_RESPONSE on the after-event.
+      ImmutableAttributeMap.Builder afterAttributes =
+          ImmutableAttributeMap.builder()
+              .put(EventAttributes.CATALOG_NAME, catalogName)
+              .put(EventAttributes.NAMESPACE, namespaceObj)
+              .put(EventAttributes.TABLE_NAME, table);
+      if (resp.getEntity() instanceof LoadTableResponse loadTableResponse) {
+        afterAttributes.put(EventAttributes.LOAD_TABLE_RESPONSE, loadTableResponse);
+      }
       polarisEventDispatcher.dispatch(
           new PolarisEvent(
               PolarisEventType.AFTER_LOAD_TABLE,
               eventMetadataFactory.create(),
-              ImmutableAttributeMap.builder()
-                  .put(EventAttributes.CATALOG_NAME, catalogName)
-                  .put(EventAttributes.NAMESPACE, namespaceObj)
-                  .put(EventAttributes.TABLE_NAME, table)
-                  .put(EventAttributes.LOAD_TABLE_RESPONSE, (LoadTableResponse) resp.getEntity())
-                  .build()));
+              afterAttributes.build()));
     }
     return resp;
   }
diff --git a/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListener.java b/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListener.java
index 20c2233884..74c15f69d6 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListener.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListener.java
@@ -261,6 +261,10 @@ public abstract class PolarisPersistenceEventListener implements PolarisEventLis
     AttributeMap.AttributeKey<?> key = attribute.key();
     Object value = attribute.value();
 
+    if (value == null) {
+      return Map.of();
+    }
+
     if (value instanceof String || value instanceof Number || value instanceof Boolean) {
       return Map.of(key.key(), value.toString());
     }
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegatorLoadTableTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegatorLoadTableTest.java
new file mode 100644
index 0000000000..87c002edb4
--- /dev/null
+++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergRestCatalogEventServiceDelegatorLoadTableTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+package org.apache.polaris.service.catalog.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.core.SecurityContext;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.rest.responses.LoadTableResponse;
+import org.apache.iceberg.types.Types;
+import org.apache.polaris.core.collection.MutableAttributeMap;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.service.catalog.CatalogPrefixParser;
+import org.apache.polaris.service.events.EventAttributes;
+import org.apache.polaris.service.events.PolarisEvent;
+import org.apache.polaris.service.events.PolarisEventDispatcher;
+import org.apache.polaris.service.events.PolarisEventMetadata;
+import org.apache.polaris.service.events.PolarisEventMetadataFactory;
+import org.apache.polaris.service.events.PolarisEventType;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * Conditional GET (304 notModified) has no response entity; AFTER_LOAD_TABLE must not store a null
+ * LOAD_TABLE_RESPONSE.
+ */
+public class IcebergRestCatalogEventServiceDelegatorLoadTableTest {
+
+  private IcebergCatalogAdapter delegate;
+  private PolarisEventDispatcher eventDispatcher;
+  private PolarisEventMetadataFactory eventMetadataFactory;
+  private CatalogPrefixParser prefixParser;
+  private IcebergRestCatalogEventServiceDelegator delegator;
+
+  @BeforeEach
+  void setUp() {
+    delegate = mock(IcebergCatalogAdapter.class);
+    eventDispatcher = mock(PolarisEventDispatcher.class);
+    eventMetadataFactory = mock(PolarisEventMetadataFactory.class);
+    prefixParser = mock(CatalogPrefixParser.class);
+    when(prefixParser.prefixToCatalogName(anyString())).thenReturn("test-catalog");
+    when(eventMetadataFactory.create())
+        .thenReturn(PolarisEventMetadata.builder().realmId("test-realm").build());
+    when(eventDispatcher.hasListeners(any())).thenReturn(false);
+    when(eventDispatcher.hasListeners(PolarisEventType.AFTER_LOAD_TABLE)).thenReturn(true);
+
+    delegator =
+        new IcebergRestCatalogEventServiceDelegator(
+            delegate,
+            eventDispatcher,
+            eventMetadataFactory,
+            prefixParser,
+            new MutableAttributeMap());
+  }
+
+  @Test
+  void afterLoadTableOmitsResponseWhenNotModified() {
+    when(delegate.loadTable(
+            anyString(),
+            anyString(),
+            anyString(),
+            any(),
+            any(),
+            any(),
+            any(),
+            any(RealmContext.class),
+            any(SecurityContext.class)))
+        .thenReturn(Response.notModified().build());
+
+    Response response =
+        delegator.loadTable(
+            "prefix",
+            "ns",
+            "t1",
+            null,
+            "W/\"etag\"",
+            null,
+            null,
+            mock(RealmContext.class),
+            mock(SecurityContext.class));
+
+    assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_MODIFIED.getStatusCode());
+    assertThat(response.getEntity()).isNull();
+
+    ArgumentCaptor<PolarisEvent> eventCaptor = ArgumentCaptor.forClass(PolarisEvent.class);
+    verify(eventDispatcher).dispatch(eventCaptor.capture());
+    PolarisEvent afterEvent = eventCaptor.getValue();
+    assertThat(afterEvent.type()).isEqualTo(PolarisEventType.AFTER_LOAD_TABLE);
+    assertThat(afterEvent.attributes().containsKey(EventAttributes.LOAD_TABLE_RESPONSE)).isFalse();
+    assertThat(afterEvent.attributes().get(EventAttributes.TABLE_NAME)).isEqualTo("t1");
+  }
+
+  @Test
+  void afterLoadTableIncludesResponseWhenEntityPresent() {
+    TableMetadata metadata =
+        TableMetadata.buildFromEmpty()
+            .assignUUID()
+            .setLocation("file:///tmp/t1")
+            .addSchema(new Schema(Types.NestedField.required(1, "id", Types.LongType.get())))
+            .addPartitionSpec(PartitionSpec.unpartitioned())
+            .addSortOrder(SortOrder.unsorted())
+            .build();
+    LoadTableResponse loadTableResponse =
+        LoadTableResponse.builder().withTableMetadata(metadata).build();
+    when(delegate.loadTable(
+            anyString(),
+            anyString(),
+            anyString(),
+            any(),
+            any(),
+            any(),
+            any(),
+            any(RealmContext.class),
+            any(SecurityContext.class)))
+        .thenReturn(Response.ok(loadTableResponse).build());
+
+    delegator.loadTable(
+        "prefix",
+        "ns",
+        "t1",
+        null,
+        null,
+        null,
+        null,
+        mock(RealmContext.class),
+        mock(SecurityContext.class));
+
+    ArgumentCaptor<PolarisEvent> eventCaptor = ArgumentCaptor.forClass(PolarisEvent.class);
+    verify(eventDispatcher).dispatch(eventCaptor.capture());
+    assertThat(eventCaptor.getValue().attributes().get(EventAttributes.LOAD_TABLE_RESPONSE))
+        .isSameAs(loadTableResponse);
+  }
+}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListenerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListenerTest.java
index d82e6473c9..09433c6627 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListenerTest.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/PolarisPersistenceEventListenerTest.java
@@ -271,6 +271,29 @@ class PolarisPersistenceEventListenerTest {
         .doesNotContainKey(EventAttributes.LOAD_TABLE_RESPONSE.key());
   }
 
+  @Test
+  void shouldSkipNullLoadTableResponseWithoutNpe() {
+    CapturingPersistenceListener listener = new CapturingPersistenceListener();
+
+    // Conditional GET after-event can omit a body; a null attribute must not crash pruning.
+    listener.onEvent(
+        new PolarisEvent(
+            PolarisEventType.AFTER_LOAD_TABLE,
+            metadata(),
+            ImmutableAttributeMap.builder()
+                .put(EventAttributes.CATALOG_NAME, CATALOG_NAME)
+                .put(EventAttributes.NAMESPACE, NAMESPACE)
+                .put(EventAttributes.TABLE_NAME, TABLE_NAME)
+                .put(EventAttributes.LOAD_TABLE_RESPONSE, null)
+                .build()));
+
+    EventEntity persisted = listener.persistedEvent(PolarisEventType.AFTER_LOAD_TABLE);
+    assertThat(persisted).isNotNull();
+    assertThat(additionalProperties(persisted))
+        .containsEntry(EventAttributes.CATALOG_NAME.key(), CATALOG_NAME)
+        .doesNotContainKey(EventAttributes.LOAD_TABLE_RESPONSE.key());
+  }
+
   @Test
   void shouldResolveViewRenameIdentifier() {
     CapturingPersistenceListener listener = new CapturingPersistenceListener();