@Override public Block getLoadedBlock() { return block.getLoadedBlock(); } }
@Override public Block getLoadedBlock() { return block.getLoadedBlock(); } }
@Override public Optional<Block> replacementBlockForWrite(Block block) { return Optional.of(block.getLoadedBlock()); } }
@Override public Block getLoadedBlock() { Block loadedValueBlock = value.getLoadedBlock(); if (loadedValueBlock == value) { return this; } return new RunLengthEncodedBlock(loadedValueBlock, positionCount); }
@Override public void load(LazyBlock lazyBlock) { if (block == null) { return; } lazyBlock.setBlock(coercer.apply(block.getLoadedBlock())); // clear reference to loader to free resources, since load was successful block = null; } }
@Override public Block getLoadedBlock() { if (keyBlock != keyBlock.getLoadedBlock()) { // keyBlock has to be loaded since MapBlock constructs hash table eagerly. throw new IllegalStateException(); } Block loadedValueBlock = valueBlock.getLoadedBlock(); if (loadedValueBlock == valueBlock) { return this; } return new SingleMapBlock( offset, positionCount, keyBlock, loadedValueBlock, hashTable, keyType, keyNativeHashCode, keyBlockNativeEquals); }
@Override public Block getLoadedBlock() { Block loadedValuesBlock = values.getLoadedBlock(); if (loadedValuesBlock == values) { return this; } return createArrayBlockInternal( arrayOffset, positionCount, valueIsNull, offsets, loadedValuesBlock); } }
@Override public Block getLoadedBlock() { if (keyBlock != keyBlock.getLoadedBlock()) { // keyBlock has to be loaded since MapBlock constructs hash table eagerly. throw new IllegalStateException(); } Block loadedValueBlock = valueBlock.getLoadedBlock(); if (loadedValueBlock == valueBlock) { return this; } return createMapBlockInternal( startOffset, positionCount, Optional.ofNullable(mapIsNull), offsets, keyBlock, loadedValueBlock, hashTables, keyType, keyBlockNativeEquals, keyNativeHashCode); } }
@Override public Block getLoadedBlock() { boolean allLoaded = true; Block[] loadedFieldBlocks = new Block[fieldBlocks.length]; for (int i = 0; i < fieldBlocks.length; i++) { loadedFieldBlocks[i] = fieldBlocks[i].getLoadedBlock(); if (loadedFieldBlocks[i] != fieldBlocks[i]) { allLoaded = false; } } if (allLoaded) { return this; } return new SingleRowBlock(rowIndex, loadedFieldBlocks); } }
/** * Returns a page that assures all data is in memory. * May return the same page if all page data is already in memory. * <p> * This allows streaming data sources to skip sections that are not * accessed in a query. */ public Page getLoadedPage() { boolean allLoaded = true; Block[] loadedBlocks = new Block[blocks.length]; for (int i = 0; i < blocks.length; i++) { loadedBlocks[i] = blocks[i].getLoadedBlock(); if (loadedBlocks[i] != blocks[i]) { allLoaded = false; } } if (allLoaded) { return this; } return new Page(loadedBlocks); }
@Override public Block getLoadedBlock() { boolean allLoaded = true; Block[] loadedFieldBlocks = new Block[fieldBlocks.length]; for (int i = 0; i < fieldBlocks.length; i++) { loadedFieldBlocks[i] = fieldBlocks[i].getLoadedBlock(); if (loadedFieldBlocks[i] != fieldBlocks[i]) { allLoaded = false; } } if (allLoaded) { return this; } return createRowBlockInternal( startOffset, positionCount, rowIsNull, fieldBlockOffsets, loadedFieldBlocks); } }
public DictionaryAwarePageProjectionWork(@Nullable ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) { this.session = session; this.yieldSignal = requireNonNull(yieldSignal, "yieldSignal is null"); Block block = requireNonNull(page, "page is null").getBlock(0).getLoadedBlock(); this.block = block; this.selectedPositions = requireNonNull(selectedPositions, "selectedPositions is null"); Optional<Block> dictionary = Optional.empty(); if (block instanceof RunLengthEncodedBlock) { dictionary = Optional.of(((RunLengthEncodedBlock) block).getValue()); } else if (block instanceof DictionaryBlock) { dictionary = Optional.of(((DictionaryBlock) block).getDictionary()); } // Try use dictionary processing first; if it fails, fall back to the generic case dictionaryProcessingProjectionWork = createDictionaryBlockProjection(dictionary); fallbackProcessingProjectionWork = null; }
public DictionaryAwarePageProjectionWork(@Nullable ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) { this.session = session; this.yieldSignal = requireNonNull(yieldSignal, "yieldSignal is null"); Block block = requireNonNull(page, "page is null").getBlock(0).getLoadedBlock(); this.block = block; this.selectedPositions = requireNonNull(selectedPositions, "selectedPositions is null"); Optional<Block> dictionary = Optional.empty(); if (block instanceof RunLengthEncodedBlock) { dictionary = Optional.of(((RunLengthEncodedBlock) block).getValue()); } else if (block instanceof DictionaryBlock) { dictionary = Optional.of(((DictionaryBlock) block).getDictionary()); } // Try use dictionary processing first; if it fails, fall back to the generic case dictionaryProcessingProjectionWork = createDictionaryBlockProjection(dictionary); fallbackProcessingProjectionWork = null; }
@Override protected Page computeNext() { try { if (Thread.currentThread().isInterrupted()) { throw new InterruptedIOException(); } int batchSize = reader.nextBatch(); if (batchSize <= 0) { return endOfData(); } Block[] blocks = new Block[types.size()]; for (int i = 0; i < types.size(); i++) { blocks[i] = reader.readBlock(types.get(i), i).getLoadedBlock(); } return new Page(batchSize, blocks); } catch (IOException e) { throw new PrestoException(HIVE_WRITER_DATA_ERROR, "Failed to read temporary data"); } } }
@Override public Block getLoadedBlock() { Block loadedDictionary = dictionary.getLoadedBlock(); if (loadedDictionary == dictionary) { return this; } return new DictionaryBlock(idsOffset, getPositionCount(), loadedDictionary, ids, false, randomDictionaryId()); }
@Override public Work<Block> project(ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) { return new CompletedWork<>(page.getBlock(0).getLoadedBlock()); } }
@Override public Work<Block> project(ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) { return new CompletedWork<>(page.getBlock(0).getLoadedBlock()); } }
@Override public SelectedPositions filter(ConnectorSession session, Page page) { Block block = page.getBlock(0).getLoadedBlock(); if (block instanceof RunLengthEncodedBlock) { Block value = ((RunLengthEncodedBlock) block).getValue(); Optional<boolean[]> selectedPosition = processDictionary(session, value); // single value block is always considered effective, but the processing could have thrown // in that case we fallback and process again so the correct error message sent if (selectedPosition.isPresent()) { return SelectedPositions.positionsRange(0, selectedPosition.get()[0] ? page.getPositionCount() : 0); } } if (block instanceof DictionaryBlock) { DictionaryBlock dictionaryBlock = (DictionaryBlock) block; // Attempt to process the dictionary. If dictionary is processing has not been considered effective, an empty response will be returned Optional<boolean[]> selectedDictionaryPositions = processDictionary(session, dictionaryBlock.getDictionary()); // record the usage count regardless of dictionary processing choice, so we have stats for next time lastDictionaryUsageCount += page.getPositionCount(); // if dictionary was processed, produce a dictionary block; otherwise do normal processing if (selectedDictionaryPositions.isPresent()) { return selectDictionaryPositions(dictionaryBlock, selectedDictionaryPositions.get()); } } return filter.filter(session, new Page(block)); }
private static void testFilter(DictionaryAwarePageFilter filter, Block block, boolean filterRange) { IntSet actualSelectedPositions = toSet(filter.filter(null, new Page(block))); block = block.getLoadedBlock(); IntSet expectedSelectedPositions = new IntArraySet(block.getPositionCount()); for (int position = 0; position < block.getPositionCount(); position++) { if (isSelected(filterRange, block.getLong(position, 0))) { expectedSelectedPositions.add(position); } } assertEquals(actualSelectedPositions, expectedSelectedPositions); }
private static void testFilter(DictionaryAwarePageFilter filter, Block block, boolean filterRange) { IntSet actualSelectedPositions = toSet(filter.filter(null, new Page(block))); block = block.getLoadedBlock(); IntSet expectedSelectedPositions = new IntArraySet(block.getPositionCount()); for (int position = 0; position < block.getPositionCount(); position++) { if (isSelected(filterRange, block.getLong(position, 0))) { expectedSelectedPositions.add(position); } } assertEquals(actualSelectedPositions, expectedSelectedPositions); }