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.

32 lines
760 B

10 months ago
  1. package schema
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
  5. )
  6. type Schema struct {
  7. RecordType *schema_pb.RecordType
  8. indexedFields []*schema_pb.Field
  9. }
  10. func NewSchema(recordType *schema_pb.RecordType) (*Schema, error) {
  11. var indexedFields []*schema_pb.Field
  12. var largestIndex int32
  13. for _, field := range recordType.Fields {
  14. if field.Index > largestIndex {
  15. largestIndex = field.Index
  16. }
  17. if field.Index < 0 {
  18. return nil, fmt.Errorf("field %s index %d is negative", field.Name, field.Index)
  19. }
  20. }
  21. indexedFields = make([]*schema_pb.Field, largestIndex+1)
  22. for _, field := range recordType.Fields {
  23. indexedFields[field.Index] = field
  24. }
  25. return &Schema{
  26. RecordType: recordType,
  27. indexedFields: indexedFields,
  28. }, nil
  29. }