use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.
the class TestHivePageSourceProvider method testModifyDomainLessThanOrEqual.
@Test
public void testModifyDomainLessThanOrEqual() {
Collection<Object> valueSet = new HashSet<>();
valueSet.add(Long.valueOf(40));
VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$less_than_or_equal");
BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
CallExpression filter = new CallExpression("LESS_THAN", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
domain = modifyDomain(domain, Optional.of(filter));
assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValue(), Long.valueOf(40));
assertEquals(domain.getValues().getRanges().getSpan().getLow().getValueBlock(), Optional.empty());
}
use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.
the class TestHivePageSourceProvider method testModifyDomainGreaterThanOrEqual.
@Test
public void testModifyDomainGreaterThanOrEqual() {
Collection<Object> valueSet = new HashSet<>();
valueSet.add(Long.valueOf(40));
VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$greater_than_or_equal");
BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
CallExpression filter = new CallExpression("GREATER_THAN_OR_EQUAL", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
domain = modifyDomain(domain, Optional.of(filter));
assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValueBlock(), Optional.empty());
assertEquals(domain.getValues().getRanges().getSpan().getLow().getValue(), Long.valueOf(40));
}
use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.
the class SqlQueryExecution method findMappingFromPlan.
private void findMappingFromPlan(Map<String, Set<String>> mapping, PlanNode sourceNode) {
if (sourceNode != null && sourceNode instanceof ProjectNode) {
ProjectNode projectNode = (ProjectNode) sourceNode;
Map<Symbol, RowExpression> assignments = projectNode.getAssignments().getMap();
for (Symbol symbol : assignments.keySet()) {
if (mapping.containsKey(symbol.getName())) {
Set<String> sets = mapping.get(symbol.getName());
RowExpression expression = assignments.get(symbol);
if (expression instanceof VariableReferenceExpression) {
sets.add(((VariableReferenceExpression) expression).getName());
} else {
sets.add(expression.toString());
}
} else {
for (Map.Entry<String, Set<String>> entry : mapping.entrySet()) {
if (entry.getValue().contains(symbol.getName())) {
RowExpression expression = assignments.get(symbol);
if (expression instanceof VariableReferenceExpression) {
entry.getValue().add(((VariableReferenceExpression) expression).getName());
} else {
entry.getValue().add(expression.toString());
}
}
}
}
}
}
for (PlanNode planNode : sourceNode.getSources()) {
findMappingFromPlan(mapping, planNode);
}
}
use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.
the class TestDynamicFilters method testExtractStaticFilters.
@Test
public void testExtractStaticFilters() {
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
ConstantExpression staticExpression = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
VariableReferenceExpression variableExpression = new VariableReferenceExpression("col", VarcharType.VARCHAR);
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
RowExpression dynamicFilterExpression = call(DynamicFilters.Function.NAME, functionHandle, staticExpression.getType(), asList(staticExpression, variableExpression), Optional.empty());
RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, dynamicFilterExpression);
Optional<RowExpression> extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression.get(), staticExpression);
RowExpression combinedStaticExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression);
combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression, dynamicFilterExpression);
extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression.get(), combinedStaticExpression);
}
use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.
the class TestDynamicFilters method testExtractDynamicFilterExpression.
@Test
public void testExtractDynamicFilterExpression() {
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("col", VarcharType.VARCHAR);
ConstantExpression staticExpression2 = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
VariableReferenceExpression variableExpression2 = new VariableReferenceExpression("col", 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());
RowExpression combineDynamicFilterExpression = logicalRowExpressions.combineDisjuncts(asList(dynamicFilterExpression1, dynamicFilterExpression2));
RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression1, combineDynamicFilterExpression);
RowExpression extractedExpression = DynamicFilters.extractDynamicFilterExpression(combinedExpression, metadata);
assertEquals(extractedExpression, combineDynamicFilterExpression);
}
Aggregations