use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class RowComparator method compare.
@Override
public int compare(Page leftRow, Page rightRow) {
for (int index = 0; index < sortChannels.size(); index++) {
Type type = sortTypes.get(index);
int channel = sortChannels.get(index);
SortOrder sortOrder = sortOrders.get(index);
Block left = leftRow.getBlock(channel);
Block right = rightRow.getBlock(channel);
int comparison;
try {
comparison = sortOrder.compareBlockValue(type, left, 0, right, 0);
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
if (comparison != 0) {
return comparison;
}
}
return 0;
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class SimplePagesIndexComparator method compareTo.
@Override
public int compareTo(PagesIndex pagesIndex, int leftPosition, int rightPosition) {
AdaptiveLongBigArray valueAddresses = pagesIndex.getValueAddresses();
long leftPageAddress = valueAddresses.get(leftPosition);
long rightPageAddress = valueAddresses.get(rightPosition);
int leftBlockIndex = decodeSliceIndex(leftPageAddress);
int leftBlockPosition = decodePosition(leftPageAddress);
int rightBlockIndex = decodeSliceIndex(rightPageAddress);
int rightBlockPosition = decodePosition(rightPageAddress);
for (int i = 0; i < sortChannels.length; i++) {
int sortChannel = sortChannels[i];
SortOrder sortOrder = sortOrders[i];
Type sortType = sortTypes[i];
List<Block> indexChannel = pagesIndex.getChannel(sortChannel);
Block leftBlock = indexChannel.get(leftBlockIndex);
Block rightBlock = indexChannel.get(rightBlockIndex);
try {
int compare = sortOrder.compareBlockValue(sortType, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
if (compare != 0) {
return compare;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
return 0;
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class PushAggregationThroughOuterJoin method inlineOrderByVariables.
private static OrderingScheme inlineOrderByVariables(Map<VariableReferenceExpression, VariableReferenceExpression> variableMapping, OrderingScheme orderingScheme) {
// This is a logic expanded from ExpressionTreeRewriter::rewriteSortItems
ImmutableList.Builder<VariableReferenceExpression> orderBy = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, SortOrder> ordering = new ImmutableMap.Builder<>();
for (VariableReferenceExpression variable : orderingScheme.getOrderByVariables()) {
VariableReferenceExpression translated = variableMapping.get(variable);
orderBy.add(translated);
ordering.put(translated, orderingScheme.getOrdering(variable));
}
ImmutableMap<VariableReferenceExpression, SortOrder> orderingMap = ordering.build();
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 TestWindowOperator method testRowNumberPartition.
@Test(dataProvider = "spillEnabled")
public void testRowNumberPartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
List<Page> input = rowPagesBuilder(VARCHAR, BIGINT, DOUBLE, BOOLEAN).row("b", -1L, -0.1, true).row("a", 2L, 0.3, false).row("a", 4L, 0.2, true).pageBreak().row("b", 5L, 0.4, false).row("a", 6L, 0.1, true).build();
WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN), Ints.asList(0, 1, 2, 3), ROW_NUMBER, Ints.asList(0), Ints.asList(1), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), spillEnabled);
DriverContext driverContext = createDriverContext(memoryLimit);
MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, BIGINT, DOUBLE, BOOLEAN, BIGINT).row("a", 2L, 0.3, false, 1L).row("a", 4L, 0.2, true, 2L).row("a", 6L, 0.1, true, 3L).row("b", -1L, -0.1, true, 1L).row("b", 5L, 0.4, false, 2L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
use of com.facebook.presto.common.block.SortOrder in project presto by prestodb.
the class TestWindowOperator method testRowNumber.
@Test(dataProvider = "spillEnabled")
public void testRowNumber(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(2L, 0.3).row(4L, 0.2).row(6L, 0.1).pageBreak().row(-1L, -0.1).row(5L, 0.4).build();
WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1, 0), ROW_NUMBER, Ints.asList(), Ints.asList(0), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), spillEnabled);
DriverContext driverContext = createDriverContext(memoryLimit);
MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT, BIGINT).row(-0.1, -1L, 1L).row(0.3, 2L, 2L).row(0.2, 4L, 3L).row(0.4, 5L, 4L).row(0.1, 6L, 5L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Aggregations