Java Code Examples for it.unimi.dsi.fastutil.ints.IntArrayList#isEmpty()

The following examples show how to use it.unimi.dsi.fastutil.ints.IntArrayList#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PartitioningExchanger.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void accept(Page page)
{
    // reset the assignment lists
    for (IntList partitionAssignment : partitionAssignments) {
        partitionAssignment.clear();
    }

    // assign each row to a partition
    for (int position = 0; position < page.getPositionCount(); position++) {
        int partition = partitionGenerator.getPartition(page, position);
        partitionAssignments[partition].add(position);
    }

    // build a page for each partition
    Block[] outputBlocks = new Block[page.getChannelCount()];
    for (int partition = 0; partition < buffers.size(); partition++) {
        IntArrayList positions = partitionAssignments[partition];
        if (!positions.isEmpty()) {
            for (int i = 0; i < page.getChannelCount(); i++) {
                outputBlocks[i] = page.getBlock(i).copyPositions(positions.elements(), 0, positions.size());
            }

            Page pageSplit = new Page(positions.size(), outputBlocks);
            memoryManager.updateMemoryUsage(pageSplit.getRetainedSizeInBytes());
            buffers.get(partition).accept(new PageReference(pageSplit, 1, () -> memoryManager.updateMemoryUsage(-pageSplit.getRetainedSizeInBytes())));
        }
    }
}
 
Example 2
Source File: TestDictionaryAwarePageFilter.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public SelectedPositions filter(ConnectorSession session, Page page)
{
    assertEquals(page.getChannelCount(), 1);
    Block block = page.getBlock(0);

    boolean sequential = true;
    IntArrayList selectedPositions = new IntArrayList();
    for (int position = 0; position < block.getPositionCount(); position++) {
        long value = block.getLong(position, 0);
        verifyPositive(value);

        boolean selected = isSelected(filterRange, value);
        if (selected) {
            if (sequential && !selectedPositions.isEmpty()) {
                sequential = (position == selectedPositions.getInt(selectedPositions.size() - 1) + 1);
            }
            selectedPositions.add(position);
        }
    }
    if (selectedPositions.isEmpty()) {
        return SelectedPositions.positionsRange(0, 0);
    }
    if (sequential) {
        return SelectedPositions.positionsRange(selectedPositions.getInt(0), selectedPositions.size());
    }
    // add 3 invalid elements to the head and tail
    for (int i = 0; i < 3; i++) {
        selectedPositions.add(0, -1);
        selectedPositions.add(-1);
    }

    // verify the input block is the expected type (this is to assure that
    // dictionary processing enabled and disabled as expected)
    // this check is performed last so that dictionary processing that fails
    // is not checked (only the fall back processing is checked)
    assertTrue(expectedType.isInstance(block));

    return SelectedPositions.positionsList(selectedPositions.elements(), 3, selectedPositions.size() - 6);
}
 
Example 3
Source File: MessageColumnIO.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private void writeNullToLeaves(GroupColumnIO group) {
  IntArrayList nullCache = groupNullCache.get(group);
  if (nullCache == null || nullCache.isEmpty())
    return;

  int parentDefinitionLevel = group.getParent().getDefinitionLevel();
  for (ColumnWriter leafWriter : groupToLeafWriter.get(group)) {
    for (IntIterator iter = nullCache.iterator(); iter.hasNext();) {
      int repetitionLevel = iter.nextInt();
      leafWriter.writeNull(repetitionLevel, parentDefinitionLevel);
    }
  }
  nullCache.clear();
}
 
Example 4
Source File: SortedPositionLinks.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Factory build()
{
    ArrayPositionLinks.FactoryBuilder arrayPositionLinksFactoryBuilder = ArrayPositionLinks.builder(size);
    int[][] sortedPositionLinks = new int[size][];

    for (Int2ObjectMap.Entry<IntArrayList> entry : positionLinks.int2ObjectEntrySet()) {
        int key = entry.getIntKey();
        IntArrayList positions = entry.getValue();
        positions.sort(comparator);

        sortedPositionLinks[key] = new int[positions.size()];
        for (int i = 0; i < positions.size(); i++) {
            sortedPositionLinks[key][i] = positions.get(i);
        }

        // ArrayPositionsLinks.Builder::link builds position links from
        // tail to head, so we must add them in descending order to have
        // smallest element as a head
        for (int i = positions.size() - 2; i >= 0; i--) {
            arrayPositionLinksFactoryBuilder.link(positions.get(i), positions.get(i + 1));
        }

        // add link from starting position to position links chain
        if (!positions.isEmpty()) {
            arrayPositionLinksFactoryBuilder.link(key, positions.get(0));
        }
    }

    Factory arrayPositionLinksFactory = arrayPositionLinksFactoryBuilder.build();

    return new Factory()
    {
        @Override
        public PositionLinks create(List<JoinFilterFunction> searchFunctions)
        {
            return new SortedPositionLinks(
                    arrayPositionLinksFactory.create(ImmutableList.of()),
                    sortedPositionLinks,
                    searchFunctions);
        }

        @Override
        public long checksum()
        {
            // For spill/unspill state restoration, sorted position links do not matter
            return arrayPositionLinksFactory.checksum();
        }
    };
}
 
Example 5
Source File: MessageColumnIO.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private boolean hasNullCache(GroupColumnIO group) {
  IntArrayList nulls = groupNullCache.get(group);
  return nulls != null && !nulls.isEmpty();
}