(cond *Condition)
| 144 | } |
| 145 | |
| 146 | func (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 | |
| 183 | func (b *sqlExprBuilder) writeJoinedExpressions(exprs []*Expression, joiner string) error { |
| 184 | if len(exprs) == 0 { |
no test coverage detected