diff --git a/fe/check/checkstyle/suppressions.xml b/fe/check/checkstyle/suppressions.xml
index 906a511b4be278..96d40705bfe670 100644
--- a/fe/check/checkstyle/suppressions.xml
+++ b/fe/check/checkstyle/suppressions.xml
@@ -79,6 +79,8 @@ under the License.
+
+
diff --git a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadata.java b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadata.java
index b8b415f6f88033..b571662d2b0fa0 100644
--- a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadata.java
+++ b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadata.java
@@ -533,6 +533,12 @@ public ConnectorTableSchema getTableSchema(
// parse ITS schema (e.g. t$snapshots -> committed_at/snapshot_id/...). Mirrors legacy
// IcebergSysExternalTable.getSysIcebergTable + getOrCreateSchemaCacheValue; the enable.mapping.*
// flags are threaded by the shared buildTableSchema -> parseSchema (deviation 5).
+ if (IcebergLabelsSysTable.isLabels(iceHandle)) {
+ // $labels is not an iceberg metadata table: its schema is fixed and needs no table load (the
+ // base table's existence was already checked by getTableHandle).
+ return new ConnectorTableSchema(iceHandle.getTableName(),
+ parseSchema(IcebergLabelsSysTable.SCHEMA), "ICEBERG", Collections.emptyMap());
+ }
Table sysTable = loadSysTable(session, iceHandle);
return buildTableSchema(iceHandle.getTableName(), sysTable, sysTable.schema(), false);
}
@@ -833,6 +839,9 @@ public Map getColumnHandles(
// Mirror getTableSchema: wrap the remote load in the auth context. A sys handle resolves the
// metadata-table columns (t$snapshots -> committed_at/...) so the generic scan node can look up
// its pruned sys-table slots by name; a data handle resolves the base table's columns.
+ if (IcebergLabelsSysTable.isLabels(iceHandle)) {
+ return buildColumnHandles(IcebergLabelsSysTable.SCHEMA, false);
+ }
Table table = iceHandle.isSystemTable() ? loadSysTable(session, iceHandle) : loadTable(session, iceHandle);
return buildColumnHandles(table.schema(), !iceHandle.isSystemTable());
}
@@ -1919,6 +1928,9 @@ private boolean isHmsCatalog() {
* excluding it here would be a capability regression vs master. Unlike every other entry, its scan takes
* BE's native reader rather than the JNI serialized-split path (see
* {@code IcebergScanPlanProvider.doPlanPositionDeletesSystemTableScan}).
+ *
+ *
A REST catalog additionally exposes {@code labels} ({@link IcebergLabelsSysTable}), which is not a
+ * {@code MetadataTableType}: its rows are the catalog labels returned with the table load.
*/
@Override
public List listSupportedSysTables(ConnectorSession session,
@@ -1927,6 +1939,9 @@ public List listSupportedSysTables(ConnectorSession session,
for (MetadataTableType type : MetadataTableType.values()) {
names.add(type.name().toLowerCase(Locale.ROOT));
}
+ if (supportsLabels()) {
+ names.add(IcebergLabelsSysTable.NAME);
+ }
return Collections.unmodifiableList(names);
}
@@ -1969,13 +1984,16 @@ public Optional getSysTableHandle(ConnectorSession session
/**
* Whether iceberg exposes a system table named {@code sysName} (case-insensitive). Mirrors
* {@code IcebergSysTable.SUPPORTED_SYS_TABLES}: every {@code MetadataTableType}, {@code POSITION_DELETES}
- * included (see {@link #listSupportedSysTables}). A {@code null} name is simply not exposed (returns
- * false, not NPE).
+ * included (see {@link #listSupportedSysTables}), plus {@code labels} for a REST catalog. A {@code null}
+ * name is simply not exposed (returns false, not NPE).
*/
- private static boolean isSupportedSysTable(String sysName) {
+ private boolean isSupportedSysTable(String sysName) {
if (sysName == null) {
return false;
}
+ if (IcebergLabelsSysTable.NAME.equalsIgnoreCase(sysName)) {
+ return supportsLabels();
+ }
for (MetadataTableType type : MetadataTableType.values()) {
if (type.name().equalsIgnoreCase(sysName)) {
return true;
@@ -1984,6 +2002,11 @@ private static boolean isSupportedSysTable(String sysName) {
return false;
}
+ /** Only a REST catalog returns catalog labels with the table load, so only it exposes {@code $labels}. */
+ private boolean supportsLabels() {
+ return IcebergCatalogProperties.TYPE_REST.equals(catalogProps.getFlavor());
+ }
+
// ========== Write / Transaction (P6.3) ==========
/**
diff --git a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergLabelsSysTable.java b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergLabelsSysTable.java
new file mode 100644
index 00000000000000..a088e4d515e929
--- /dev/null
+++ b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergLabelsSysTable.java
@@ -0,0 +1,49 @@
+// 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.doris.connector.iceberg;
+
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Types;
+
+/**
+ * The {@code t$labels} system table: the catalog-provided labels of an iceberg table loaded from a REST catalog
+ * (apache/iceberg#15750), one row per object-level or field-level label.
+ *
+ *
Unlike every other iceberg system table it is not a {@link org.apache.iceberg.MetadataTableType}: labels
+ * come from the REST load response, not from the table metadata, are not versioned with snapshots, and only a
+ * REST catalog returns them. Rows reflect the table load the statement read, so they follow the iceberg table
+ * cache like the rest of the table's state. The schema mirrors iceberg's proposed {@code LabelsTable}.
+ */
+final class IcebergLabelsSysTable {
+ static final String NAME = "labels";
+
+ static final Schema SCHEMA = new Schema(
+ Types.NestedField.required(1, "scope", Types.StringType.get()),
+ Types.NestedField.optional(2, "field_id", Types.IntegerType.get()),
+ Types.NestedField.optional(3, "field_name", Types.StringType.get()),
+ Types.NestedField.required(4, "key", Types.StringType.get()),
+ Types.NestedField.required(5, "value", Types.StringType.get()));
+
+ private IcebergLabelsSysTable() {
+ }
+
+ /** Whether {@code handle} is a {@code $labels} handle; sys handles carry the lower-cased name. */
+ static boolean isLabels(IcebergTableHandle handle) {
+ return NAME.equals(handle.getSysTableName());
+ }
+}
diff --git a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergScanPlanProvider.java b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergScanPlanProvider.java
index fe1f1fd1da02a5..acbfe7f4587e72 100644
--- a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergScanPlanProvider.java
+++ b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergScanPlanProvider.java
@@ -47,12 +47,14 @@
import org.apache.iceberg.BatchScan;
import org.apache.iceberg.ContentScanTask;
import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DataTask;
import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.DeleteFileIndex;
import org.apache.iceberg.FileContent;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.FileScanTask;
import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.IcebergLabelsDataTask;
import org.apache.iceberg.ManifestContent;
import org.apache.iceberg.ManifestFile;
import org.apache.iceberg.ManifestFiles;
@@ -977,6 +979,9 @@ private List planSystemTableScan(IcebergTableHandle handle,
private List doPlanSystemTableScan(IcebergTableHandle handle,
List columns, Optional filter,
ConnectorSession session) {
+ if (IcebergLabelsSysTable.isLabels(handle)) {
+ return doPlanLabelsSystemTableScan(handle, columns, session);
+ }
Table metadataTable = resolveSysTable(session, handle);
if (isPositionDeletesSysTable(handle)) {
return doPlanPositionDeletesSystemTableScan(handle, metadataTable, columns, filter, session);
@@ -998,27 +1003,8 @@ private List doPlanSystemTableScan(IcebergTableHandle handle
// hand from the requested columns.
List projectedColumns = requestedColumnNames(columns);
if (!projectedColumns.isEmpty()) {
- Schema metadataSchema = metadataTable.schema();
- List projectedFields = new ArrayList<>(projectedColumns.size());
- Set seenFieldIds = new HashSet<>();
- for (String columnName : projectedColumns) {
- NestedField field = metadataSchema.findField(columnName);
- if (field == null) {
- throw new RuntimeException("Column " + columnName
- + " not found in iceberg system table schema " + metadataTable.name());
- }
- if (seenFieldIds.add(field.fieldId())) {
- projectedFields.add(field);
- }
- }
- // Iceberg returns split_offsets only when the last offset is smaller than file_size_in_bytes.
- // Without that dependency, even valid offsets such as [4, 2048] are hidden as null. Append it
- // after the requested columns so BE's positional reads keep their original order.
- if (seenFieldIds.contains(DataFile.SPLIT_OFFSETS.fieldId())
- && seenFieldIds.add(DataFile.FILE_SIZE.fieldId())) {
- projectedFields.add(metadataSchema.findField(DataFile.FILE_SIZE.fieldId()));
- }
- scan = scan.project(new Schema(projectedFields));
+ scan = scan.project(projectSystemTableSchema(
+ metadataTable.schema(), projectedColumns, metadataTable.name()));
}
List ranges = new ArrayList<>();
try (CloseableIterable tasks = scan.planFiles()) {
@@ -1043,6 +1029,58 @@ private static boolean isPositionDeletesSysTable(IcebergTableHandle handle) {
&& MetadataTableType.POSITION_DELETES.name().equalsIgnoreCase(handle.getSysTableName());
}
+ /**
+ * The system-table schema projected to the requested columns, in the order BE lists them in
+ * required_fields: BE's {@code IcebergSysTableJniScanner} reads projected rows positionally. Built by hand
+ * because {@code scan.select(names)} would re-emit the fields in table-schema order. Any dependent metadata
+ * fields are appended after the requested columns.
+ */
+ private static Schema projectSystemTableSchema(Schema schema, List projectedColumns,
+ String tableName) {
+ List projectedFields = new ArrayList<>(projectedColumns.size());
+ Set seenFieldIds = new HashSet<>();
+ for (String columnName : projectedColumns) {
+ NestedField field = schema.findField(columnName);
+ if (field == null) {
+ throw new RuntimeException("Column " + columnName
+ + " not found in iceberg system table schema " + tableName);
+ }
+ if (seenFieldIds.add(field.fieldId())) {
+ projectedFields.add(field);
+ }
+ }
+ // Iceberg returns split_offsets only when the last offset is smaller than file_size_in_bytes.
+ // Without that dependency, even valid offsets such as [4, 2048] are hidden as null. Append it
+ // after the requested columns so BE's positional reads keep their original order.
+ if (seenFieldIds.contains(DataFile.SPLIT_OFFSETS.fieldId())
+ && seenFieldIds.add(DataFile.FILE_SIZE.fieldId())) {
+ projectedFields.add(schema.findField(DataFile.FILE_SIZE.fieldId()));
+ }
+ return new Schema(projectedFields);
+ }
+
+ /**
+ * Plan {@code t$labels}: one serialized split whose {@code StaticDataTask} carries every catalog label of the
+ * base table, read by BE's JNI scanner like any other static metadata table. Labels are not versioned, so
+ * the handle's snapshot pin is ignored (as for {@code $snapshots}/{@code $history}); predicates are left to
+ * the scan node's conjuncts, the row count being bounded by the catalog response.
+ */
+ private List doPlanLabelsSystemTableScan(IcebergTableHandle handle,
+ List columns, ConnectorSession session) {
+ Table base = resolveSysBaseTable(session, handle);
+ List projectedColumns = requestedColumnNames(columns);
+ Schema projectedSchema = projectedColumns.isEmpty()
+ ? IcebergLabelsSysTable.SCHEMA
+ : projectSystemTableSchema(IcebergLabelsSysTable.SCHEMA, projectedColumns,
+ base.name() + "$" + IcebergLabelsSysTable.NAME);
+ DataTask task = IcebergLabelsDataTask.of(
+ base, IcebergLabelsSysTable.SCHEMA, projectedSchema, SYS_TABLE_DUMMY_PATH);
+ return Collections.singletonList(new IcebergScanRange.Builder()
+ .path(SYS_TABLE_DUMMY_PATH)
+ .serializedSplit(IcebergSystemTableSerialization.serializeToBase64(task))
+ .build());
+ }
+
/**
* Plan a {@code $position_deletes} scan. Port of legacy
* {@code IcebergScanNode.doGetPositionDeletesSystemTableSplits} (upstream #65135).
@@ -1328,6 +1366,10 @@ private static boolean isSnapshotIndependentSystemTable(IcebergTableHandle handl
if (!handle.isSystemTable()) {
return false;
}
+ if (IcebergLabelsSysTable.isLabels(handle)) {
+ // Catalog labels come with the table load, not from a snapshot, so a table with no commit has them.
+ return true;
+ }
MetadataTableType type = MetadataTableType.from(handle.getSysTableName());
// Only metadata_log_entries has a creation row before the first data snapshot; every other metadata
// table must preserve the resolved-empty fence or a concurrent first append becomes visible.
@@ -3398,9 +3440,11 @@ Table wrapTableForScan(Table table) {
}
BaseTable baseTable = (BaseTable) table;
TableOperations rawOps = baseTable.operations();
- // Keep the table's metrics reporter: every scan of a Kerberos catalog runs on this wrapper.
+ // Keep the table's metrics reporter and REST catalog labels: every scan of a Kerberos catalog runs on this
+ // wrapper.
return new BaseTable(new IcebergAuthenticatedTableOperations(
- rawOps, new IcebergAuthenticatedFileIO(rawOps.io(), auth)), table.name(), baseTable.reporter());
+ rawOps, new IcebergAuthenticatedFileIO(rawOps.io(), auth)), table.name(), baseTable.reporter(),
+ baseTable.labels());
}
/**
@@ -3413,6 +3457,13 @@ Table wrapTableForScan(Table table) {
* task serialization) in ONE scope — no nested wrap here.
*/
private Table resolveSysTable(ConnectorSession session, IcebergTableHandle handle) {
+ return MetadataTableUtils.createMetadataTableInstance(
+ resolveSysBaseTable(session, handle),
+ MetadataTableType.from(handle.getSysTableName()));
+ }
+
+ /** The base table a system-table scan reads, shared with metadata binding; see {@link #resolveSysTable}. */
+ private Table resolveSysBaseTable(ConnectorSession session, IcebergTableHandle handle) {
IcebergCatalogOps ops = catalogOpsResolver.apply(session);
// Keep the raw base shared with metadata binding and ordinary scan properties. The caller already owns
// the auth scope, and avoiding a fresh load prevents system-table slots and rows crossing generations.
@@ -3428,9 +3479,7 @@ private Table resolveSysTable(ConnectorSession session, IcebergTableHandle handl
() -> ops.loadTable(handle.getDbName(), handle.getTableName())),
() -> ops.loadTable(handle.getDbName(), handle.getTableName()));
rejectServerSideScanPlanning(base, handle);
- return MetadataTableUtils.createMetadataTableInstance(
- base,
- MetadataTableType.from(handle.getSysTableName()));
+ return base;
}
/** This catalog's engine-owned storage services (see {@link ConnectorContext#getStorageContext()}). */
diff --git a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergStatementScope.java b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergStatementScope.java
index 6bb44ce3612ed2..9d687e68b822be 100644
--- a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergStatementScope.java
+++ b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergStatementScope.java
@@ -292,7 +292,7 @@ private static Table snapshotReadTable(Table table, String dbName, String tableN
TableMetadata metadata = operations.current();
// Keep IO, encryption and location behavior from the raw table while pinning only metadata.
return new BaseTable(new IcebergSnapshotTableOperations(operations, metadata),
- table.name(), baseTable.reporter());
+ table.name(), baseTable.reporter(), baseTable.labels());
}
/**
diff --git a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergTableCache.java b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergTableCache.java
index b727259d491fcd..ddc89637b8ea0e 100644
--- a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergTableCache.java
+++ b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergTableCache.java
@@ -314,7 +314,7 @@ private Table snapshotReadTable() {
? operations.current()
: TableMetadataParser.fromJson(snapshotMetadataLocation, snapshotMetadataJson);
return new BaseTable(new IcebergSnapshotTableOperations(operations, metadata),
- table.name(), baseTable.reporter());
+ table.name(), baseTable.reporter(), baseTable.labels());
}
private TableLease tryBorrow() {
diff --git a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/iceberg/IcebergLabelsDataTask.java b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/iceberg/IcebergLabelsDataTask.java
new file mode 100644
index 00000000000000..e8ae091c1c6168
--- /dev/null
+++ b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/iceberg/IcebergLabelsDataTask.java
@@ -0,0 +1,71 @@
+// 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.iceberg;
+
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Builds the single in-memory {@link DataTask} that carries a table's REST catalog labels as rows.
+ *
+ *
Labels (apache/iceberg#15750) are returned by the catalog with each table load and are not part of the
+ * table metadata, so no {@link MetadataTableType} can produce them. This split-package helper builds an iceberg
+ * {@link StaticDataTask} directly (its constructors are package-private) so the task serializes and is read by
+ * BE's {@code IcebergSysTableJniScanner} exactly like the SDK's own static metadata tables. The metadata file is
+ * synthesized rather than built from an {@code InputFile}, which would issue a storage HEAD for its length.
+ */
+public final class IcebergLabelsDataTask {
+ public static final String OBJECT_SCOPE = "object";
+ public static final String FIELD_SCOPE = "field";
+
+ private IcebergLabelsDataTask() {
+ }
+
+ /**
+ * Returns a task with one row per label: {@code (scope, field_id, field_name, key, value)}. Field labels
+ * resolve {@code field_name} against the current table schema, so a label on a dropped field keeps its
+ * {@code field_id} with a null {@code field_name}.
+ */
+ public static DataTask of(Table table, Schema labelsSchema, Schema projectedSchema, String path) {
+ Preconditions.checkState(table instanceof SupportsLabels,
+ "Iceberg table %s does not expose catalog labels", table.name());
+ Labels labels = ((SupportsLabels) table).labels();
+ Schema tableSchema = table.schema();
+ List rows = new ArrayList<>();
+ for (Map.Entry label : labels.objectLabels().entrySet()) {
+ rows.add(StaticDataTask.Row.of(OBJECT_SCOPE, null, null, label.getKey(), label.getValue()));
+ }
+ for (FieldLabel field : labels.fields()) {
+ String fieldName = tableSchema.findColumnName(field.fieldId());
+ for (Map.Entry label : field.labels().entrySet()) {
+ rows.add(StaticDataTask.Row.of(
+ FIELD_SCOPE, field.fieldId(), fieldName, label.getKey(), label.getValue()));
+ }
+ }
+ DataFile metadataFile = DataFiles.builder(PartitionSpec.unpartitioned())
+ .withPath(path)
+ .withFileSizeInBytes(0L)
+ .withRecordCount(rows.size())
+ .withFormat(FileFormat.METADATA)
+ .build();
+ return new StaticDataTask(metadataFile, labelsSchema, projectedSchema, rows.toArray(new StructLike[0]));
+ }
+}
diff --git a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadataSysTableTest.java b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadataSysTableTest.java
index 74d4b178756258..d354d7eecc00cc 100644
--- a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadataSysTableTest.java
+++ b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorMetadataSysTableTest.java
@@ -80,6 +80,12 @@ private static IcebergConnectorMetadata metadataWith(
return new IcebergConnectorMetadata(ops, IcebergCatalogProperties.of(Collections.emptyMap()), ctx);
}
+ private static IcebergConnectorMetadata restMetadataWith(RecordingIcebergCatalogOps ops) {
+ Map props = new HashMap<>();
+ props.put(IcebergCatalogProperties.ICEBERG_CATALOG_TYPE, IcebergCatalogProperties.TYPE_REST);
+ return new IcebergConnectorMetadata(ops, IcebergCatalogProperties.of(props), new RecordingConnectorContext());
+ }
+
private static IcebergTableHandle baseHandle() {
return new IcebergTableHandle("db1", "t1");
}
@@ -577,4 +583,48 @@ public void getSysTableHandleEmptyForBlankName() {
.getSysTableHandle(null, baseHandle(), "").isPresent(),
"an empty sys name must yield Optional.empty()");
}
+
+ // ---------------------------------------------------------------------
+ // $labels (REST catalog labels, not a MetadataTableType)
+ // ---------------------------------------------------------------------
+
+ @Test
+ public void listSupportedSysTablesAddsLabelsForRestCatalogOnly() {
+ // WHY: only a REST catalog returns labels with the table load; elsewhere t$labels would always be
+ // empty, so it is not offered. MUTATION: listing labels unconditionally -> non-REST list grows -> red.
+ List expectedRest = expectedSupported();
+ expectedRest.add("labels");
+ Assertions.assertEquals(expectedRest,
+ restMetadataWith(new RecordingIcebergCatalogOps()).listSupportedSysTables(null, baseHandle()));
+ Assertions.assertEquals(expectedSupported(),
+ metadataWith(new RecordingIcebergCatalogOps()).listSupportedSysTables(null, baseHandle()));
+ }
+
+ @Test
+ public void getSysTableHandleResolvesLabelsForRestCatalogOnly() {
+ RecordingIcebergCatalogOps ops = new RecordingIcebergCatalogOps();
+ Optional rest = restMetadataWith(ops).getSysTableHandle(null, baseHandle(), "LABELS");
+
+ Assertions.assertTrue(rest.isPresent());
+ Assertions.assertEquals("labels", ((IcebergTableHandle) rest.get()).getSysTableName());
+ Assertions.assertTrue(ops.log.isEmpty(), "resolving t$labels must not touch the catalog seam");
+ Assertions.assertFalse(metadataWith(new RecordingIcebergCatalogOps())
+ .getSysTableHandle(null, baseHandle(), "labels").isPresent());
+ }
+
+ @Test
+ public void getTableSchemaForLabelsHandleIsFixedAndLoadsNothing() {
+ // WHY: labels has no iceberg metadata table, so the generic sys path (MetadataTableType.from -> null)
+ // cannot build its schema; the schema is fixed and needs no base load. MUTATION: falling through to
+ // loadSysTable -> NPE / a catalog round-trip -> red.
+ RecordingIcebergCatalogOps ops = new RecordingIcebergCatalogOps();
+ IcebergConnectorMetadata md = restMetadataWith(ops);
+ IcebergTableHandle sysHandle = (IcebergTableHandle) md.getSysTableHandle(null, baseHandle(), "labels").get();
+
+ Assertions.assertEquals(Arrays.asList("scope", "field_id", "field_name", "key", "value"),
+ columnNames(md.getTableSchema(null, sysHandle)));
+ Assertions.assertEquals(Arrays.asList("scope", "field_id", "field_name", "key", "value"),
+ new ArrayList<>(md.getColumnHandles(null, sysHandle).keySet()));
+ Assertions.assertTrue(ops.log.isEmpty(), "t$labels schema must not load the base table");
+ }
}
diff --git a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergLabelsDataTaskTest.java b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergLabelsDataTaskTest.java
new file mode 100644
index 00000000000000..b15771c2d68f02
--- /dev/null
+++ b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergLabelsDataTaskTest.java
@@ -0,0 +1,143 @@
+// 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.doris.connector.iceberg;
+
+import org.apache.iceberg.BaseTable;
+import org.apache.iceberg.DataTask;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.IcebergLabelsDataTask;
+import org.apache.iceberg.ImmutableFieldLabel;
+import org.apache.iceberg.ImmutableLabels;
+import org.apache.iceberg.Labels;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.inmemory.InMemoryCatalog;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Tests for the {@code t$labels} rows ({@link IcebergLabelsDataTask}): one row per object-level and field-level
+ * label, projected in the requested order, and carried intact through the system-table serialization that BE's
+ * JNI scanner reads.
+ */
+public class IcebergLabelsDataTaskTest {
+
+ private static final Schema BASE_SCHEMA = new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.optional(2, "email", Types.StringType.get()));
+
+ private static final Labels LABELS = ImmutableLabels.builder()
+ .objectLabels(Collections.singletonMap("owner", "team-a"))
+ .addFields(ImmutableFieldLabel.builder()
+ .fieldId(2)
+ .labels(Collections.singletonMap("classification", "pii"))
+ .build())
+ // Field 7 is not in the current schema (e.g. a dropped column): keep its id, no name.
+ .addFields(ImmutableFieldLabel.builder()
+ .fieldId(7)
+ .labels(Collections.singletonMap("deprecated", "true"))
+ .build())
+ .build();
+
+ private static Table labeledTable(Labels labels) {
+ InMemoryCatalog catalog = new InMemoryCatalog();
+ catalog.initialize("test", Collections.emptyMap());
+ catalog.createNamespace(Namespace.of("db1"));
+ BaseTable table = (BaseTable) catalog.createTable(
+ TableIdentifier.of("db1", "t1"), BASE_SCHEMA, PartitionSpec.unpartitioned());
+ return new BaseTable(table.operations(), table.name(), table.reporter(), labels);
+ }
+
+ /** Reads every row eagerly: StaticDataTask re-wraps one projection per row, so rows cannot be kept. */
+ private static List> read(DataTask task, int width) throws IOException {
+ List> rows = new ArrayList<>();
+ try (CloseableIterable iterable = task.rows()) {
+ for (StructLike row : iterable) {
+ List