use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testLeftJoin.
@Test
public void testLeftJoin() {
ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
criteriaBuilder.add(new JoinNode.EquiJoinClause(AV, DV));
criteriaBuilder.add(new JoinNode.EquiJoinClause(BV, EV));
List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
Map<VariableReferenceExpression, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<VariableReferenceExpression, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(DV, EV, FV)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, and(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(GV, bigintLiteral(10))));
FilterNode right = filter(rightScan, and(equals(DV, EV), lessThan(FV, bigintLiteral(100))));
PlanNode node = new JoinNode(Optional.empty(), newId(), JoinNode.Type.LEFT, left, right, criteria, ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// All right side symbols having output symbols should be checked against NULL
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), or(equals(DV, EV), and(isNull(DV), isNull(EV))), or(lessThan(FV, bigintLiteral(100)), isNull(FV)), or(equals(AV, DV), isNull(DV)), or(equals(BV, EV), isNull(EV))));
}
use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testInnerJoin.
@Test
public void testInnerJoin() {
ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
criteriaBuilder.add(new JoinNode.EquiJoinClause(AV, DV));
criteriaBuilder.add(new JoinNode.EquiJoinClause(BV, EV));
List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
Map<VariableReferenceExpression, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<VariableReferenceExpression, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(DV, EV, FV)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, and(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(GV, bigintLiteral(10))));
FilterNode right = filter(rightScan, and(equals(DV, EV), lessThan(FV, bigintLiteral(100))));
PlanNode node = new JoinNode(Optional.empty(), newId(), JoinNode.Type.INNER, left, right, criteria, ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.of(lessThanOrEqual(BV, EV)), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// All predicates having output symbol should be carried through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(DV, EV), lessThan(FV, bigintLiteral(100)), equals(AV, DV), equals(BV, EV), lessThanOrEqual(BV, EV)));
}
use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.
the class TestSchedulingOrderVisitor method testIndexJoinOrder.
@Test
public void testIndexJoinOrder() {
PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), METADATA);
TableScanNode a = planBuilder.tableScan(emptyList(), emptyMap());
TableScanNode b = planBuilder.tableScan(emptyList(), emptyMap());
List<PlanNodeId> order = scheduleOrder(planBuilder.indexJoin(IndexJoinNode.Type.INNER, a, b));
assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.
the class TestHiveLogicalPlanner method assertRequestedColumnsInLayout.
private void assertRequestedColumnsInLayout(Plan plan, String tableName, Set<String> expectedRequestedColumns) {
TableScanNode tableScan = searchFrom(plan.getRoot()).where(node -> isTableScanNode(node, tableName)).findOnlyElement();
assertTrue(tableScan.getTable().getLayout().isPresent());
HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) tableScan.getTable().getLayout().get();
assertTrue(layoutHandle.getRequestedColumns().isPresent());
Set<HiveColumnHandle> requestedColumns = layoutHandle.getRequestedColumns().get();
List<String> actualRequestedColumns = new ArrayList<>();
for (HiveColumnHandle column : requestedColumns) {
if (!column.getRequiredSubfields().isEmpty()) {
column.getRequiredSubfields().stream().map(Subfield::serialize).forEach(actualRequestedColumns::add);
} else {
actualRequestedColumns.add(column.getName());
}
}
Set<String> requestedColumnsSet = ImmutableSet.copyOf(actualRequestedColumns);
assertEquals(requestedColumnsSet.size(), actualRequestedColumns.size(), "There should be no duplicates in the requested column list");
assertEquals(requestedColumnsSet, expectedRequestedColumns);
}
use of com.facebook.presto.spi.plan.TableScanNode in project presto by prestodb.
the class TestHiveLogicalPlanner method assertBucketFilter.
private void assertBucketFilter(Plan plan, String tableName, int readBucketCount, Set<Integer> bucketsToKeep) {
TableScanNode tableScan = searchFrom(plan.getRoot()).where(node -> isTableScanNode(node, tableName)).findOnlyElement();
assertTrue(tableScan.getTable().getLayout().isPresent());
HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) tableScan.getTable().getLayout().get();
assertTrue(layoutHandle.getBucketHandle().isPresent());
assertTrue(layoutHandle.getBucketFilter().isPresent());
assertEquals(layoutHandle.getBucketHandle().get().getReadBucketCount(), readBucketCount);
assertEquals(layoutHandle.getBucketFilter().get().getBucketsToKeep(), bucketsToKeep);
}
Aggregations