Skip to content

Commit 5cb42af

Browse files
committed
fix(tests): risingwave ensure field description in test is marked repeated
1 parent f7f59da commit 5cb42af

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

db_proto/sql/risingwave/dialect.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ func (d *DialectRisingwave) createTable(table *schema.Table) error {
168168
}
169169
}
170170

171-
// Determine field type
172-
fieldType := MapFieldType(f.FieldDescriptor)
173-
if f.IsUnique {
174-
fieldType = fieldType + " UNIQUE"
175-
}
171+
// Determine field type
172+
fieldType := MapFieldType(f.FieldDescriptor)
173+
if f.IsUnique {
174+
fieldType = fieldType + " UNIQUE"
175+
}
176176

177177
// Add the column
178178
sb.WriteString(fmt.Sprintf("%s %s", fieldQuotedName, fieldType))

db_proto/sql/risingwave/dialect_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ func TestDialectRisingwave_CreateTable_WithUniqueConstraint(t *testing.T) {
232232
func TestDialectRisingwave_CreateTable_HandlesRepeatedScalarsAsArrays(t *testing.T) {
233233
logger := zap.NewNop()
234234

235-
tagsField := createMockFieldDescriptor("tags", descriptor.FieldDescriptorProto_TYPE_STRING)
236-
nameField := createMockFieldDescriptor("name", descriptor.FieldDescriptorProto_TYPE_STRING)
235+
tagsField := createMockRepeatedFieldDescriptor("tags", descriptor.FieldDescriptorProto_TYPE_STRING)
236+
nameField := createMockFieldDescriptor("name", descriptor.FieldDescriptorProto_TYPE_STRING)
237237

238238
table := &schema.Table{
239239
Name: "users",
@@ -792,6 +792,37 @@ func createMockFieldDescriptor(name string, fieldType descriptor.FieldDescriptor
792792
return fieldDesc
793793
}
794794

795+
// Helper to create a repeated field descriptor
796+
func createMockRepeatedFieldDescriptor(name string, fieldType descriptor.FieldDescriptorProto_Type) *desc.FieldDescriptor {
797+
fieldNumber := int32(1)
798+
label := descriptor.FieldDescriptorProto_LABEL_REPEATED
799+
proto := &descriptor.FieldDescriptorProto{
800+
Name: &name,
801+
Type: &fieldType,
802+
Number: &fieldNumber,
803+
Label: &label,
804+
}
805+
806+
msgProto := &descriptor.DescriptorProto{
807+
Name: stringPtr("TestMessageRepeated"),
808+
Field: []*descriptor.FieldDescriptorProto{proto},
809+
}
810+
811+
fileProto := &descriptor.FileDescriptorProto{
812+
Name: stringPtr("test_repeated.proto"),
813+
MessageType: []*descriptor.DescriptorProto{msgProto},
814+
}
815+
816+
fileDesc, err := desc.CreateFileDescriptor(fileProto)
817+
if err != nil {
818+
panic(err)
819+
}
820+
821+
msgDesc := fileDesc.GetMessageTypes()[0]
822+
fieldDesc := msgDesc.GetFields()[0]
823+
return fieldDesc
824+
}
825+
795826
func stringPtr(s string) *string {
796827
return &s
797828
}

0 commit comments

Comments
 (0)