use of io.prestosql.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT in project hetu-core by openlookeng.
the class ArrayJoin method specializeArrayJoin.
private static BuiltInScalarFunctionImplementation specializeArrayJoin(Map<String, Type> types, FunctionAndTypeManager functionAndTypeManager, List<Boolean> nullableArguments, MethodHandle methodHandle) {
Type type = types.get("T");
List<ArgumentProperty> argumentProperties = nullableArguments.stream().map(nullable -> nullable ? valueTypeArgumentProperty(USE_BOXED_TYPE) : valueTypeArgumentProperty(RETURN_NULL_ON_NULL)).collect(toImmutableList());
if (type instanceof UnknownType) {
return new BuiltInScalarFunctionImplementation(false, argumentProperties, methodHandle.bindTo(null), Optional.of(STATE_FACTORY));
} else {
try {
BuiltInScalarFunctionImplementation castFunction = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionAndTypeManager.lookupCast(CastType.CAST, type.getTypeSignature(), VARCHAR_TYPE_SIGNATURE));
MethodHandle getter;
Class<?> elementType = type.getJavaType();
if (elementType == boolean.class) {
getter = GET_BOOLEAN;
} else if (elementType == double.class) {
getter = GET_DOUBLE;
} else if (elementType == long.class) {
getter = GET_LONG;
} else if (elementType == Slice.class) {
getter = GET_SLICE;
} else {
throw new UnsupportedOperationException("Unsupported type: " + elementType.getName());
}
MethodHandle cast = castFunction.getMethodHandle();
// if the cast doesn't take a ConnectorSession, create an adapter that drops the provided session
if (cast.type().parameterArray()[0] != ConnectorSession.class) {
cast = MethodHandles.dropArguments(cast, 0, ConnectorSession.class);
}
// Adapt a target cast that takes (ConnectorSession, ?) to one that takes (Block, int, ConnectorSession), which will be invoked by the implementation
// The first two arguments (Block, int) are filtered through the element type's getXXX method to produce the underlying value that needs to be passed to
// the cast.
cast = MethodHandles.permuteArguments(cast, MethodType.methodType(Slice.class, cast.type().parameterArray()[1], cast.type().parameterArray()[0]), 1, 0);
cast = MethodHandles.dropArguments(cast, 1, int.class);
cast = MethodHandles.dropArguments(cast, 1, Block.class);
cast = MethodHandles.foldArguments(cast, getter.bindTo(type));
MethodHandle target = MethodHandles.insertArguments(methodHandle, 0, cast);
return new BuiltInScalarFunctionImplementation(false, argumentProperties, target, Optional.of(STATE_FACTORY));
} catch (PrestoException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, String.format("Input type %s not supported", type), e);
}
}
}
use of io.prestosql.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT in project hetu-core by openlookeng.
the class HanaRowExpressionConverter method handleOperatorFunction.
private String handleOperatorFunction(CallExpression call, FunctionMetadata functionMetadata, JdbcConverterContext context) {
Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
OperatorType type = operatorTypeOptional.get();
if (type.equals(OperatorType.CAST)) {
return handleCastOperator(call.getArguments().get(0), call.getType(), context);
}
List<String> argumentList = call.getArguments().stream().map(expr -> expr.accept(this, context)).collect(Collectors.toList());
if (type.isArithmeticOperator()) {
if (type.equals(OperatorType.MODULUS)) {
return format("MOD(%s, %s)", argumentList.get(0), argumentList.get(1));
} else {
return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
}
}
if (type.isComparisonOperator()) {
final String[] hanaCompareOperators = new String[] { "=", ">", "<", ">=", "<=", "!=", "<>" };
if (Arrays.asList(hanaCompareOperators).contains(type.getOperator())) {
return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
} else {
String exceptionInfo = "Hana Connector does not support comparison operator " + type.getOperator();
throw new PrestoException(NOT_SUPPORTED, exceptionInfo);
}
}
if (type.equals(OperatorType.SUBSCRIPT)) {
if (call.getArguments().size() == 2) {
return format("MEMBER_AT(%s, %s)", argumentList.get(0), argumentList.get(1));
}
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal argument num of function " + type.getOperator());
}
if (call.getArguments().size() == 1 && type.equals(OperatorType.NEGATION)) {
String value = argumentList.get(0);
String separator = value.startsWith("-") ? " " : "";
return format("-%s%s", separator, value);
}
throw new PrestoException(NOT_SUPPORTED, String.format("Unknown operator %s in push down", type.getOperator()));
}
Aggregations