MCPcopy Create free account
hub / github.com/rilldata/rill / writeCast

Method writeCast

runtime/metricsview/astexpr.go:146–181  ·  view source on GitHub ↗
(cond *Condition)

Source from the content-addressed store, hash-verified

144}
145
146func (b *sqlExprBuilder) writeCast(cond *Condition) error {
147 b.writeString("CAST(")
148 err := b.writeExpression(cond.Expressions[0])
149 if err != nil {
150 return err
151 }
152 b.writeString(" AS ")
153 switch v := cond.Expressions[1].Value.(type) {
154 case runtimev1.Type:
155 typeStr, err := b.ast.Dialect.CastToDataType(v.Code)
156 if err != nil {
157 return fmt.Errorf("unsupported cast type code: %v", cond.Expressions[1].Value)
158 }
159 b.writeString(typeStr)
160 case map[string]any:
161 // runtimev1.Type will be serialized as map[string]any
162 codeVal, ok := v["code"]
163 if !ok {
164 return fmt.Errorf("unsupported cast type code: %v", cond.Expressions[1].Value)
165 }
166 codeFloat, ok := codeVal.(float64)
167 if !ok {
168 return fmt.Errorf("unsupported cast type code: %v", cond.Expressions[1].Value)
169 }
170 code := runtimev1.Type_Code(int32(codeFloat))
171 typeStr, err := b.ast.Dialect.CastToDataType(code)
172 if err != nil {
173 return fmt.Errorf("unsupported cast type code: %v", cond.Expressions[1].Value)
174 }
175 b.writeString(typeStr)
176 default:
177 return fmt.Errorf("unsupported cast type: %T", cond.Expressions[1].Value)
178 }
179 b.writeByte(')')
180 return nil
181}
182
183func (b *sqlExprBuilder) writeJoinedExpressions(exprs []*Expression, joiner string) error {
184 if len(exprs) == 0 {

Callers 1

writeConditionMethod · 0.95

Calls 5

writeStringMethod · 0.95
writeExpressionMethod · 0.95
writeByteMethod · 0.95
CastToDataTypeMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected