Browse Source

improve api

mq-subscribe
chrislu 8 months ago
parent
commit
0da1b7b0f9
  1. 18
      weed/mq/schema/schema_builder.go
  2. 14
      weed/mq/schema/write_parquet_test.go

18
weed/mq/schema/schema_builder.go

@ -39,16 +39,6 @@ func (rtb *RecordTypeBuilder) SetField(name string, scalarType *schema_pb.Type)
return rtb
}
func (rtb *RecordTypeBuilder) SetLongField(name string) *RecordTypeBuilder {
return rtb.SetField(name, TypeLong)
}
func (rtb *RecordTypeBuilder) SetFloatField(name string) *RecordTypeBuilder {
return rtb.SetField(name, TypeFloat)
}
func (rtb *RecordTypeBuilder) SetStringField(name string) *RecordTypeBuilder {
return rtb.SetField(name, TypeString)
}
func (rtb *RecordTypeBuilder) SetRecordField(name string, recordTypeBuilder *RecordTypeBuilder) *RecordTypeBuilder {
rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{
Name: name,
@ -57,14 +47,6 @@ func (rtb *RecordTypeBuilder) SetRecordField(name string, recordTypeBuilder *Rec
return rtb
}
func (rtb *RecordTypeBuilder) SetListField(name string, elementType *schema_pb.Type) *RecordTypeBuilder {
rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{
Name: name,
Type: &schema_pb.Type{Kind: &schema_pb.Type_ListType{ListType: &schema_pb.ListType{ElementType: elementType}}},
})
return rtb
}
func ListOf(elementType *schema_pb.Type) *schema_pb.Type {
return &schema_pb.Type{Kind: &schema_pb.Type_ListType{ListType: &schema_pb.ListType{ElementType: elementType}}}
}

14
weed/mq/schema/write_parquet_test.go

@ -13,15 +13,15 @@ import (
func TestWriteReadParquet(t *testing.T) {
// create a schema_pb.RecordType
recordType := NewRecordTypeBuilder().
SetLongField("ID").
SetLongField("CreatedAt").
SetField("ID", TypeLong).
SetField("CreatedAt", TypeLong).
SetRecordField("Person", NewRecordTypeBuilder().
SetStringField("zName").
SetListField("emails", TypeString)).
SetStringField("Company").
SetField("zName", TypeString).
SetField("emails", ListOf(TypeString))).
SetField("Company", TypeString).
SetRecordField("Address", NewRecordTypeBuilder().
SetStringField("Street").
SetStringField("City")).Build()
SetField("Street", TypeString).
SetField("City", TypeString)).Build()
fmt.Printf("RecordType: %v\n", recordType)
// create a parquet schema

Loading…
Cancel
Save