Search in sources :

Example 6 with ConversionException

use of io.crate.exceptions.ConversionException in project crate by crate.

the class ImplicitCastFunction method normalizeSymbol.

@Override
public Symbol normalizeSymbol(io.crate.expression.symbol.Function symbol, TransactionContext txnCtx, NodeContext nodeCtx) {
    Symbol argument = symbol.arguments().get(0);
    var targetTypeAsString = (String) ((Input<?>) symbol.arguments().get(1)).value();
    var targetType = parseTypeSignature(targetTypeAsString).createType();
    if (argument.valueType().equals(targetType)) {
        return argument;
    }
    if (argument instanceof Input) {
        Object value = ((Input<?>) argument).value();
        try {
            return Literal.ofUnchecked(targetType, targetType.implicitCast(value));
        } catch (ConversionException e) {
            throw e;
        } catch (ClassCastException | IllegalArgumentException e) {
            throw new ConversionException(argument, targetType);
        }
    }
    return symbol;
}
Also used : ConversionException(io.crate.exceptions.ConversionException) Input(io.crate.data.Input) Symbol(io.crate.expression.symbol.Symbol)

Aggregations

ConversionException (io.crate.exceptions.ConversionException)6 ColumnValidationException (io.crate.exceptions.ColumnValidationException)2 Literal (io.crate.analyze.symbol.Literal)1 Input (io.crate.data.Input)1 SubscriptFunction (io.crate.expression.scalar.SubscriptFunction)1 SubscriptObjectFunction (io.crate.expression.scalar.SubscriptObjectFunction)1 SubscriptRecordFunction (io.crate.expression.scalar.SubscriptRecordFunction)1 ArrayFunction (io.crate.expression.scalar.arithmetic.ArrayFunction)1 ExplicitCastFunction (io.crate.expression.scalar.cast.ExplicitCastFunction)1 ImplicitCastFunction (io.crate.expression.scalar.cast.ImplicitCastFunction)1 TryCastFunction (io.crate.expression.scalar.cast.TryCastFunction)1 CurrentSchemaFunction (io.crate.expression.scalar.systeminformation.CurrentSchemaFunction)1 CurrentSchemasFunction (io.crate.expression.scalar.systeminformation.CurrentSchemasFunction)1 CurrentTimeFunction (io.crate.expression.scalar.timestamp.CurrentTimeFunction)1 CurrentTimestampFunction (io.crate.expression.scalar.timestamp.CurrentTimestampFunction)1 Literal (io.crate.expression.symbol.Literal)1 Symbol (io.crate.expression.symbol.Symbol)1 PgArrayParsingException (io.crate.protocols.postgres.parser.PgArrayParsingException)1 ArrayType (io.crate.types.ArrayType)1 ArrayList (java.util.ArrayList)1