mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 20:06:19 +08:00

Some checks are pending
go: build dev binaries / cleanup (push) Waiting to run
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Blocked by required conditions
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Blocked by required conditions
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Blocked by required conditions
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Blocked by required conditions
docker: build dev containers / build-dev-containers (push) Waiting to run
End to End / FUSE Mount (push) Waiting to run
go: build binary / Build (push) Waiting to run
Ceph S3 tests / Ceph S3 tests (push) Waiting to run
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
)
|
|
|
|
type Schema struct {
|
|
RecordType *schema_pb.RecordType
|
|
fieldMap map[string]*schema_pb.Field
|
|
}
|
|
|
|
func NewSchema(recordType *schema_pb.RecordType) (*Schema, error) {
|
|
fieldMap := make(map[string]*schema_pb.Field)
|
|
for _, field := range recordType.Fields {
|
|
fieldMap[field.Name] = field
|
|
}
|
|
return &Schema{
|
|
RecordType: recordType,
|
|
fieldMap: fieldMap,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Schema) GetField(name string) (*schema_pb.Field, bool) {
|
|
field, ok := s.fieldMap[name]
|
|
return field, ok
|
|
}
|
|
|
|
func TypeToString(t *schema_pb.Type) string {
|
|
switch t.Kind.(type) {
|
|
case *schema_pb.Type_ScalarType:
|
|
switch t.GetScalarType() {
|
|
case schema_pb.ScalarType_BOOL:
|
|
return "bool"
|
|
case schema_pb.ScalarType_INT32:
|
|
return "int32"
|
|
case schema_pb.ScalarType_INT64:
|
|
return "int64"
|
|
case schema_pb.ScalarType_FLOAT:
|
|
return "float"
|
|
case schema_pb.ScalarType_DOUBLE:
|
|
return "double"
|
|
case schema_pb.ScalarType_BYTES:
|
|
return "bytes"
|
|
case schema_pb.ScalarType_STRING:
|
|
return "string"
|
|
}
|
|
case *schema_pb.Type_ListType:
|
|
return "list"
|
|
case *schema_pb.Type_RecordType:
|
|
return "record"
|
|
}
|
|
return "unknown"
|
|
}
|