use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class TestWindowOperator method testLastValuePartition.
@Test(dataProvider = "spillEnabled")
public void testLastValuePartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("b", "A1", 1L, true, "").row("a", "A2", 1L, false, "").row("a", "B1", 2L, true, "").pageBreak().row("b", "C1", 2L, false, "").row("a", "C2", 3L, true, "").row("c", "A3", 1L, true, "").build();
DriverContext driverContext = createDriverContext(memoryLimit);
WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 3), LAST_VALUE, Ints.asList(0), Ints.asList(2), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), spillEnabled);
MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("a", "A2", 1L, false, "C2").row("a", "B1", 2L, true, "C2").row("a", "C2", 3L, true, "C2").row("b", "A1", 1L, true, "C1").row("b", "C1", 2L, false, "C1").row("c", "A3", 1L, true, "A3").build();
assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class TestWindowOperator method testFirstValuePartition.
@Test(dataProvider = "spillEnabled")
public void testFirstValuePartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("b", "A1", 1L, true, "").row("a", "A2", 1L, false, "").row("a", "B1", 2L, true, "").pageBreak().row("b", "C1", 2L, false, "").row("a", "C2", 3L, true, "").row("c", "A3", 1L, true, "").build();
WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 3), FIRST_VALUE, Ints.asList(0), Ints.asList(2), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), spillEnabled);
DriverContext driverContext = createDriverContext(memoryLimit);
MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("a", "A2", 1L, false, "A2").row("a", "B1", 2L, true, "A2").row("a", "C2", 3L, true, "A2").row("b", "A1", 1L, true, "A1").row("b", "C1", 2L, false, "A1").row("c", "A3", 1L, true, "A3").build();
assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class SymbolMapper method map.
public TopNNode map(TopNNode node, PlanNode source, PlanNodeId newNodeId) {
ImmutableList.Builder<VariableReferenceExpression> variables = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, SortOrder> orderings = ImmutableMap.builder();
Set<VariableReferenceExpression> seenCanonicals = new HashSet<>(node.getOrderingScheme().getOrderByVariables().size());
for (VariableReferenceExpression variable : node.getOrderingScheme().getOrderByVariables()) {
VariableReferenceExpression canonical = map(variable);
if (seenCanonicals.add(canonical)) {
seenCanonicals.add(canonical);
variables.add(canonical);
orderings.put(canonical, node.getOrderingScheme().getOrdering(variable));
}
}
ImmutableMap<VariableReferenceExpression, SortOrder> orderingMap = orderings.build();
return new TopNNode(node.getSourceLocation(), newNodeId, source, node.getCount(), new OrderingScheme(variables.build().stream().map(variable -> new Ordering(variable, orderingMap.get(variable))).collect(toImmutableList())), node.getStep());
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class SymbolMapper method map.
public OrderingScheme map(OrderingScheme orderingScheme) {
// SymbolMapper inlines symbol with multiple level reference (SymbolInliner only inline single level).
ImmutableList.Builder<VariableReferenceExpression> orderBy = ImmutableList.builder();
HashMap<VariableReferenceExpression, SortOrder> orderingMap = new HashMap<>();
for (VariableReferenceExpression variable : orderingScheme.getOrderByVariables()) {
VariableReferenceExpression translated = map(variable);
// Some variables may become duplicates after canonicalization, so we put them only once.
if (!orderingMap.containsKey(translated)) {
orderBy.add(translated);
orderingMap.put(translated, orderingScheme.getOrdering(variable));
} else if (orderingMap.get(translated) != orderingScheme.getOrdering(variable)) {
warningCollector.add(new PrestoWarning(MULTIPLE_ORDER_BY, "Multiple ORDER BY for a variable were given, only first provided will be considered"));
}
}
return new OrderingScheme(orderBy.build().stream().map(variable -> new Ordering(variable, orderingMap.get(variable))).collect(toImmutableList()));
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class Util method orderingSchemeMatches.
static boolean orderingSchemeMatches(List<Ordering> expectedOrderBy, OrderingScheme orderingScheme, SymbolAliases symbolAliases) {
if (expectedOrderBy.size() != orderingScheme.getOrderByVariables().size()) {
return false;
}
for (int i = 0; i < expectedOrderBy.size(); ++i) {
Ordering ordering = expectedOrderBy.get(i);
Symbol symbol = Symbol.from(symbolAliases.get(ordering.getField()));
if (!symbol.equals(new Symbol(orderingScheme.getOrderByVariables().get(i).getName()))) {
return false;
}
SortOrder sortOrder = getOnlyElement(Maps.filterKeys(orderingScheme.getOrderingsMap(), variable -> variable.getName().equals(symbol.getName())).values().iterator());
if (!ordering.getSortOrder().equals(sortOrder)) {
return false;
}
}
return true;
}
Aggregations