convert to parquet schema and value

This commit is contained in:
chrislu
2024-04-17 23:49:21 -07:00
parent ce2b2fa9b2
commit 0847a17484
7 changed files with 358 additions and 84 deletions

View File

@@ -1,32 +1,26 @@
package schema
import (
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
)
type Schema struct {
RecordType *schema_pb.RecordType
indexedFields []*schema_pb.Field
fieldMap map[string]*schema_pb.Field
}
func NewSchema(recordType *schema_pb.RecordType) (*Schema, error) {
var indexedFields []*schema_pb.Field
var largestIndex int32
var fieldMap map[string]*schema_pb.Field
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
fieldMap[field.Name] = field
}
return &Schema{
RecordType: recordType,
indexedFields: indexedFields,
fieldMap: fieldMap,
}, nil
}
func (s *Schema) GetField(name string) (*schema_pb.Field, bool) {
field, ok := s.fieldMap[name]
return field, ok
}