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;
}
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);
}
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"));
}
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;
}
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));
}
Aggregations