MCPcopy Create free account
hub / github.com/cockscomb/cel2sql / FindFieldType

Method FindFieldType

bq/provider.go:61–105  ·  view source on GitHub ↗
(messageType string, fieldName string)

Source from the content-addressed store, hash-verified

59}
60
61func (p *typeProvider) FindFieldType(messageType string, fieldName string) (*ref.FieldType, bool) {
62 schema, found := p.findSchema(messageType)
63 if !found {
64 return nil, false
65 }
66 var field *bigquery.FieldSchema
67 for _, fieldSchema := range schema {
68 if fieldSchema.Name == fieldName {
69 field = fieldSchema
70 break
71 }
72 }
73 if field == nil {
74 return nil, false
75 }
76 var typ *exprpb.Type
77 switch field.Type {
78 case bigquery.StringFieldType:
79 typ = decls.String
80 case bigquery.BytesFieldType:
81 typ = decls.Bytes
82 case bigquery.BooleanFieldType:
83 typ = decls.Bool
84 case bigquery.IntegerFieldType:
85 typ = decls.Int
86 case bigquery.FloatFieldType:
87 typ = decls.Double
88 case bigquery.TimestampFieldType:
89 typ = decls.Timestamp
90 case bigquery.RecordFieldType:
91 typ = decls.NewObjectType(strings.Join([]string{messageType, fieldName}, "."))
92 case bigquery.DateFieldType:
93 typ = sqltypes.Date
94 case bigquery.TimeFieldType:
95 typ = sqltypes.Time
96 case bigquery.DateTimeFieldType:
97 typ = sqltypes.DateTime
98 }
99 if field.Repeated {
100 typ = decls.NewListType(typ)
101 }
102 return &ref.FieldType{
103 Type: typ,
104 }, true
105}
106
107func (p *typeProvider) NewValue(typeName string, fields map[string]ref.Val) ref.Val {
108 return types.NewErr("unknown type '%s'", typeName)

Callers 1

Calls 1

findSchemaMethod · 0.95

Tested by 1