Java Code Examples for io.prestosql.spi.block.Block#getSlice()

The following examples show how to use io.prestosql.spi.block.Block#getSlice() . 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: KuduUpdatablePageSource.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteRows(Block rowIds)
{
    Schema schema = table.getSchema();
    KuduSession session = clientSession.newSession();
    session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND);
    try {
        try {
            for (int i = 0; i < rowIds.getPositionCount(); i++) {
                int len = rowIds.getSliceLength(i);
                Slice slice = rowIds.getSlice(i, 0, len);
                PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes());
                Delete delete = table.newDelete();
                RowHelper.copyPrimaryKey(schema, row, delete.getRow());
                session.apply(delete);
            }
        }
        finally {
            session.close();
        }
    }
    catch (KuduException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: CharType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    Slice leftSlice = leftBlock.getSlice(leftPosition, 0, leftBlock.getSliceLength(leftPosition));
    Slice rightSlice = rightBlock.getSlice(rightPosition, 0, rightBlock.getSliceLength(rightPosition));

    return compareChars(leftSlice, rightSlice);
}
 
Example 3
Source File: CodePointsType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObject(Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }

    Slice slice = block.getSlice(position, 0, block.getSliceLength(position));
    int[] codePoints = new int[slice.length() / Integer.BYTES];
    slice.getBytes(0, Slices.wrappedIntArray(codePoints));
    return codePoints;
}
 
Example 4
Source File: JsonType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    Slice leftValue = leftBlock.getSlice(leftPosition, 0, leftBlock.getSliceLength(leftPosition));
    Slice rightValue = rightBlock.getSlice(rightPosition, 0, rightBlock.getSliceLength(rightPosition));
    return leftValue.equals(rightValue);
}
 
Example 5
Source File: SphericalGeographyType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectValue(ConnectorSession session, Block block, int position)
{
    if (block.isNull(position)) {
        return null;
    }
    Slice slice = block.getSlice(position, 0, block.getSliceLength(position));
    return deserialize(slice).asText();
}
 
Example 6
Source File: ArrayType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 7
Source File: CharType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 8
Source File: SphericalGeographyType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 9
Source File: VarcharType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 10
Source File: ShortTimestampWithTimeZoneType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public final Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, getFixedSize());
}
 
Example 11
Source File: HyperLogLogType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 12
Source File: VarbinaryType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 13
Source File: AbstractLongType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public final Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, getFixedSize());
}
 
Example 14
Source File: SliceDictionaryColumnWriter.java    From presto with Apache License 2.0 4 votes vote down vote up
private void bufferOutputData()
{
    checkState(closed);
    checkState(!directEncoded);

    Block dictionaryElements = dictionary.getElementBlock();

    // write dictionary in sorted order
    int[] sortedDictionaryIndexes = getSortedDictionaryNullsLast(dictionaryElements);
    for (int sortedDictionaryIndex : sortedDictionaryIndexes) {
        if (!dictionaryElements.isNull(sortedDictionaryIndex)) {
            int length = dictionaryElements.getSliceLength(sortedDictionaryIndex);
            dictionaryLengthStream.writeLong(length);
            Slice value = dictionaryElements.getSlice(sortedDictionaryIndex, 0, length);
            dictionaryDataStream.writeSlice(value);
        }
    }
    columnEncoding = new ColumnEncoding(DICTIONARY_V2, dictionaryElements.getPositionCount() - 1);

    // build index from original dictionary index to new sorted position
    int[] originalDictionaryToSortedIndex = new int[sortedDictionaryIndexes.length];
    for (int sortOrdinal = 0; sortOrdinal < sortedDictionaryIndexes.length; sortOrdinal++) {
        int dictionaryIndex = sortedDictionaryIndexes[sortOrdinal];
        originalDictionaryToSortedIndex[dictionaryIndex] = sortOrdinal;
    }

    if (!rowGroups.isEmpty()) {
        presentStream.recordCheckpoint();
        dataStream.recordCheckpoint();
    }
    for (DictionaryRowGroup rowGroup : rowGroups) {
        IntBigArray dictionaryIndexes = rowGroup.getDictionaryIndexes();
        for (int position = 0; position < rowGroup.getValueCount(); position++) {
            presentStream.writeBoolean(dictionaryIndexes.get(position) != 0);
        }
        for (int position = 0; position < rowGroup.getValueCount(); position++) {
            int originalDictionaryIndex = dictionaryIndexes.get(position);
            // index zero in original dictionary is reserved for null
            if (originalDictionaryIndex != 0) {
                int sortedIndex = originalDictionaryToSortedIndex[originalDictionaryIndex];
                if (sortedIndex < 0) {
                    throw new IllegalArgumentException();
                }
                dataStream.writeLong(sortedIndex);
            }
        }
        presentStream.recordCheckpoint();
        dataStream.recordCheckpoint();
    }

    // free the dictionary memory
    dictionary.clear();

    dictionaryDataStream.close();
    dictionaryLengthStream.close();

    dataStream.close();
    presentStream.close();
}
 
Example 15
Source File: ModelType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 16
Source File: QuantileDigestType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 17
Source File: JsonType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 18
Source File: SetDigestType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 19
Source File: GeometryType.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Slice getSlice(Block block, int position)
{
    return block.getSlice(position, 0, block.getSliceLength(position));
}
 
Example 20
Source File: PagesRTreeIndex.java    From presto with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an array of addresses from {@link PagesIndex#valueAddresses} corresponding
 * to rows with matching geometries.
 * <p>
 * The caller is responsible for calling {@link #isJoinPositionEligible(int, int, Page)}
 * for each of these addresses to apply additional join filters.
 */
@Override
public int[] findJoinPositions(int probePosition, Page probe, int probeGeometryChannel, Optional<Integer> probePartitionChannel)
{
    Block probeGeometryBlock = probe.getBlock(probeGeometryChannel);
    if (probeGeometryBlock.isNull(probePosition)) {
        return EMPTY_ADDRESSES;
    }

    int probePartition = probePartitionChannel.map(channel -> toIntExact(INTEGER.getLong(probe.getBlock(channel), probePosition))).orElse(-1);

    Slice slice = probeGeometryBlock.getSlice(probePosition, 0, probeGeometryBlock.getSliceLength(probePosition));
    OGCGeometry probeGeometry = deserialize(slice);
    verifyNotNull(probeGeometry);
    if (probeGeometry.isEmpty()) {
        return EMPTY_ADDRESSES;
    }

    boolean probeIsPoint = probeGeometry instanceof OGCPoint;

    IntArrayList matchingPositions = new IntArrayList();

    Envelope envelope = getEnvelope(probeGeometry);
    rtree.query(envelope, item -> {
        GeometryWithPosition geometryWithPosition = (GeometryWithPosition) item;
        OGCGeometry buildGeometry = geometryWithPosition.getGeometry();
        if (partitions.isEmpty() || (probePartition == geometryWithPosition.getPartition() && (probeIsPoint || (buildGeometry instanceof OGCPoint) || testReferencePoint(envelope, buildGeometry, probePartition)))) {
            if (radiusChannel == -1) {
                if (spatialRelationshipTest.apply(buildGeometry, probeGeometry, OptionalDouble.empty())) {
                    matchingPositions.add(geometryWithPosition.getPosition());
                }
            }
            else {
                if (spatialRelationshipTest.apply(geometryWithPosition.getGeometry(), probeGeometry, OptionalDouble.of(getRadius(geometryWithPosition.getPosition())))) {
                    matchingPositions.add(geometryWithPosition.getPosition());
                }
            }
        }
    });

    return matchingPositions.toIntArray(null);
}