use of io.prestosql.spi.function.FunctionMetadata in project hetu-core by openlookeng.
the class ClickHouseRowExpressionConverter 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()) {
return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
}
if (type.isComparisonOperator()) {
final String[] clickHouseCompareOperators = new String[] { "=", ">", "<", ">=", "<=", "!=", "<>" };
if (Arrays.asList(clickHouseCompareOperators).contains(type.getOperator())) {
return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
} else {
String exceptionInfo = "ClickHouse Connector does not support comparison operator " + type.getOperator();
throw new PrestoException(NOT_SUPPORTED, exceptionInfo);
}
}
if (type.equals(OperatorType.SUBSCRIPT)) {
throw new PrestoException(NOT_SUPPORTED, "ClickHouse Connector does not support subscript now");
}
/*
* "Negative" needs to be tested
*/
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()));
}
use of io.prestosql.spi.function.FunctionMetadata in project hetu-core by openlookeng.
the class WindowFunctionValidator method visitFunctionCall.
@Override
protected Void visitFunctionCall(FunctionCall functionCall, Analysis analysis) {
requireNonNull(analysis, "analysis is null");
FunctionMetadata functionMetadata = functionAndTypeManager.getFunctionMetadata(analysis.getFunctionHandle(functionCall));
if (functionMetadata != null && functionMetadata.getFunctionKind() == WINDOW && !functionCall.getWindow().isPresent()) {
throw new SemanticException(WINDOW_REQUIRES_OVER, functionCall, "Window function %s requires an OVER clause", functionMetadata.getName());
}
return super.visitFunctionCall(functionCall, analysis);
}
use of io.prestosql.spi.function.FunctionMetadata 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()));
}
use of io.prestosql.spi.function.FunctionMetadata in project hetu-core by openlookeng.
the class HanaRowExpressionConverter method visitCall.
@Override
public String visitCall(CallExpression call, JdbcConverterContext context) {
FunctionHandle functionHandle = call.getFunctionHandle();
FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(functionHandle);
String functionName = functionMetadata.getName().getObjectName();
if (hanaNotSupportFunctions.contains(functionName)) {
throw new PrestoException(NOT_SUPPORTED, "Hana connector does not support " + functionName);
}
if (standardFunctionResolution.isOperator(functionHandle)) {
return handleOperatorFunction(call, functionMetadata, context);
}
List<String> argumentList = call.getArguments().stream().map(expr -> expr.accept(this, context)).collect(Collectors.toList());
if (standardFunctionResolution.isNotFunction(functionHandle)) {
return format("(NOT %s)", argumentList.get(0));
}
if (standardFunctionResolution.isLikeFunction(functionHandle)) {
return format("(%s LIKE %s)", argumentList.get(0), argumentList.get(1));
}
if (standardFunctionResolution.isArrayConstructor(functionHandle)) {
return format("ARRAY(%s)", Joiner.on(", ").join(argumentList));
}
return functionCall(new QualifiedName(Collections.singletonList(functionName)), false, argumentList, Optional.empty(), Optional.empty(), Optional.empty());
}
use of io.prestosql.spi.function.FunctionMetadata in project hetu-core by openlookeng.
the class LogicalRowExpressions method flipOperatorFunctionWithOneVarOneConstant.
public RowExpression flipOperatorFunctionWithOneVarOneConstant(RowExpression expressions) {
if (expressions instanceof CallExpression) {
CallExpression call = (CallExpression) expressions;
FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
if (functionMetadata.getOperatorType().isPresent() && functionMetadata.getOperatorType().get().isComparisonOperator()) {
if (call.getArguments().get(1) instanceof VariableReferenceExpression && call.getArguments().get(0) instanceof ConstantExpression) {
OperatorType operator;
switch(functionMetadata.getOperatorType().get()) {
case LESS_THAN:
operator = GREATER_THAN;
break;
case LESS_THAN_OR_EQUAL:
operator = GREATER_THAN_OR_EQUAL;
break;
case GREATER_THAN:
operator = LESS_THAN;
break;
case GREATER_THAN_OR_EQUAL:
operator = LESS_THAN_OR_EQUAL;
break;
case IS_DISTINCT_FROM:
operator = IS_DISTINCT_FROM;
break;
case EQUAL:
case NOT_EQUAL:
operator = functionMetadata.getOperatorType().get();
break;
default:
throw new UnsupportedOperationException(format("Unsupported or is not comparison operator: %s", functionMetadata.getOperatorType().get()));
}
List<RowExpression> arguments = new ArrayList<>();
arguments.add(call.getArguments().get(1));
arguments.add(call.getArguments().get(0));
return new CallExpression(operator.name(), functionResolution.comparisonFunction(operator, call.getArguments().get(1).getType(), call.getArguments().get(0).getType()), call.getType(), arguments, Optional.empty());
}
}
}
return expressions;
}
Aggregations