strSerializer).useHeap(true) .keepSize(true).make()) { buffer.put("value1", "first"); buffer.put("value2", "first"); buffer.put("value3", "first"); buffer.put("value1", "second"); buffer.put("value3", "second"); buffer.put("value1", "third"); assertThat(buffer.size(), is(6L)); Iterator<String> iter = buffer.ascending(); assertThat(iter.next(), is("first")); assertThat(iter.next(), is("second")); assertThat(iter.hasNext(), is(false)); iter = buffer.descending(); assertThat(iter.next(), is("second")); assertThat(iter.next(), is("first")); assertThat(iter.hasNext(), is(false)); iter = buffer.getAll("value1"); assertThat(iter.next(), is("first")); assertThat(iter.next(), is("second"));
@SuppressWarnings( "unchecked" ) @Test public void shouldCreateSortBufferOnHeap() { TypeFactory<String> stringType = types.getStringFactory(); BTreeKeySerializer<String> strKeySerializer = (BTreeKeySerializer<String>)mgr.bTreeKeySerializerFor(stringType, false); Serializer<String> strSerializer = (Serializer<String>)mgr.serializerFor(stringType); try (SortingBuffer<String, String> buffer = mgr.createSortingBuffer(strKeySerializer, strSerializer).useHeap(true) .keepSize(true).make()) { buffer.put("value1", "first"); buffer.put("value2", "first"); buffer.put("value3", "first"); buffer.put("value1", "second"); buffer.put("value3", "second"); buffer.put("value1", "third"); assertThat(buffer.size(), is(3L)); Iterator<String> iter = buffer.ascending(); assertThat(iter.next(), is("third")); assertThat(iter.next(), is("first")); assertThat(iter.next(), is("second")); assertThat(iter.hasNext(), is(false)); iter = buffer.descending(); assertThat(iter.next(), is("second")); assertThat(iter.next(), is("first")); assertThat(iter.next(), is("third")); assertThat(iter.hasNext(), is(false)); iter = buffer.getAll("value1"); assertThat(iter.next(), is("third")); assertThat(iter.hasNext(), is(false)); } }
@SuppressWarnings( "unchecked" ) @Test public void shouldCreateSortBufferOffHeap() { TypeFactory<String> stringType = types.getStringFactory(); BTreeKeySerializer<String> strKeySerializer = (BTreeKeySerializer<String>)mgr.bTreeKeySerializerFor(stringType, false); Serializer<String> strSerializer = (Serializer<String>)mgr.serializerFor(stringType); try (SortingBuffer<String, String> buffer = mgr.createSortingBuffer(strKeySerializer, strSerializer).useHeap(false) .keepSize(true).make()) { buffer.put("value1", "first"); buffer.put("value2", "first"); buffer.put("value3", "first"); buffer.put("value1", "second"); buffer.put("value3", "second"); buffer.put("value1", "third"); assertThat(buffer.size(), is(3L)); Iterator<String> iter = buffer.ascending(); assertThat(iter.next(), is("third")); assertThat(iter.next(), is("first")); assertThat(iter.next(), is("second")); assertThat(iter.hasNext(), is(false)); iter = buffer.descending(); assertThat(iter.next(), is("second")); assertThat(iter.next(), is("first")); assertThat(iter.next(), is("third")); assertThat(iter.hasNext(), is(false)); iter = buffer.getAll("value1"); assertThat(iter.next(), is("third")); assertThat(iter.hasNext(), is(false)); } }
/** * Initialize this node sequence only the first time that {@link #nextBatch()} is called. * * @return the iterator over the buffered rows in this sequence; may be null if this sequence is empty */ protected Iterator<BufferedRow> initialize() { // Load everthing into the buffer ... batchSize = loadAll(delegate, extractor, rowsWithNullKey); remainingRowCount.set(buffer.size() + rowsWithNullKey.size()); // We always return the buffered rows in ascending order of the extracted key ... if (rowsWithNullKey.isEmpty()) { return buffer.ascending(); } // Return the rows with NULL first ... assert nullOrder != null; switch (nullOrder) { case NULLS_FIRST: return SequentialIterator.create(rowsWithNullKey.iterator(), buffer.ascending()); case NULLS_LAST: return SequentialIterator.create(buffer.ascending(), rowsWithNullKey.iterator()); } assert false; return null; }
/** * Initialize this node sequence only the first time that {@link #nextBatch()} is called. * * @return the iterator over the buffered rows in this sequence; may be null if this sequence is empty */ protected Iterator<BufferedRow> initialize() { // Load everthing into the buffer ... batchSize = loadAll(delegate, extractor, rowsWithNullKey); remainingRowCount.set(buffer.size() + rowsWithNullKey.size()); // We always return the buffered rows in ascending order of the extracted key ... if (rowsWithNullKey.isEmpty()) { return buffer.ascending(); } // Return the rows with NULL first ... assert nullOrder != null; switch (nullOrder) { case NULLS_FIRST: return SequentialIterator.create(rowsWithNullKey.iterator(), buffer.ascending()); case NULLS_LAST: return SequentialIterator.create(buffer.ascending(), rowsWithNullKey.iterator()); } assert false; return null; }
protected long rowCount() { return buffer.size(); }
protected Iterator<BufferedRows.BufferedRow> matchingRightRows(Object keyInLeft) { return buffer.getAll(keyInLeft); }
protected long rowCount() { return buffer.size(); }
protected Iterator<BufferedRow> getRightRowsFor( Object leftValue ) { return buffer.getAll(leftValue); }
protected Iterator<BufferedRow> getRightRowsFor( Object leftValue ) { return buffer.getAll(leftValue); }
protected Iterator<BufferedRows.BufferedRow> matchingRightRows(Object keyInLeft) { return buffer.getAll(keyInLeft); }
@Override protected Iterator<BufferedRow> getRightRowsFor( Object leftValue ) { if (leftValue == null) { // Nothing on the right ever matches a NULL on the left ... return null; } Range<Object> range = HashJoinSequence.this.rangeProducer.getRange(leftValue); if (range == null) return null; return buffer.getAll(range.lowerBound(), range.isLowerBoundIncluded(), range.upperBound(), range.isUpperBoundIncluded()); } }
@Override public void close() { try { super.close(); } finally { buffer.close(); } }
@Override public void close() { try { super.close(); } finally { buffer.close(); } }
@Override protected Iterator<BufferedRow> getRightRowsFor( Object leftValue ) { if (leftValue == null) { // Nothing on the right ever matches a NULL on the left ... return null; } Range<Object> range = HashJoinSequence.this.rangeProducer.getRange(leftValue); if (range == null) return null; return buffer.getAll(range.lowerBound(), range.isLowerBoundIncluded(), range.upperBound(), range.isUpperBoundIncluded()); } }