@Override public int compare( Object baseObj1, long baseOff1, int baseLen1, Object baseObj2, long baseOff2, int baseLen2) { // Note that since ordering doesn't need the total length of the record, we just pass 0 // into the row. row1.pointTo(baseObj1, baseOff1 + 4, 0); row2.pointTo(baseObj2, baseOff2 + 4, 0); return ordering.compare(row1, row2); } }
@Override public int compare( Object baseObj1, long baseOff1, int baseLen1, Object baseObj2, long baseOff2, int baseLen2) { // Note that since ordering doesn't need the total length of the record, we just pass -1 // into the row. row1.pointTo(baseObj1, baseOff1 + 4, -1); row2.pointTo(baseObj2, baseOff2 + 4, -1); return ordering.compare(row1, row2); } }
@Override public int compare( Object baseObj1, long baseOff1, int baseLen1, Object baseObj2, long baseOff2, int baseLen2) { // Note that since ordering doesn't need the total length of the record, we just pass 0 // into the row. row1.pointTo(baseObj1, baseOff1 + 4, 0); row2.pointTo(baseObj2, baseOff2 + 4, 0); return ordering.compare(row1, row2); } }
@Override public boolean next() { if (mapLocationIterator.hasNext()) { final BytesToBytesMap.Location loc = mapLocationIterator.next(); key.pointTo( loc.getKeyBase(), loc.getKeyOffset(), loc.getKeyLength() ); value.pointTo( loc.getValueBase(), loc.getValueOffset(), loc.getValueLength() ); return true; } else { return false; } }
@Override public boolean next() { if (mapLocationIterator.hasNext()) { final BytesToBytesMap.Location loc = mapLocationIterator.next(); key.pointTo( loc.getKeyBase(), loc.getKeyOffset(), loc.getKeyLength() ); value.pointTo( loc.getValueBase(), loc.getValueOffset(), loc.getValueLength() ); return true; } else { return false; } }
@Override public boolean next() { if (mapLocationIterator.hasNext()) { final BytesToBytesMap.Location loc = mapLocationIterator.next(); key.pointTo( loc.getKeyBase(), loc.getKeyOffset(), loc.getKeyLength() ); value.pointTo( loc.getValueBase(), loc.getValueOffset(), loc.getValueLength() ); return true; } else { return false; } }
@Test public void testBinaryComparatorWhenSubtractionIsDivisibleByMaxIntValue() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setLong(0, 11); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setLong(0, 11L + Integer.MAX_VALUE); insertRow(row1); insertRow(row2); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorWhenSubtractionCanOverflowLongValue() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setLong(0, Long.MIN_VALUE); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setLong(0, 1); insertRow(row1); insertRow(row2); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorWhenSubtractionIsDivisibleByMaxIntValue() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setLong(0, 11); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setLong(0, 11L + Integer.MAX_VALUE); insertRow(row1); insertRow(row2); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorWhenSubtractionIsDivisibleByMaxIntValue() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setLong(0, 11); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setLong(0, 11L + Integer.MAX_VALUE); insertRow(row1); insertRow(row2); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorWhenSubtractionCanOverflowLongValue() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setLong(0, Long.MIN_VALUE); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setLong(0, 1); insertRow(row1); insertRow(row2); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorWhenSubtractionCanOverflowLongValue() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setLong(0, Long.MIN_VALUE); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setLong(0, 1); insertRow(row1); insertRow(row2); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForSingleColumnRow() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setInt(0, 11); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setInt(0, 42); insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForSingleColumnRow() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setInt(0, 11); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setInt(0, 42); insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForSingleColumnRow() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); row1.setInt(0, 11); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); row2.setInt(0, 42); insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForMultipleColumnRow() throws Exception { int numFields = 5; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row1.setDouble(i, i * 3.14); } UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row2.setDouble(i, 198.7 / (i + 1)); } insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForMultipleColumnRow() throws Exception { int numFields = 5; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row1.setDouble(i, i * 3.14); } UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row2.setDouble(i, 198.7 / (i + 1)); } insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForMultipleColumnRow() throws Exception { int numFields = 5; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row1.setDouble(i, i * 3.14); } UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row2.setDouble(i, 198.7 / (i + 1)); } insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) < 0); }
@Test public void testBinaryComparatorForNullColumns() throws Exception { int numFields = 3; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; row1.pointTo(data1, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields; i++) { row1.setNullAt(i); } UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; row2.pointTo(data2, computeSizeInBytes(numFields * 8)); for (int i = 0; i < numFields - 1; i++) { row2.setNullAt(i); } row2.setDouble(numFields - 1, 3.14); insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) > 0); }
@Test public void testBinaryComparatorForArrayColumn() throws Exception { int numFields = 1; UnsafeRow row1 = new UnsafeRow(numFields); byte[] data1 = new byte[100]; UnsafeArrayData arrayData1 = UnsafeArrayData.fromPrimitiveArray(new int[]{11, 42, -1}); row1.pointTo(data1, computeSizeInBytes(numFields * 8 + arrayData1.getSizeInBytes())); row1.setLong(0, (relativeOffset(numFields) << 32) | (long) arrayData1.getSizeInBytes()); Platform.copyMemory(arrayData1.getBaseObject(), arrayData1.getBaseOffset(), data1, row1.getBaseOffset() + relativeOffset(numFields), arrayData1.getSizeInBytes()); UnsafeRow row2 = new UnsafeRow(numFields); byte[] data2 = new byte[100]; UnsafeArrayData arrayData2 = UnsafeArrayData.fromPrimitiveArray(new int[]{22}); row2.pointTo(data2, computeSizeInBytes(numFields * 8 + arrayData2.getSizeInBytes())); row2.setLong(0, (relativeOffset(numFields) << 32) | (long) arrayData2.getSizeInBytes()); Platform.copyMemory(arrayData2.getBaseObject(), arrayData2.getBaseOffset(), data2, row2.getBaseOffset() + relativeOffset(numFields), arrayData2.getSizeInBytes()); insertRow(row1); insertRow(row2); assert(compare(0, 0) == 0); assert(compare(0, 1) > 0); }