This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new a7535a22c6 [core] Expose snapshot properties in snapshots system table 
(#10933)
a7535a22c6 is described below

commit a7535a22c6a3e470fb12956f2826a5969a344d9e
Author: zhoulii <[email protected]>
AuthorDate: Mon Nov 2 22:42:15 2026 +0800

    [core] Expose snapshot properties in snapshots system table (#10933)
---
 docs/docs/concepts/system-tables.mdx               | 15 +++++--
 .../apache/paimon/table/system/SnapshotsTable.java | 26 +++++++++++-
 .../paimon/table/system/SnapshotsTableTest.java    | 47 +++++++++++++++++++++-
 .../apache/paimon/flink/CatalogTableITCase.java    | 27 +++++++++++++
 4 files changed, 109 insertions(+), 6 deletions(-)

diff --git a/docs/docs/concepts/system-tables.mdx 
b/docs/docs/concepts/system-tables.mdx
index 3286451b22..1f423fba11 100644
--- a/docs/docs/concepts/system-tables.mdx
+++ b/docs/docs/concepts/system-tables.mdx
@@ -74,9 +74,18 @@ ORDER BY snapshot_id DESC;
 ```
 
 Additional columns include manifest-list names, `changelog_record_count`, 
`watermark`,
-`next_row_id`, `operation`, and `writer_version`. Optional metadata can be 
`NULL`, depending on
-the writer and enabled features. See the [Snapshot 
specification](./spec/snapshot) for the meaning
-of these fields.
+`next_row_id`, `operation`, `writer_version`, and `properties`. Optional 
metadata can be `NULL`,
+depending on the writer and enabled features. See the [Snapshot 
specification](./spec/snapshot)
+for the meaning of these fields.
+
+The `properties` column is a `MAP<STRING, STRING>` containing additional 
metadata recorded in each
+snapshot. It is `NULL` when the snapshot has no properties. For example, if a 
writer records a
+`source.batch-id` property, you can query it with:
+
+```sql
+SELECT snapshot_id, properties['source.batch-id'] AS batch_id
+FROM my_table$snapshots;
+```
 
 `total_record_count` and `delta_record_count` are unmerged counts calculated 
from data files, not
 logical row counts. All dedicated data files contribute to these values. For 
example, appending `N`
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java 
b/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
index 75d46b708e..2b4ae3b99e 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/table/system/SnapshotsTable.java
@@ -20,6 +20,7 @@ package org.apache.paimon.table.system;
 
 import org.apache.paimon.Snapshot;
 import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.data.GenericMap;
 import org.apache.paimon.data.GenericRow;
 import org.apache.paimon.data.InternalRow;
 import org.apache.paimon.data.Timestamp;
@@ -50,6 +51,7 @@ import org.apache.paimon.table.source.Split;
 import org.apache.paimon.table.source.TableRead;
 import org.apache.paimon.types.BigIntType;
 import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.MapType;
 import org.apache.paimon.types.RowType;
 import org.apache.paimon.types.TimestampType;
 import org.apache.paimon.utils.IteratorRecordReader;
@@ -66,6 +68,7 @@ import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -111,7 +114,13 @@ public class SnapshotsTable implements ReadonlyTable {
                             new DataField(13, "next_row_id", new 
BigIntType(true)),
                             new DataField(14, "operation", 
SerializationUtils.newStringType(true)),
                             new DataField(
-                                    15, "writer_version", 
SerializationUtils.newStringType(true))));
+                                    15, "writer_version", 
SerializationUtils.newStringType(true)),
+                            new DataField(
+                                    16,
+                                    "properties",
+                                    new MapType(
+                                            
SerializationUtils.newStringType(false),
+                                            
SerializationUtils.newStringType(true)))));
 
     private final FileIO fileIO;
     private final Path location;
@@ -325,6 +334,18 @@ public class SnapshotsTable implements ReadonlyTable {
         }
 
         private InternalRow toRow(Snapshot snapshot) {
+            GenericMap properties = null;
+            if (snapshot.properties() != null) {
+                Map<BinaryString, BinaryString> map = new HashMap<>();
+                snapshot.properties()
+                        .forEach(
+                                (key, value) ->
+                                        map.put(
+                                                BinaryString.fromString(key),
+                                                
BinaryString.fromString(value)));
+                properties = new GenericMap(map);
+            }
+
             return GenericRow.of(
                     snapshot.id(),
                     snapshot.schemaId(),
@@ -346,7 +367,8 @@ public class SnapshotsTable implements ReadonlyTable {
                     snapshot.operation() == null
                             ? null
                             : 
BinaryString.fromString(snapshot.operation().toString()),
-                    BinaryString.fromString(snapshot.writerVersion()));
+                    BinaryString.fromString(snapshot.writerVersion()),
+                    properties);
         }
     }
 }
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
index e04da130b6..23e26d60a2 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/table/system/SnapshotsTableTest.java
@@ -25,10 +25,12 @@ import org.apache.paimon.data.BinaryString;
 import org.apache.paimon.data.GenericRow;
 import org.apache.paimon.data.InternalRow;
 import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.data.serializer.InternalMapSerializer;
 import org.apache.paimon.data.serializer.InternalRowSerializer;
 import org.apache.paimon.fs.FileIO;
 import org.apache.paimon.fs.Path;
 import org.apache.paimon.fs.local.LocalFileIO;
+import org.apache.paimon.manifest.ManifestCommittable;
 import org.apache.paimon.options.ExpireConfig;
 import org.apache.paimon.predicate.Predicate;
 import org.apache.paimon.predicate.PredicateBuilder;
@@ -39,6 +41,7 @@ import org.apache.paimon.schema.TableSchema;
 import org.apache.paimon.table.FileStoreTable;
 import org.apache.paimon.table.FileStoreTableFactory;
 import org.apache.paimon.table.TableTestBase;
+import org.apache.paimon.table.sink.TableCommitImpl;
 import org.apache.paimon.table.source.ReadBuilder;
 import org.apache.paimon.types.DataTypes;
 import org.apache.paimon.utils.SnapshotManager;
@@ -52,7 +55,9 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import static org.apache.paimon.SnapshotTest.newSnapshotManager;
 import static org.apache.paimon.catalog.Identifier.SYSTEM_TABLE_SPLITTER;
@@ -103,6 +108,45 @@ public class SnapshotsTableTest extends TableTestBase {
         assertThat(result).containsExactlyInAnyOrderElementsOf(expectedRow);
     }
 
+    @Test
+    public void testReadSnapshotProperties() throws Exception {
+        ManifestCommittable committable = new ManifestCommittable(0);
+        committable.addProperty("source.batch-id", "42");
+        committable.addProperty("empty", "");
+        committable.addProperty("nullable", null);
+        FileStoreTable table = (FileStoreTable) 
catalog.getTable(identifier(tableName));
+        try (TableCommitImpl commit = 
table.newCommit(commitUser).ignoreEmptyCommit(false)) {
+            commit.commit(committable);
+        }
+
+        int propertiesIndex = 
snapshotsTable.rowType().getFieldIndex("properties");
+        Map<BinaryString, BinaryString> expected = new HashMap<>();
+        expected.put(BinaryString.fromString("source.batch-id"), 
BinaryString.fromString("42"));
+        expected.put(BinaryString.fromString("empty"), 
BinaryString.fromString(""));
+        expected.put(BinaryString.fromString("nullable"), null);
+
+        List<InternalRow> rows = read(snapshotsTable);
+        assertThat(rows).hasSize(3);
+        assertThat(rows.get(0).isNullAt(propertiesIndex)).isTrue();
+        assertThat(rows.get(1).isNullAt(propertiesIndex)).isTrue();
+        assertThat(
+                        InternalMapSerializer.convertToJavaMap(
+                                rows.get(2).getMap(propertiesIndex),
+                                DataTypes.STRING(),
+                                DataTypes.STRING()))
+                .isEqualTo(expected);
+
+        rows = read(snapshotsTable, new int[] {propertiesIndex, 0});
+        assertThat(rows).hasSize(3);
+        assertThat(rows.get(0).isNullAt(0)).isTrue();
+        assertThat(rows.get(1).isNullAt(0)).isTrue();
+        assertThat(rows.get(2).getLong(1)).isEqualTo(3L);
+        assertThat(
+                        InternalMapSerializer.convertToJavaMap(
+                                rows.get(2).getMap(0), DataTypes.STRING(), 
DataTypes.STRING()))
+                .isEqualTo(expected);
+    }
+
     @Test
     public void testReadSnapshotsWithInFilterContainingUnknownId() throws 
Exception {
         PredicateBuilder builder = new 
PredicateBuilder(snapshotsTable.rowType());
@@ -210,7 +254,8 @@ public class SnapshotsTableTest extends TableTestBase {
                             snapshot.operation() == null
                                     ? null
                                     : 
BinaryString.fromString(snapshot.operation().toString()),
-                            
BinaryString.fromString(snapshot.writerVersion())));
+                            BinaryString.fromString(snapshot.writerVersion()),
+                            null));
         }
 
         return expectedRow;
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
index 751e6192b1..0182f55f50 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
@@ -20,7 +20,10 @@ package org.apache.paimon.flink;
 
 import org.apache.paimon.catalog.Catalog;
 import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.manifest.ManifestCommittable;
 import org.apache.paimon.schema.Schema;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.table.sink.TableCommitImpl;
 import org.apache.paimon.types.DataTypes;
 import org.apache.paimon.utils.BlockingIterator;
 import org.apache.paimon.utils.StringUtils;
@@ -212,6 +215,30 @@ public class CatalogTableITCase extends CatalogITCaseBase {
         assertThat(result).contains(Row.of(1L), Row.of(2L), Row.of(3L));
     }
 
+    @Test
+    public void testSnapshotProperties() throws Exception {
+        sql("CREATE TABLE T (a INT)");
+        FileStoreTable table = paimonTable("T");
+        Map<String, String> properties = new HashMap<>();
+        properties.put("source.batch-id", "42");
+        properties.put("empty", "");
+        properties.put("nullable", null);
+        ManifestCommittable committable = new ManifestCommittable(0);
+        properties.forEach(committable::addProperty);
+        try (TableCommitImpl commit = 
table.newCommit("test").ignoreEmptyCommit(false)) {
+            commit.commit(committable);
+            commit.commit(new ManifestCommittable(1));
+        }
+
+        assertThat(sql("SELECT snapshot_id, properties FROM T$snapshots ORDER 
BY snapshot_id"))
+                .containsExactly(Row.of(1L, properties), Row.of(2L, null));
+        assertThat(
+                        sql(
+                                "SELECT snapshot_id, 
properties['source.batch-id'], properties['missing'] "
+                                        + "FROM T$snapshots WHERE 
properties['source.batch-id'] = '42'"))
+                .containsExactly(Row.of(1L, "42", null));
+    }
+
     @Test
     public void testSnapshotsTableWithRecordCount() throws Exception {
         sql("CREATE TABLE T (a INT, b INT)");

Reply via email to