Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import java.util.Map;
import java.util.Set;
import org.apache.iceberg.BaseTable;
import org.apache.iceberg.FieldLabel;
import org.apache.iceberg.Labels;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Snapshot;
import org.apache.iceberg.SupportsLabels;
import org.apache.iceberg.Table;
import org.apache.iceberg.TableOperations;
import org.apache.iceberg.TableUtil;
Expand All @@ -55,6 +58,8 @@ abstract class BaseSparkTable
private static final String LOCATION = "location";
private static final String SORT_ORDER = "sort-order";
private static final String IDENTIFIER_FIELDS = "identifier-fields";
private static final String LABELS_OBJECT_PREFIX = "labels.object.";
private static final String LABELS_FIELD_PREFIX = "labels.field.";
private static final Set<String> RESERVED_PROPERTIES =
ImmutableSet.of(
PROVIDER,
Expand Down Expand Up @@ -157,6 +162,23 @@ public Map<String, String> properties() {
.filter(entry -> !RESERVED_PROPERTIES.contains(entry.getKey()))
.forEach(propsBuilder::put);

// Surface catalog-provided labels (driver-side only; not part of table state) so they are
// visible in DESCRIBE EXTENDED. The tbl.labels metadata table is the queryable counterpart.
if (table instanceof SupportsLabels) {
Labels labels = ((SupportsLabels) table).labels();
labels
.objectLabels()
.forEach((key, value) -> propsBuilder.put(LABELS_OBJECT_PREFIX + key, value));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle collisions with stored table properties here. A table can already have a property such as labels.object.owner; if the catalog also supplies the owner label, both entries are added to the ImmutableMap.Builder, and build() throws, breaking DESCRIBE EXTENDED and SHOW TBLPROPERTIES. The field-label prefix has the same issue. Could we define precedence, filter conflicts, and add coverage for both prefixes?

for (FieldLabel fieldLabels : labels.fields()) {
fieldLabels
.labels()
.forEach(
(key, value) ->
propsBuilder.put(
LABELS_FIELD_PREFIX + fieldLabels.fieldId() + "." + key, value));
}
}

return propsBuilder.build();
}

Expand Down
Loading