use of io.prestosql.spi.function.FunctionHandle in project hetu-core by openlookeng.
the class TestDynamicFilters method testExtractDynamicFiltersAsUnion.
@Test
public void testExtractDynamicFiltersAsUnion() {
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
ConstantExpression staticExpression1 = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
VariableReferenceExpression variableExpression1 = new VariableReferenceExpression("col1", VarcharType.VARCHAR);
ConstantExpression staticExpression2 = new ConstantExpression(utf8Slice("id"), VarcharType.VARCHAR);
VariableReferenceExpression variableExpression2 = new VariableReferenceExpression("col2", VarcharType.VARCHAR);
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
RowExpression dynamicFilterExpression1 = call(DynamicFilters.Function.NAME, functionHandle, staticExpression1.getType(), asList(staticExpression1, variableExpression1), Optional.empty());
RowExpression dynamicFilterExpression2 = call(DynamicFilters.Function.NAME, functionHandle, staticExpression2.getType(), asList(staticExpression2, variableExpression2), Optional.empty());
List<DynamicFilters.Descriptor> dynamicFilter1 = new ArrayList<>();
dynamicFilter1.add(new DynamicFilters.Descriptor("age", variableExpression1, Optional.empty()));
List<DynamicFilters.Descriptor> dynamicFilter2 = new ArrayList<>();
dynamicFilter2.add(new DynamicFilters.Descriptor("id", variableExpression2, Optional.empty()));
List<List<DynamicFilters.Descriptor>> dynamicFilterUnion = new ArrayList<>();
dynamicFilterUnion.add(dynamicFilter1);
dynamicFilterUnion.add(dynamicFilter2);
RowExpression combineDynamicFilterExpression = logicalRowExpressions.combineDisjuncts(asList(dynamicFilterExpression1, dynamicFilterExpression2));
RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression1, combineDynamicFilterExpression);
List<List<DynamicFilters.Descriptor>> extractedExpression = DynamicFilters.extractDynamicFiltersAsUnion(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression, dynamicFilterUnion);
}
use of io.prestosql.spi.function.FunctionHandle in project hetu-core by openlookeng.
the class BaseJdbcRowExpressionConverter method visitCall.
@Override
public String visitCall(CallExpression call, JdbcConverterContext context) {
// remote udf verify
FunctionHandle functionHandle = call.getFunctionHandle();
if (!isDefaultFunction(call)) {
throw new PrestoException(NOT_SUPPORTED, String.format("This connector do not support push down %s.%s", functionHandle.getFunctionNamespace(), call.getDisplayName()));
}
context.setDefaultFunctionVisited(true);
if (!isDeterministic(rowExpressionService.getDeterminismEvaluator(), call)) {
throw new PrestoException(NOT_SUPPORTED, "Unsupported not deterministic function push down.");
}
if (standardFunctionResolution.isNotFunction(functionHandle)) {
return format("(NOT %s)", call.getArguments().get(0).accept(this, context));
}
if (standardFunctionResolution.isTryFunction(functionHandle)) {
return format("TRY(%s)", call.getArguments().get(0).accept(this, context));
}
if (standardFunctionResolution.isLikeFunction(functionHandle)) {
return format("(%s LIKE %s)", call.getArguments().get(0).accept(this, context), call.getArguments().get(1).accept(this, context));
}
if (standardFunctionResolution.isArrayConstructor(functionHandle)) {
String arguments = Joiner.on(",").join(call.getArguments().stream().map(expression -> expression.accept(this, context)).collect(toList()));
return format("ARRAY[%s]", arguments);
}
FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(functionHandle);
if (standardFunctionResolution.isOperator(functionHandle)) {
return handleOperator(call, functionMetadata, context);
}
if (functionMetadata.getName().getObjectName().equals(TIMESTAMP_LITERAL)) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
long time = (long) ((ConstantExpression) call.getArguments().get(0)).getValue();
return format("TIMESTAMP '%s'", formatter.format(Instant.ofEpochMilli(time).atZone(UTC).toLocalDateTime()));
}
return handleFunction(call, functionMetadata, context);
}
use of io.prestosql.spi.function.FunctionHandle in project hetu-core by openlookeng.
the class BaseJdbcRowExpressionConverter method handleOperator.
private String handleOperator(CallExpression call, FunctionMetadata functionMetadata, JdbcConverterContext context) {
FunctionHandle functionHandle = call.getFunctionHandle();
List<RowExpression> arguments = call.getArguments();
if (standardFunctionResolution.isCastFunction(functionHandle)) {
if (call.getType().getDisplayName().equals(LIKE_PATTERN_NAME)) {
return arguments.get(0).accept(this, context);
}
return format("CAST(%s AS %s)", arguments.get(0).accept(this, context), call.getType().getDisplayName());
}
if (call.getArguments().size() == 1 && standardFunctionResolution.isNegateFunction(functionHandle)) {
String value = call.getArguments().get(0).accept(this, context);
String separator = value.startsWith("-") ? " " : "";
return format("-%s%s", separator, value);
}
Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
if (operatorTypeOptional.isPresent() && arguments.size() == 2 && (standardFunctionResolution.isComparisonFunction(functionHandle) || standardFunctionResolution.isArithmeticFunction(functionHandle))) {
return format("(%s %s %s)", arguments.get(0).accept(this, context), operatorTypeOptional.get().getOperator(), arguments.get(1).accept(this, context));
}
if (standardFunctionResolution.isSubscriptFunction(functionHandle)) {
String base = call.getArguments().get(0).accept(this, context);
String index = call.getArguments().get(1).accept(this, context);
return format("%s[%s]", base, index);
}
throw new PrestoException(NOT_SUPPORTED, String.format("Unknown operator %s in push down", operatorTypeOptional));
}
use of io.prestosql.spi.function.FunctionHandle in project hetu-core by openlookeng.
the class SplitFiltering method isSupportedExpression.
private static boolean isSupportedExpression(RowExpression predicate) {
if (predicate instanceof SpecialForm) {
SpecialForm specialForm = (SpecialForm) predicate;
switch(specialForm.getForm()) {
case BETWEEN:
case IN:
return true;
case AND:
case OR:
return isSupportedExpression(specialForm.getArguments().get(0)) && isSupportedExpression(specialForm.getArguments().get(1));
default:
return false;
}
}
if (predicate instanceof CallExpression) {
CallExpression call = (CallExpression) predicate;
FunctionHandle builtInFunctionHandle = call.getFunctionHandle();
if (builtInFunctionHandle instanceof BuiltInFunctionHandle) {
Signature signature = ((BuiltInFunctionHandle) builtInFunctionHandle).getSignature();
if (signature.getName().getObjectName().equals("not")) {
return true;
}
try {
OperatorType operatorType = Signature.unmangleOperator(signature.getName().getObjectName());
if (operatorType.isComparisonOperator() && operatorType != IS_DISTINCT_FROM) {
return true;
}
return false;
} catch (IllegalArgumentException e) {
return false;
}
}
}
return false;
}
use of io.prestosql.spi.function.FunctionHandle in project hetu-core by openlookeng.
the class SplitFiltering method extractExpression.
private static RowExpression extractExpression(RowExpression expression) {
if (expression instanceof CallExpression) {
FunctionHandle builtInFunctionHandle = ((CallExpression) expression).getFunctionHandle();
Signature signature;
if (builtInFunctionHandle instanceof BuiltInFunctionHandle) {
signature = ((BuiltInFunctionHandle) builtInFunctionHandle).getSignature();
if (signature.getName().getObjectName().contains("CAST")) {
// extract the inner expression for CAST expressions
return extractExpression(((CallExpression) expression).getArguments().get(0));
}
}
}
return expression;
}
Aggregations