WithResolvedChildren implements the vitess.InjectableExpression interface.
(ctx context.Context, children []any)
| 191 | |
| 192 | // WithResolvedChildren implements the vitess.InjectableExpression interface. |
| 193 | func (c *ExplicitCast) WithResolvedChildren(ctx context.Context, children []any) (any, error) { |
| 194 | if len(children) != 1 { |
| 195 | return nil, errors.Errorf("invalid vitess child count, expected `1` but got `%d`", len(children)) |
| 196 | } |
| 197 | resolvedExpression, ok := children[0].(sql.Expression) |
| 198 | if !ok { |
| 199 | return nil, errors.Errorf("expected vitess child to be an expression but has type `%T`", children[0]) |
| 200 | } |
| 201 | if !c.castToType.IsResolvedType() { |
| 202 | sqlCtx, ok := ctx.(*sql.Context) |
| 203 | if !ok { |
| 204 | return nil, errors.Errorf("%T requires a SQL context for type resolution", c) |
| 205 | } |
| 206 | typeColl, err := core.GetTypesCollectionFromContext(sqlCtx, "") |
| 207 | if err != nil { |
| 208 | return nil, err |
| 209 | } |
| 210 | resolvedType, err := typeColl.ResolveType(sqlCtx, c.castToType.ID) |
| 211 | if err != nil { |
| 212 | return nil, err |
| 213 | } |
| 214 | c.castToType = resolvedType |
| 215 | } |
| 216 | if !c.castToType.IsDefined { |
| 217 | return nil, pgtypes.ErrTypeIsOnlyAShell.New(c.castToType.Name()) |
| 218 | } |
| 219 | return &ExplicitCast{ |
| 220 | sqlChild: resolvedExpression, |
| 221 | castToType: c.castToType, |
| 222 | domainNullable: c.domainNullable, |
| 223 | domainChecks: c.domainChecks, |
| 224 | }, nil |
| 225 | } |
| 226 | |
| 227 | // WithCastToType returns a copy of the expression with castToType replaced. |
| 228 | func (c *ExplicitCast) WithCastToType(t *pgtypes.DoltgresType) sql.Expression { |
nothing calls this directly
no test coverage detected