Search in sources :

Example 16 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression 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 17 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class TestSplitFiltering method testGetFilteredSplit.

/**
 * This test will not actually filter any splits since the indexes will not be found,
 * instead it's just testing the flow. The actual filtering is tested in other classes.
 */
@Test
public void testGetFilteredSplit() {
    PropertyService.setProperty(HetuConstant.FILTER_ENABLED, true);
    PropertyService.setProperty(HetuConstant.INDEXSTORE_URI, "/tmp/hetu/indices");
    PropertyService.setProperty(HetuConstant.INDEXSTORE_FILESYSTEM_PROFILE, "local-config-default");
    PropertyService.setProperty(HetuConstant.FILTER_CACHE_TTL, new Duration(10, TimeUnit.MINUTES));
    PropertyService.setProperty(HetuConstant.FILTER_CACHE_LOADING_DELAY, new Duration(5000, TimeUnit.MILLISECONDS));
    PropertyService.setProperty(HetuConstant.FILTER_CACHE_LOADING_THREADS, 2L);
    RowExpression expression = PlanBuilder.comparison(OperatorType.EQUAL, new VariableReferenceExpression("a", VarcharType.VARCHAR), new ConstantExpression(utf8Slice("test_value"), VarcharType.VARCHAR));
    SqlStageExecution stage = TestUtil.getTestStage(expression);
    List<Split> mockSplits = new ArrayList<>();
    MockSplit mock = new MockSplit("hdfs://hacluster/AppData/BIProd/DWD/EVT/bogus_table/000000_0", 0, 10, 0);
    MockSplit mock1 = new MockSplit("hdfs://hacluster/AppData/BIProd/DWD/EVT/bogus_table/000000_1", 0, 10, 0);
    MockSplit mock2 = new MockSplit("hdfs://hacluster/AppData/BIProd/DWD/EVT/bogus_table/000001_0", 0, 10, 0);
    MockSplit mock3 = new MockSplit("hdfs://hacluster/AppData/BIProd/DWD/EVT/bogus_table/000000_4", 0, 10, 0);
    mockSplits.add(new Split(new CatalogName("bogus_catalog"), mock, Lifespan.taskWide()));
    mockSplits.add(new Split(new CatalogName("bogus_catalog"), mock1, Lifespan.taskWide()));
    mockSplits.add(new Split(new CatalogName("bogus_catalog"), mock2, Lifespan.taskWide()));
    mockSplits.add(new Split(new CatalogName("bogus_catalog"), mock3, Lifespan.taskWide()));
    SplitSource.SplitBatch nextSplits = new SplitSource.SplitBatch(mockSplits, true);
    HeuristicIndexerManager indexerManager = new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager());
    Pair<Optional<RowExpression>, Map<Symbol, ColumnHandle>> pair = SplitFiltering.getExpression(stage);
    List<Split> filteredSplits = SplitFiltering.getFilteredSplit(pair.getFirst(), SplitFiltering.getFullyQualifiedName(stage), pair.getSecond(), nextSplits, indexerManager);
    assertNotNull(filteredSplits);
    assertEquals(filteredSplits.size(), 4);
}
Also used : Optional(java.util.Optional) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) Duration(io.airlift.units.Duration) MockSplit(io.prestosql.utils.MockSplit) SqlStageExecution(io.prestosql.execution.SqlStageExecution) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) CatalogName(io.prestosql.spi.connector.CatalogName) Split(io.prestosql.metadata.Split) MockSplit(io.prestosql.utils.MockSplit) SplitSource(io.prestosql.split.SplitSource) HetuMetaStoreManager(io.prestosql.metastore.HetuMetaStoreManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 18 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression 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 19 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class HeuristicIndexFilter method matchAny.

// Apply the indices on the expression. Currently only ComparisonExpression is supported
private boolean matchAny(CallExpression callExp) {
    if (callExp.getArguments().size() != 2) {
        return true;
    }
    RowExpression varRef = callExp.getArguments().get(0);
    if (!(varRef instanceof VariableReferenceExpression)) {
        return true;
    }
    String columnName = ((VariableReferenceExpression) varRef).getName();
    List<IndexMetadata> selectedIndices = HeuristicIndexSelector.select(callExp, indices.get(columnName));
    if (selectedIndices == null || selectedIndices.isEmpty()) {
        return true;
    }
    for (IndexMetadata indexMetadata : selectedIndices) {
        if (indexMetadata == null || indexMetadata.getIndex() == null) {
            // Invalid index. Don't filter out
            return true;
        }
        try {
            if (indexMetadata.getIndex().matches(callExp)) {
                return true;
            }
        } catch (UnsupportedOperationException e) {
            // Unable to apply the index. Don't filter out
            return true;
        }
    }
    // None of the index matches the expression
    return false;
}
Also used : VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata)

Example 20 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression 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)

Aggregations

VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)59 RowExpression (io.prestosql.spi.relation.RowExpression)35 Symbol (io.prestosql.spi.plan.Symbol)32 CallExpression (io.prestosql.spi.relation.CallExpression)22 Test (org.testng.annotations.Test)22 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)21 Map (java.util.Map)16 List (java.util.List)14 PlanNode (io.prestosql.spi.plan.PlanNode)13 ImmutableList (com.google.common.collect.ImmutableList)12 SpecialForm (io.prestosql.spi.relation.SpecialForm)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)10 Assignments (io.prestosql.spi.plan.Assignments)10 ProjectNode (io.prestosql.spi.plan.ProjectNode)10 SymbolReference (io.prestosql.sql.tree.SymbolReference)10 FunctionHandle (io.prestosql.spi.function.FunctionHandle)9 DynamicFilters (io.prestosql.sql.DynamicFilters)9 Optional (java.util.Optional)9