use of io.prestosql.spi.relation.SpecialForm in project hetu-core by openlookeng.
the class BetweenCodeGenerator method generateExpression.
@Override
public BytecodeNode generateExpression(FunctionHandle functionHandle, BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments) {
checkArgument(functionHandle == null, "functionHandle is null here");
RowExpression value = arguments.get(0);
RowExpression min = arguments.get(1);
RowExpression max = arguments.get(2);
Variable firstValue = generatorContext.getScope().createTempVariable(value.getType().getJavaType());
VariableReferenceExpression valueReference = createTempVariableReferenceExpression(firstValue, value.getType());
SpecialForm newExpression = new SpecialForm(BETWEEN_AND, BOOLEAN, call(GREATER_THAN_OR_EQUAL.getFunctionName().getObjectName(), generatorContext.getFunctionManager().resolveOperatorFunctionHandle(GREATER_THAN_OR_EQUAL, TypeSignatureProvider.fromTypes(value.getType(), min.getType())), BOOLEAN, valueReference, min), call(LESS_THAN_OR_EQUAL.getFunctionName().getObjectName(), generatorContext.getFunctionManager().resolveOperatorFunctionHandle(LESS_THAN_OR_EQUAL, TypeSignatureProvider.fromTypes(value.getType(), min.getType())), BOOLEAN, valueReference, max));
LabelNode done = new LabelNode("done");
// push value arg on the stack
BytecodeBlock block = new BytecodeBlock().comment("check if value is null").append(generatorContext.generate(value)).append(ifWasNullPopAndGoto(generatorContext.getScope(), done, boolean.class, value.getType().getJavaType())).putVariable(firstValue).append(generatorContext.generate(newExpression)).visitLabel(done);
return block;
}
use of io.prestosql.spi.relation.SpecialForm in project hetu-core by openlookeng.
the class TestSplitFiltering method testGetColumns.
@Test
public void testGetColumns() {
RowExpression rowExpression1 = PlanBuilder.comparison(OperatorType.EQUAL, new VariableReferenceExpression("col_a", BIGINT), new ConstantExpression(8L, BIGINT));
RowExpression rowExpression2 = new SpecialForm(SpecialForm.Form.IN, BOOLEAN, new VariableReferenceExpression("col_b", BIGINT), new ConstantExpression(20L, BIGINT), new ConstantExpression(80L, BIGINT));
RowExpression expression1 = new SpecialForm(SpecialForm.Form.AND, BOOLEAN, rowExpression1, rowExpression2);
RowExpression rowExpression3 = PlanBuilder.comparison(OperatorType.EQUAL, new VariableReferenceExpression("c1", VarcharType.VARCHAR), new ConstantExpression("d", VarcharType.VARCHAR));
RowExpression rowExpression4 = PlanBuilder.comparison(OperatorType.EQUAL, new VariableReferenceExpression("c2", VarcharType.VARCHAR), new ConstantExpression("e", VarcharType.VARCHAR));
RowExpression rowExpression5 = new SpecialForm(SpecialForm.Form.IN, BOOLEAN, new VariableReferenceExpression("c2", VarcharType.VARCHAR), new ConstantExpression("a", VarcharType.VARCHAR), new ConstantExpression("f", VarcharType.VARCHAR));
RowExpression expression6 = new SpecialForm(SpecialForm.Form.OR, BOOLEAN, rowExpression4, rowExpression5);
RowExpression expression2 = new SpecialForm(SpecialForm.Form.AND, BOOLEAN, rowExpression3, expression6);
parseExpressionGetColumns(expression1, ImmutableSet.of("col_a", "col_b"));
parseExpressionGetColumns(expression2, ImmutableSet.of("c1", "c2"));
}
use of io.prestosql.spi.relation.SpecialForm in project hetu-core by openlookeng.
the class TestHeuristicIndexFilter method testFilterWithMinMaxIndices.
@Test
public void testFilterWithMinMaxIndices() {
RowExpression expression1 = LogicalRowExpressions.and(simplePredicate(OperatorType.EQUAL, "testColumn", BIGINT, 8L), new SpecialForm(SpecialForm.Form.IN, BOOLEAN, new VariableReferenceExpression("testColumn", VARCHAR), new ConstantExpression(20L, BIGINT), new ConstantExpression(80L, BIGINT)));
RowExpression expression2 = LogicalRowExpressions.and(simplePredicate(OperatorType.EQUAL, "testColumn", BIGINT, 5L), simplePredicate(OperatorType.EQUAL, "testColumn", BIGINT, 20L));
RowExpression expression3 = LogicalRowExpressions.and(simplePredicate(OperatorType.GREATER_THAN_OR_EQUAL, "testColumn", BIGINT, 2L), simplePredicate(OperatorType.LESS_THAN_OR_EQUAL, "testColumn", BIGINT, 10L));
RowExpression expression4 = LogicalRowExpressions.and(simplePredicate(OperatorType.GREATER_THAN, "testColumn", BIGINT, 8L), simplePredicate(OperatorType.LESS_THAN, "testColumn", BIGINT, 20L));
RowExpression expression5 = LogicalRowExpressions.or(simplePredicate(OperatorType.GREATER_THAN, "testColumn", BIGINT, 200L), simplePredicate(OperatorType.LESS_THAN, "testColumn", BIGINT, 0L));
RowExpression expression6 = LogicalRowExpressions.or(simplePredicate(OperatorType.LESS_THAN, "testColumn", BIGINT, 0L), new SpecialForm(SpecialForm.Form.BETWEEN, BOOLEAN, new VariableReferenceExpression("testColumn", VARCHAR), new ConstantExpression(5L, BIGINT), new ConstantExpression(15L, BIGINT)));
HeuristicIndexFilter filter = new HeuristicIndexFilter(ImmutableMap.of("testColumn", ImmutableList.of(new IndexMetadata(minMaxIndex1, "testTable", new String[] { "testColumn" }, null, null, 0, 0), new IndexMetadata(minMaxIndex2, "testTable", new String[] { "testColumn" }, null, null, 10, 0))));
assertTrue(filter.matches(expression1));
assertFalse(filter.matches(expression2));
assertTrue(filter.matches(expression3));
assertTrue(filter.matches(expression4));
assertFalse(filter.matches(expression5));
assertTrue(filter.matches(expression6));
}
use of io.prestosql.spi.relation.SpecialForm in project hetu-core by openlookeng.
the class TestHeuristicIndexFilter method testFilterWithBloomIndices.
@Test
public void testFilterWithBloomIndices() {
RowExpression expression1 = LogicalRowExpressions.and(simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "a"), simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "b"));
RowExpression expression2 = LogicalRowExpressions.and(simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "a"), simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "e"));
RowExpression expression3 = LogicalRowExpressions.or(simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "e"), simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "c"));
RowExpression expression4 = LogicalRowExpressions.or(simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "e"), simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "f"));
RowExpression expression5 = LogicalRowExpressions.and(simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "d"), LogicalRowExpressions.or(simplePredicate(OperatorType.EQUAL, "testColumn", VARCHAR, "e"), new SpecialForm(SpecialForm.Form.IN, BOOLEAN, new VariableReferenceExpression("testColumn", VARCHAR), new ConstantExpression("a", VARCHAR), new ConstantExpression("f", VARCHAR))));
HeuristicIndexFilter filter = new HeuristicIndexFilter(ImmutableMap.of("testColumn", ImmutableList.of(new IndexMetadata(bloomIndex1, "testTable", new String[] { "testColumn" }, null, null, 0, 0), new IndexMetadata(bloomIndex2, "testTable", new String[] { "testColumn" }, null, null, 10, 0))));
assertTrue(filter.matches(expression1));
assertFalse(filter.matches(expression2));
assertTrue(filter.matches(expression3));
assertFalse(filter.matches(expression4));
assertTrue(filter.matches(expression5));
}
use of io.prestosql.spi.relation.SpecialForm in project hetu-core by openlookeng.
the class LogicalRowExpressions method extractPredicates.
public static List<RowExpression> extractPredicates(SpecialForm.Form form, RowExpression expression) {
if (expression instanceof SpecialForm && ((SpecialForm) expression).getForm() == form) {
SpecialForm specialFormExpression = (SpecialForm) expression;
if (specialFormExpression.getArguments().size() != 2) {
throw new IllegalStateException("logical binary expression requires exactly 2 operands");
}
List<RowExpression> predicates = new ArrayList<>();
predicates.addAll(extractPredicates(form, specialFormExpression.getArguments().get(0)));
predicates.addAll(extractPredicates(form, specialFormExpression.getArguments().get(1)));
return unmodifiableList(predicates);
}
return singletonList(expression);
}
Aggregations