@Override public boolean hasNext() { // Find the next buffered row that was not used ... while (rightRows.hasNext() && count < maxSize) { currentRight = rightRows.next(); Object key = extractor.getValueInRow(currentRight); if (key == null || rightMatchedRowKeys.addIfAbsent(key)) { logger.trace("Join found non-matched rows on right with value {0}", key); ++count; return true; } logger.trace("Join found matched rows on right with value {0}", key); } return 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; }
buffer.put(value, createRow(batch)); } else if (rowsWithNullKey != null) { rowsWithNullKey.addIfAbsent(createRow(batch));
buffer.put(value, createRow(batch)); } else if (rowsWithNullKey != null) { rowsWithNullKey.addIfAbsent(createRow(batch));
/** * 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; }
@Override public boolean hasNext() { // Find the next buffered row that was not used ... while (rightRows.hasNext() && count < maxSize) { currentRight = rightRows.next(); Object key = extractor.getValueInRow(currentRight); if (key == null || rightMatchedRowKeys.addIfAbsent(key)) { logger.trace("Join found non-matched rows on right with value {0}", key); ++count; return true; } logger.trace("Join found matched rows on right with value {0}", key); } return false; }
@Test public void shouldCreateDistinctBufferOnHeap() { try (DistinctBuffer<String> buffer = mgr.createDistinctBuffer(Serializer.STRING).useHeap(true).keepSize(true).make()) { assertTrue(buffer.addIfAbsent("first")); assertTrue(buffer.addIfAbsent("second")); assertTrue(buffer.addIfAbsent("third")); assertTrue(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("first")); assertFalse(buffer.addIfAbsent("second")); assertFalse(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("third")); assertThat(buffer.size(), is(4L)); } }
@Test public void shouldCreateDistinctBufferOffHeap() { try (DistinctBuffer<String> buffer = mgr.createDistinctBuffer(Serializer.STRING).useHeap(false).keepSize(true).make()) { assertTrue(buffer.addIfAbsent("first")); assertTrue(buffer.addIfAbsent("second")); assertTrue(buffer.addIfAbsent("third")); assertTrue(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("first")); assertFalse(buffer.addIfAbsent("second")); assertFalse(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("third")); assertThat(buffer.size(), is(4L)); } }
@Override public void close() { try { super.close(); } finally { rowsWithNullKey.close(); } }
protected void recordRightRowsMatched( Object rightKey ) { if (rightMatchedRowKeys != null) { // We only record the non-null values, since NULL never matches and they will always be unmatched ... // logger.trace("Join found matching rows on right with value {0}", matchingValue); rightMatchedRowKeys.addIfAbsent(rightKey); } }
@Override public void close() { try { super.close(); } finally { rowsWithNullKey.close(); } }
protected Iterator<BufferedRow> allRightRows() { if (rightRowsWithNullKey != null) { return SequentialIterator.create(rightRowsWithNullKey.iterator(), buffer.ascending()); } return buffer.ascending(); }
protected Iterator<BufferedRow> allRightRows() { if (rightRowsWithNullKey != null) { return SequentialIterator.create(rightRowsWithNullKey.iterator(), buffer.ascending()); } return buffer.ascending(); }
@Override public boolean isCurrentRowValid( Batch batch ) { Object key = keyExtractor.getValueInRow(batch); if (!rowsSeen.addIfAbsent(key)) { if (trace) LOGGER.trace("Distinct found existing key: {0}", key); return false; } if (trace) LOGGER.trace("Distinct found new key: {0}", key); return true; } };
@Override public long getRowCount() { if (bufferedRows == null) { bufferedRows = initialize(); } return super.rowCount() + rowsWithNullKey.size(); }
@Override public long getRowCount() { if (bufferedRows == null) { bufferedRows = initialize(); } return super.rowCount() + rowsWithNullKey.size(); }
@Override public boolean isCurrentRowValid( Batch batch ) { Object key = keyExtractor.getValueInRow(batch); if (!rowsSeen.addIfAbsent(key)) { if (trace) LOGGER.trace("Distinct found existing key: {0}", key); return false; } if (trace) LOGGER.trace("Distinct found new key: {0}", key); return true; } };
protected void recordRightRowsMatched( Object rightKey ) { if (rightMatchedRowKeys != null) { // We only record the non-null values, since NULL never matches and they will always be unmatched ... // logger.trace("Join found matching rows on right with value {0}", matchingValue); rightMatchedRowKeys.addIfAbsent(rightKey); } }