From 667084ee77ca38dc823c1530a69aadeb4dc8a698 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 1 Dec 2026 17:32:37 -0800 Subject: [PATCH] mq: reserve the day partition field's name in a topic's table layout The spec partitions by day(_ts) under the name _ts_day, and Iceberg only lets a partition field share a column's name when it is that column's identity. A topic with its own _ts_day field mapped fine and then failed the table create with an invalid partition spec. Schema now refuses the name up front, with the system columns, saying it is reserved. Co-Authored-By: Claude Opus 5.5 --- weed/mq/topictable/layout.go | 10 ++++++---- weed/mq/topictable/layout_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/weed/mq/topictable/layout.go b/weed/mq/topictable/layout.go index bb0758fd87..adb94895b6 100644 --- a/weed/mq/topictable/layout.go +++ b/weed/mq/topictable/layout.go @@ -59,8 +59,8 @@ func Schema(recordType *schema_pb.RecordType) (*iceberg.Schema, error) { fields = append(fields, iceberg.NestedField{Name: ValueColumn, Type: iceberg.PrimitiveTypes.Binary}) } else { for _, field := range recordType.Fields { - if isSystemColumn(field.Name) { - return nil, fmt.Errorf("field %s: name is reserved for a system column", field.Name) + if isReservedName(field.Name) { + return nil, fmt.Errorf("field %s: name is reserved for a system column or partition field", field.Name) } mapped, err := mapField(field) if err != nil { @@ -72,9 +72,11 @@ func Schema(recordType *schema_pb.RecordType) (*iceberg.Schema, error) { return iceberg.AssignFreshSchemaIDs(iceberg.NewSchema(0, fields...), nil) } -func isSystemColumn(name string) bool { +// isReservedName reports a name the table layout itself uses: a partition +// field sharing a column's name only binds when it is that column's identity. +func isReservedName(name string) bool { switch name { - case PartitionColumn, OffsetColumn, TsNsColumn, TsColumn, KeyColumn, ValueColumn: + case PartitionColumn, OffsetColumn, TsNsColumn, TsColumn, KeyColumn, ValueColumn, TsDayField: return true } return false diff --git a/weed/mq/topictable/layout_test.go b/weed/mq/topictable/layout_test.go index c1189eca7c..5b801432de 100644 --- a/weed/mq/topictable/layout_test.go +++ b/weed/mq/topictable/layout_test.go @@ -256,6 +256,15 @@ func TestCheckSchema(t *testing.T) { } } +// A field named like a partition field would make the spec unbindable, so the +// schema refuses it up front. +func TestSchemaReservesPartitionFieldNames(t *testing.T) { + _, err := Schema(&schema_pb.RecordType{Fields: []*schema_pb.Field{scalarField(TsDayField, schema_pb.ScalarType_INT32, false)}}) + if err == nil || !strings.Contains(err.Error(), "reserved") { + t.Fatalf("got %v, want %s refused as reserved", err, TsDayField) + } +} + // Topics whose names only split differently own different tables. func TestTopicPropertyValueIsUnambiguous(t *testing.T) { if a, b := TopicPropertyValue(topic.NewTopic("a.b", "c")), TopicPropertyValue(topic.NewTopic("a", "b.c")); a == b {