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;
}
Aggregations