aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2024-04-12 22:31:28 -0700
committerchrislu <chris.lu@gmail.com>2024-04-12 22:31:28 -0700
commit6f80dbdfe5cad8c2ca1b111c3da1bc7de65a1c20 (patch)
treec2405d179d1aa3084468343f455632af777395d5
parent53d1d2b78a480ac9b8432b9a78d6f6c48a6cfbf7 (diff)
downloadseaweedfs-6f80dbdfe5cad8c2ca1b111c3da1bc7de65a1c20.tar.xz
seaweedfs-6f80dbdfe5cad8c2ca1b111c3da1bc7de65a1c20.zip
Create schema.go
-rw-r--r--weed/mq/schema/schema.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/weed/mq/schema/schema.go b/weed/mq/schema/schema.go
new file mode 100644
index 000000000..5cb7a8df1
--- /dev/null
+++ b/weed/mq/schema/schema.go
@@ -0,0 +1,32 @@
+package schema
+
+import (
+ "fmt"
+ "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
+)
+
+type Schema struct {
+ RecordType *schema_pb.RecordType
+ indexedFields []*schema_pb.Field
+}
+
+func NewSchema(recordType *schema_pb.RecordType) (*Schema, error) {
+ var indexedFields []*schema_pb.Field
+ var largestIndex int32
+ for _, field := range recordType.Fields {
+ if field.Index > largestIndex {
+ largestIndex = field.Index
+ }
+ if field.Index < 0 {
+ return nil, fmt.Errorf("field %s index %d is negative", field.Name, field.Index)
+ }
+ }
+ indexedFields = make([]*schema_pb.Field, largestIndex+1)
+ for _, field := range recordType.Fields {
+ indexedFields[field.Index] = field
+ }
+ return &Schema{
+ RecordType: recordType,
+ indexedFields: indexedFields,
+ }, nil
+}