Search in sources :

Example 6 with SpecialForm

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;
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) Variable(io.airlift.bytecode.Variable) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpressionCompiler.createTempVariableReferenceExpression(io.prestosql.sql.gen.RowExpressionCompiler.createTempVariableReferenceExpression) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) RowExpression(io.prestosql.spi.relation.RowExpression) SpecialForm(io.prestosql.spi.relation.SpecialForm)

Example 7 with SpecialForm

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"));
}
Also used : VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) SpecialForm(io.prestosql.spi.relation.SpecialForm) Test(org.testng.annotations.Test)

Example 8 with SpecialForm

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));
}
Also used : VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) SpecialForm(io.prestosql.spi.relation.SpecialForm) Test(org.testng.annotations.Test)

Example 9 with SpecialForm

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));
}
Also used : VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) SpecialForm(io.prestosql.spi.relation.SpecialForm) Test(org.testng.annotations.Test)

Example 10 with SpecialForm

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);
}
Also used : ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) SpecialForm(io.prestosql.spi.relation.SpecialForm)

Aggregations

SpecialForm (io.prestosql.spi.relation.SpecialForm)27 RowExpression (io.prestosql.spi.relation.RowExpression)20 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)14 CallExpression (io.prestosql.spi.relation.CallExpression)12 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)12 ArrayList (java.util.ArrayList)8 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)6 InputReferenceExpression (io.prestosql.spi.relation.InputReferenceExpression)6 Test (org.testng.annotations.Test)6 Signature (io.prestosql.spi.function.Signature)5 LambdaDefinitionExpression (io.prestosql.spi.relation.LambdaDefinitionExpression)5 OperatorType (io.prestosql.spi.function.OperatorType)4 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)3 Scope (io.airlift.bytecode.Scope)3 Variable (io.airlift.bytecode.Variable)3 FunctionHandle (io.prestosql.spi.function.FunctionHandle)3 IndexMetadata (io.prestosql.spi.heuristicindex.IndexMetadata)3 Type (io.prestosql.spi.type.Type)3 IfStatement (io.airlift.bytecode.control.IfStatement)2 LabelNode (io.airlift.bytecode.instruction.LabelNode)2