use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class RowExpressionDomainTranslator method extractDisjuncts.
private List<RowExpression> extractDisjuncts(Type type, DiscreteValues discreteValues, RowExpression reference) {
List<RowExpression> values = discreteValues.getValues().stream().map(object -> toRowExpression(reference.getSourceLocation(), object, type)).collect(toList());
// If values is empty, then the equatableValues was either ALL or NONE, both of which should already have been checked for
checkState(!values.isEmpty());
RowExpression predicate;
if (values.size() == 1) {
predicate = equal(reference, getOnlyElement(values));
} else {
predicate = in(reference, values);
}
if (!discreteValues.isWhiteList()) {
predicate = not(functionResolution, predicate);
}
return ImmutableList.of(predicate);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class FunctionAssertions method executeFilterWithAll.
private List<Boolean> executeFilterWithAll(String filter, Session session, boolean executeWithNoInputColumns, ExpressionCompiler compiler) {
requireNonNull(filter, "filter is null");
Expression filterExpression = createExpression(session, filter, metadata, SYMBOL_TYPES);
RowExpression filterRowExpression = toRowExpression(session, filterExpression);
List<Boolean> results = new ArrayList<>();
// execute as standalone operator
OperatorFactory operatorFactory = compileFilterProject(session.getSqlFunctionProperties(), Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
results.add(executeFilter(operatorFactory, session));
if (executeWithNoInputColumns) {
// execute as standalone operator
operatorFactory = compileFilterWithNoInputColumns(session.getSqlFunctionProperties(), filterRowExpression, compiler);
results.add(executeFilterWithNoInputColumns(operatorFactory, session));
}
// interpret
Boolean interpretedValue = (Boolean) interpret(filterExpression, BOOLEAN, session);
if (interpretedValue == null) {
interpretedValue = false;
}
results.add(interpretedValue);
// execute over normal operator
SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(session.getSqlFunctionProperties(), Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
boolean scanOperatorValue = executeFilter(scanProjectOperatorFactory, createNormalSplit(), session);
results.add(scanOperatorValue);
// execute over record set
boolean recordValue = executeFilter(scanProjectOperatorFactory, createRecordSetSplit(), session);
results.add(recordValue);
// If the filter does not need bound values, execute query using full engine
if (!needsBoundValue(filterExpression)) {
MaterializedResult result = runner.execute("SELECT TRUE WHERE " + filter);
assertEquals(result.getTypes().size(), 1);
Boolean queryResult;
if (result.getMaterializedRows().isEmpty()) {
queryResult = false;
} else {
assertEquals(result.getMaterializedRows().size(), 1);
queryResult = (Boolean) Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
}
results.add(queryResult);
}
return results;
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestConnectorOptimization method testPushFilterToTableScan.
@Test
public void testPushFilterToTableScan() {
RowExpression expectedPredicate = and(newBigintVariable("a"), newBigintVariable("b"));
PlanNode plan = output(filter(tableScan("cat1", "a", "b"), expectedPredicate), "a");
PlanNode actual = optimize(plan, ImmutableMap.of(new ConnectorId("cat1"), ImmutableSet.of(filterPushdown())));
// assert structure; FilterNode is removed
assertPlanMatch(actual, PlanMatchPattern.output(SimpleTableScanMatcher.tableScan("cat1", expectedPredicate)));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestJoinNodeFlattener method testCombinesCriteriaAndFilters.
@Test
public void testCombinesCriteriaAndFilters() {
PlanBuilder p = planBuilder();
VariableReferenceExpression a1 = p.variable("A1");
VariableReferenceExpression b1 = p.variable("B1");
VariableReferenceExpression b2 = p.variable("B2");
VariableReferenceExpression c1 = p.variable("C1");
VariableReferenceExpression c2 = p.variable("C2");
ValuesNode valuesA = p.values(a1);
ValuesNode valuesB = p.values(b1, b2);
ValuesNode valuesC = p.values(c1, c2);
RowExpression bcFilter = and(call(OperatorType.GREATER_THAN.name(), functionResolution.comparisonFunction(OperatorType.GREATER_THAN, c2.getType(), BIGINT), BOOLEAN, ImmutableList.of(c2, constant(0L, BIGINT))), call(OperatorType.NOT_EQUAL.name(), functionResolution.comparisonFunction(OperatorType.NOT_EQUAL, c2.getType(), BIGINT), BOOLEAN, ImmutableList.of(c2, constant(7L, BIGINT))), call(OperatorType.GREATER_THAN.name(), functionResolution.comparisonFunction(OperatorType.GREATER_THAN, b2.getType(), c2.getType()), BOOLEAN, ImmutableList.of(b2, c2)));
RowExpression add = call(OperatorType.ADD.name(), functionResolution.arithmeticFunction(OperatorType.ADD, a1.getType(), c1.getType()), a1.getType(), ImmutableList.of(a1, c1));
RowExpression abcFilter = call(OperatorType.LESS_THAN.name(), functionResolution.comparisonFunction(OperatorType.LESS_THAN, add.getType(), b1.getType()), BOOLEAN, ImmutableList.of(add, b1));
JoinNode joinNode = p.join(INNER, valuesA, p.join(INNER, valuesB, valuesC, ImmutableList.of(equiJoinClause(b1, c1)), ImmutableList.of(b1, b2, c1, c2), Optional.of(bcFilter)), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1, b2, c1, c2), Optional.of(abcFilter));
MultiJoinNode expected = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(valuesA, valuesB, valuesC)), and(createEqualsExpression(b1, c1), createEqualsExpression(a1, b1), bcFilter, abcFilter), ImmutableList.of(a1, b1, b2, c1, c2));
assertEquals(toMultiJoinNode(joinNode, noLookup(), DEFAULT_JOIN_LIMIT, functionResolution, determinismEvaluator), expected);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestJdbcComputePushdown method testJdbcComputePushdownBooleanOperations.
@Test
public void testJdbcComputePushdownBooleanOperations() {
String table = "test_table";
String schema = "test_schema";
String expression = "(((c1 + c2) - c2 <> c2) OR c2 = c1) AND c1 <> c2";
TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("c1", BIGINT, "c2", BIGINT));
RowExpression rowExpression = sqlToRowExpressionTranslator.translateAndOptimize(expression(expression), typeProvider);
Set<ColumnHandle> columns = Stream.of("c1", "c2").map(TestJdbcComputePushdown::integerJdbcColumnHandle).collect(Collectors.toSet());
PlanNode original = filter(jdbcTableScan(schema, table, BIGINT, "c1", "c2"), rowExpression);
JdbcTableHandle jdbcTableHandle = new JdbcTableHandle(CONNECTOR_ID, new SchemaTableName(schema, table), CATALOG_NAME, schema, table);
ConnectorSession session = new TestingConnectorSession(ImmutableList.of());
JdbcTableLayoutHandle jdbcTableLayoutHandle = new JdbcTableLayoutHandle(session.getSqlFunctionProperties(), jdbcTableHandle, TupleDomain.none(), Optional.of(new JdbcExpression("((((((('c1' + 'c2') - 'c2') <> 'c2')) OR (('c2' = 'c1')))) AND (('c1' <> 'c2')))")));
PlanNode actual = this.jdbcComputePushdown.optimize(original, session, null, ID_ALLOCATOR);
assertPlanMatch(actual, PlanMatchPattern.filter(expression, JdbcTableScanMatcher.jdbcTableScanPattern(jdbcTableLayoutHandle, columns)));
}
Aggregations