@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; } }
@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; } }
@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(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);
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");
private int compare(int position, Block[] blocks, Block[] currentMax) { for (int i = 0; i < sortChannels.size(); i++) { Type type = sortTypes.get(i); int sortChannel = sortChannels.get(i); SortOrder sortOrder = sortOrders.get(i); Block block = blocks[sortChannel]; Block currentMaxValue = currentMax[sortChannel]; // compare the right value to the left block but negate the result since we are evaluating in the opposite order int compare = -sortOrder.compareBlockValue(type, currentMaxValue, 0, block, position); if (compare != 0) { return compare; } } return 0; }
private int compare(int position, Block[] blocks, Block[] currentMax) { for (int i = 0; i < sortChannels.size(); i++) { Type type = sortTypes.get(i); int sortChannel = sortChannels.get(i); SortOrder sortOrder = sortOrders.get(i); Block block = blocks[sortChannel]; Block currentMaxValue = currentMax[sortChannel]; int compare = sortOrder.compareBlockValue(type, block, position, currentMaxValue, 0); if (compare != 0) { return compare; } } return 0; }
@Override public int compare(Block[] leftRow, Block[] 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[channel]; Block right = rightRow[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; } }
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.getJavaType() != void.class) { 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");