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 {