You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.9 KiB

8 months ago
7 months ago
8 months ago
8 months ago
  1. package schema
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
  4. "sort"
  5. )
  6. var (
  7. TypeBoolean = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_BOOL}}
  8. TypeInt32 = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_INT32}}
  9. TypeInt64 = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_INT64}}
  10. TypeFloat = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_FLOAT}}
  11. TypeDouble = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_DOUBLE}}
  12. TypeBytes = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_BYTES}}
  13. TypeString = &schema_pb.Type{Kind: &schema_pb.Type_ScalarType{schema_pb.ScalarType_STRING}}
  14. )
  15. type RecordTypeBuilder struct {
  16. recordType *schema_pb.RecordType
  17. }
  18. func RecordTypeBegin() *RecordTypeBuilder {
  19. return &RecordTypeBuilder{recordType: &schema_pb.RecordType{}}
  20. }
  21. func (rtb *RecordTypeBuilder) RecordTypeEnd() *schema_pb.RecordType {
  22. // be consistent with parquet.node.go `func (g Group) Fields() []Field`
  23. sort.Slice(rtb.recordType.Fields, func(i, j int) bool {
  24. return rtb.recordType.Fields[i].Name < rtb.recordType.Fields[j].Name
  25. })
  26. return rtb.recordType
  27. }
  28. func (rtb *RecordTypeBuilder) WithField(name string, scalarType *schema_pb.Type) *RecordTypeBuilder {
  29. rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{
  30. Name: name,
  31. Type: scalarType,
  32. })
  33. return rtb
  34. }
  35. func (rtb *RecordTypeBuilder) WithRecordField(name string, recordType *schema_pb.RecordType) *RecordTypeBuilder {
  36. rtb.recordType.Fields = append(rtb.recordType.Fields, &schema_pb.Field{
  37. Name: name,
  38. Type: &schema_pb.Type{Kind: &schema_pb.Type_RecordType{RecordType: recordType}},
  39. })
  40. return rtb
  41. }
  42. func ListOf(elementType *schema_pb.Type) *schema_pb.Type {
  43. return &schema_pb.Type{Kind: &schema_pb.Type_ListType{ListType: &schema_pb.ListType{ElementType: elementType}}}
  44. }