Browse Source

rename to WithField()

mq-subscribe
chrislu 8 months ago
parent
commit
5bc1b70a4c
  1. 4
      weed/mq/schema/schema_builder.go
  2. 32
      weed/mq/schema/struct_to_schema_test.go
  3. 18
      weed/mq/schema/to_parquet_levels_test.go
  4. 18
      weed/mq/schema/write_parquet_test.go

4
weed/mq/schema/schema_builder.go

@ -31,7 +31,7 @@ func (rtb *RecordTypeBuilder) RecordTypeEnd() *schema_pb.RecordType {
return rtb.recordType return rtb.recordType
} }
func (rtb *RecordTypeBuilder) SetField(name string, scalarType *schema_pb.Type) *RecordTypeBuilder {
func (rtb *RecordTypeBuilder) WithField(name string, scalarType *schema_pb.Type) *RecordTypeBuilder {
rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{ rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{
Name: name, Name: name,
Type: scalarType, Type: scalarType,
@ -39,7 +39,7 @@ func (rtb *RecordTypeBuilder) SetField(name string, scalarType *schema_pb.Type)
return rtb return rtb
} }
func (rtb *RecordTypeBuilder) SetRecordField(name string, recordType *schema_pb.RecordType) *RecordTypeBuilder {
func (rtb *RecordTypeBuilder) WithRecordField(name string, recordType *schema_pb.RecordType) *RecordTypeBuilder {
rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{ rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{
Name: name, Name: name,
Type: &schema_pb.Type{Kind: &schema_pb.Type_RecordType{RecordType: recordType}}, Type: &schema_pb.Type{Kind: &schema_pb.Type_RecordType{RecordType: recordType}},

32
weed/mq/schema/struct_to_schema_test.go

@ -31,8 +31,8 @@ func TestStructToSchema(t *testing.T) {
}{}, }{},
}, },
want: RecordTypeBegin(). want: RecordTypeBegin().
SetField("Field1", TypeInteger).
SetField("Field2", TypeString).
WithField("Field1", TypeInteger).
WithField("Field2", TypeString).
RecordTypeEnd(), RecordTypeEnd(),
}, },
{ {
@ -44,8 +44,8 @@ func TestStructToSchema(t *testing.T) {
}{}, }{},
}, },
want: RecordTypeBegin(). want: RecordTypeBegin().
SetField("Field1", ListOf(TypeInteger)).
SetField("Field2", TypeString).
WithField("Field1", ListOf(TypeInteger)).
WithField("Field2", TypeString).
RecordTypeEnd(), RecordTypeEnd(),
}, },
{ {
@ -56,7 +56,7 @@ func TestStructToSchema(t *testing.T) {
}{}, }{},
}, },
want: RecordTypeBegin(). want: RecordTypeBegin().
SetField("Field2", TypeBytes).
WithField("Field2", TypeBytes).
RecordTypeEnd(), RecordTypeEnd(),
}, },
{ {
@ -71,11 +71,11 @@ func TestStructToSchema(t *testing.T) {
}{}, }{},
}, },
want: RecordTypeBegin(). want: RecordTypeBegin().
SetField("Field1", TypeInteger).
SetRecordField("Field2",
WithField("Field1", TypeInteger).
WithRecordField("Field2",
RecordTypeBegin(). RecordTypeBegin().
SetField("Field3", TypeString).
SetField("Field4", TypeInteger).
WithField("Field3", TypeString).
WithField("Field4", TypeInteger).
RecordTypeEnd(), RecordTypeEnd(),
). ).
RecordTypeEnd(), RecordTypeEnd(),
@ -96,14 +96,14 @@ func TestStructToSchema(t *testing.T) {
}{}, }{},
}, },
want: RecordTypeBegin(). want: RecordTypeBegin().
SetField("Field1", TypeInteger).
SetRecordField("Field2", RecordTypeBegin().
SetField("Field3", TypeString).
SetField("Field4", ListOf(TypeInteger)).
SetRecordField("Field5",
WithField("Field1", TypeInteger).
WithRecordField("Field2", RecordTypeBegin().
WithField("Field3", TypeString).
WithField("Field4", ListOf(TypeInteger)).
WithRecordField("Field5",
RecordTypeBegin(). RecordTypeBegin().
SetField("Field6", TypeString).
SetField("Field7", TypeBytes).
WithField("Field6", TypeString).
WithField("Field7", TypeBytes).
RecordTypeEnd(), RecordTypeEnd(),
).RecordTypeEnd(), ).RecordTypeEnd(),
). ).

18
weed/mq/schema/to_parquet_levels_test.go

@ -19,18 +19,18 @@ func TestToParquetLevels(t *testing.T) {
name: "nested type", name: "nested type",
args: args{ args: args{
RecordTypeBegin(). RecordTypeBegin().
SetField("ID", TypeLong).
SetField("CreatedAt", TypeLong).
SetRecordField("Person",
WithField("ID", TypeLong).
WithField("CreatedAt", TypeLong).
WithRecordField("Person",
RecordTypeBegin(). RecordTypeBegin().
SetField("zName", TypeString).
SetField("emails", ListOf(TypeString)).
WithField("zName", TypeString).
WithField("emails", ListOf(TypeString)).
RecordTypeEnd()). RecordTypeEnd()).
SetField("Company", TypeString).
SetRecordField("Address",
WithField("Company", TypeString).
WithRecordField("Address",
RecordTypeBegin(). RecordTypeBegin().
SetField("Street", TypeString).
SetField("City", TypeString).
WithField("Street", TypeString).
WithField("City", TypeString).
RecordTypeEnd()). RecordTypeEnd()).
RecordTypeEnd(), RecordTypeEnd(),
}, },

18
weed/mq/schema/write_parquet_test.go

@ -13,18 +13,18 @@ import (
func TestWriteReadParquet(t *testing.T) { func TestWriteReadParquet(t *testing.T) {
// create a schema_pb.RecordType // create a schema_pb.RecordType
recordType := RecordTypeBegin(). recordType := RecordTypeBegin().
SetField("ID", TypeLong).
SetField("CreatedAt", TypeLong).
SetRecordField("Person",
WithField("ID", TypeLong).
WithField("CreatedAt", TypeLong).
WithRecordField("Person",
RecordTypeBegin(). RecordTypeBegin().
SetField("zName", TypeString).
SetField("emails", ListOf(TypeString)).
WithField("zName", TypeString).
WithField("emails", ListOf(TypeString)).
RecordTypeEnd()). RecordTypeEnd()).
SetField("Company", TypeString).
SetRecordField("Address",
WithField("Company", TypeString).
WithRecordField("Address",
RecordTypeBegin(). RecordTypeBegin().
SetField("Street", TypeString).
SetField("City", TypeString).
WithField("Street", TypeString).
WithField("City", TypeString).
RecordTypeEnd()). RecordTypeEnd()).
RecordTypeEnd() RecordTypeEnd()
fmt.Printf("RecordType: %v\n", recordType) fmt.Printf("RecordType: %v\n", recordType)

Loading…
Cancel
Save