@Override public int compareTo(Page left, int leftPosition, Page right, int rightPosition) { for (int i = 0; i < sortChannels.size(); i++) { int sortChannel = sortChannels.get(i); Block leftBlock = left.getBlock(sortChannel); Block rightBlock = right.getBlock(sortChannel); SortOrder sortOrder = sortOrders.get(i); int compare = sortOrder.compareBlockValue(types.get(sortChannel), leftBlock, leftPosition, rightBlock, rightPosition); if (compare != 0) { return compare; } } return 0; } }
int sortOrderComparison = o1OrderingScheme.getOrdering(symbol1).compareTo(o2OrderingScheme.getOrdering(symbol2)); if (sortOrderComparison != 0) { return sortOrderComparison;
.invoke("getBlock", Block.class, constantInt(sortChannel)); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
static boolean orderingSchemeMatches(List<Ordering> expectedOrderBy, OrderingScheme orderingScheme, SymbolAliases symbolAliases) { if (expectedOrderBy.size() != orderingScheme.getOrderBy().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(orderingScheme.getOrderBy().get(i))) { return false; } if (!ordering.getSortOrder().equals(orderingScheme.getOrdering(symbol))) { return false; } } return true; } }
.invoke("getBlock", Block.class, constantInt(sortChannel)); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
static boolean orderingSchemeMatches(List<Ordering> expectedOrderBy, OrderingScheme orderingScheme, SymbolAliases symbolAliases) { if (expectedOrderBy.size() != orderingScheme.getOrderBy().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(orderingScheme.getOrderBy().get(i))) { return false; } if (!ordering.getSortOrder().equals(orderingScheme.getOrdering(symbol))) { return false; } } return true; } }
@Override public int compareTo(Page left, int leftPosition, Page right, int rightPosition) { for (int i = 0; i < sortChannels.size(); i++) { int sortChannel = sortChannels.get(i); Block leftBlock = left.getBlock(sortChannel); Block rightBlock = right.getBlock(sortChannel); SortOrder sortOrder = sortOrders.get(i); int compare = sortOrder.compareBlockValue(types.get(sortChannel), leftBlock, leftPosition, rightBlock, rightPosition); if (compare != 0) { return compare; } } return 0; } }
.cast(Block.class); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
int sortOrderComparison = o1OrderingScheme.getOrdering(symbol1).compareTo(o2OrderingScheme.getOrdering(symbol2)); if (sortOrderComparison != 0) { return sortOrderComparison;
@Override public int compareTo(PagePosition other) { for (int i = 0; i < sortFields.size(); i++) { int channel = sortFields.get(i); SortOrder order = sortOrders.get(i); Type type = types.get(channel); Block block = page.getBlock(channel); Block otherBlock = other.page.getBlock(channel); int result = order.compareBlockValue(type, block, position, otherBlock, other.position); if (result != 0) { return result; } } return 0; } }
.cast(Block.class); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
@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 = sortOrder.compareBlockValue(type, left, 0, right, 0); if (comparison != 0) { return comparison; } } return 0; } }
@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 = sortOrder.compareBlockValue(type, left, 0, right, 0); if (comparison != 0) { return comparison; } } return 0; } }
@Override public int compareTo(SortedRowSource other) { if (!hasNext()) { return 1; } if (!other.hasNext()) { return -1; } for (int i = 0; i < sortIndexes.size(); i++) { int channel = sortIndexes.get(i); Type type = columnTypes.get(channel); Block leftBlock = currentPage.getBlock(channel); int leftBlockPosition = currentPosition; Block rightBlock = other.currentPage.getBlock(channel); int rightBlockPosition = other.currentPosition; int compare = sortOrders.get(i).compareBlockValue(type, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); if (compare != 0) { return compare; } } return 0; }
@Override public int compareTo(PagesIndex pagesIndex, int leftPosition, int rightPosition) { long leftPageAddress = pagesIndex.getValueAddresses().getLong(leftPosition); int leftBlockIndex = decodeSliceIndex(leftPageAddress); int leftBlockPosition = decodePosition(leftPageAddress); long rightPageAddress = pagesIndex.getValueAddresses().getLong(rightPosition); int rightBlockIndex = decodeSliceIndex(rightPageAddress); int rightBlockPosition = decodePosition(rightPageAddress); for (int i = 0; i < sortChannels.size(); i++) { int sortChannel = sortChannels.get(i); Block leftBlock = pagesIndex.getChannel(sortChannel).get(leftBlockIndex); Block rightBlock = pagesIndex.getChannel(sortChannel).get(rightBlockIndex); SortOrder sortOrder = sortOrders.get(i); int compare = sortOrder.compareBlockValue(sortTypes.get(i), leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); if (compare != 0) { return compare; } } return 0; } }
@Override public int compareTo(PagesIndex pagesIndex, int leftPosition, int rightPosition) { long leftPageAddress = pagesIndex.getValueAddresses().getLong(leftPosition); int leftBlockIndex = decodeSliceIndex(leftPageAddress); int leftBlockPosition = decodePosition(leftPageAddress); long rightPageAddress = pagesIndex.getValueAddresses().getLong(rightPosition); int rightBlockIndex = decodeSliceIndex(rightPageAddress); int rightBlockPosition = decodePosition(rightPageAddress); for (int i = 0; i < sortChannels.size(); i++) { int sortChannel = sortChannels.get(i); Block leftBlock = pagesIndex.getChannel(sortChannel).get(leftBlockIndex); Block rightBlock = pagesIndex.getChannel(sortChannel).get(rightBlockIndex); SortOrder sortOrder = sortOrders.get(i); int compare = sortOrder.compareBlockValue(sortTypes.get(i), leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); if (compare != 0) { return compare; } } return 0; } }
assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); if (type.isOrderable() && !(type instanceof UnknownType)) { Block nonNullValue = toBlock(getNonNullValue()); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, greaterValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, greaterValue, 0) < 0); assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, greaterValue, 0) > 0); assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, greaterValue, 0) > 0);
assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, expectedBlock, 0) == 0); if (type.isOrderable() && !(type instanceof UnknownType)) { Block nonNullValue = toBlock(getNonNullValue()); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, nonNullValue, 0) < 0); assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, nonNullValue, 0) > 0); assertTrue(ASC_NULLS_FIRST.compareBlockValue(type, block, position, greaterValue, 0) < 0); assertTrue(ASC_NULLS_LAST.compareBlockValue(type, block, position, greaterValue, 0) < 0); assertTrue(DESC_NULLS_FIRST.compareBlockValue(type, block, position, greaterValue, 0) > 0); assertTrue(DESC_NULLS_LAST.compareBlockValue(type, block, position, greaterValue, 0) > 0);
Block other = toBlock(getNonNullValue()); try { ASC_NULLS_FIRST.compareBlockValue(type, block, -1, other, 0); fail("expected RuntimeException"); ASC_NULLS_FIRST.compareBlockValue(type, block, block.getPositionCount(), other, 0); fail("expected RuntimeException");
Block other = toBlock(getNonNullValue()); try { ASC_NULLS_FIRST.compareBlockValue(type, block, -1, other, 0); fail("expected RuntimeException"); ASC_NULLS_FIRST.compareBlockValue(type, block, block.getPositionCount(), other, 0); fail("expected RuntimeException");