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

The following examples show how to use io.prestosql.spi.block.Block#isNull() . 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: RowEqualOperator.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Boolean equals(RowType rowType, List<MethodHandle> fieldEqualOperators, Block leftRow, Block rightRow)
{
    boolean indeterminate = false;
    for (int fieldIndex = 0; fieldIndex < leftRow.getPositionCount(); fieldIndex++) {
        if (leftRow.isNull(fieldIndex) || rightRow.isNull(fieldIndex)) {
            indeterminate = true;
            continue;
        }
        Type fieldType = rowType.getTypeParameters().get(fieldIndex);
        Object leftField = readNativeValue(fieldType, leftRow, fieldIndex);
        Object rightField = readNativeValue(fieldType, rightRow, fieldIndex);
        try {
            MethodHandle equalOperator = fieldEqualOperators.get(fieldIndex);
            Boolean result = (Boolean) equalOperator.invoke(leftField, rightField);
            if (result == null) {
                indeterminate = true;
            }
            else if (!result) {
                return false;
            }
        }
        catch (Throwable t) {
            throw internalError(t);
        }
    }

    if (indeterminate) {
        return null;
    }
    return true;
}
 
Example 2
Source File: PagesIndex.java    From presto with Apache License 2.0 5 votes vote down vote up
public boolean isNull(int channel, int position)
{
    long pageAddress = valueAddresses.getLong(position);

    Block block = channels[channel].get(decodeSliceIndex(pageAddress));
    int blockPosition = decodePosition(pageAddress);
    return block.isNull(blockPosition);
}
 
Example 3
Source File: TypeUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
public static long hashPosition(Type type, Block block, int position)
{
    if (block.isNull(position)) {
        return NULL_HASH_CODE;
    }
    return type.hash(block, position);
}
 
Example 4
Source File: FloatEncoding.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void encodeColumn(Block block, SliceOutput output, EncodeOutput encodeOutput)
{
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (!block.isNull(position)) {
            output.writeInt(Integer.reverseBytes((int) type.getLong(block, position)));
        }
        encodeOutput.closeEntry();
    }
}
 
Example 5
Source File: HiveCoercionRecordCursor.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void coerce(RecordCursor delegate, int field)
{
    if (delegate.isNull(field)) {
        setIsNull(true);
        return;
    }
    Block block = (Block) delegate.getObject(field);
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder mapBuilder = blockBuilder.beginBlockEntry();
    for (int i = 0; i < block.getPositionCount(); i++) {
        int k = i % 2;
        if (coercers[k] == null) {
            toKeyValueTypes.get(k).appendTo(block, i, mapBuilder);
        }
        else {
            if (block.isNull(i)) {
                mapBuilder.appendNull();
            }
            else {
                rewriteBlock(fromKeyValueTypes.get(k), toKeyValueTypes.get(k), block, i, mapBuilder, coercers[k], bridgingRecordCursor);
            }
        }
    }
    blockBuilder.closeEntry();
    pageBuilder.declarePosition();
    setObject(toType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1));
}
 
Example 6
Source File: TimestampEncoding.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void encodeColumn(Block block, SliceOutput output, EncodeOutput encodeOutput)
{
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (!block.isNull(position)) {
            writeTimestamp(output, type.getLong(block, position));
        }
        encodeOutput.closeEntry();
    }
}
 
Example 7
Source File: GeometryType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
    if (block.isNull(position)) {
        blockBuilder.appendNull();
    }
    else {
        block.writeBytesTo(position, 0, block.getSliceLength(position), blockBuilder);
        blockBuilder.closeEntry();
    }
}
 
Example 8
Source File: AbstractLongType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public final void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
    if (block.isNull(position)) {
        blockBuilder.appendNull();
    }
    else {
        blockBuilder.writeLong(block.getLong(position, 0)).closeEntry();
    }
}
 
Example 9
Source File: DateEncoding.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void encodeColumn(Block block, SliceOutput output, EncodeOutput encodeOutput)
{
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (!block.isNull(position)) {
            encodeValueInto(block, position, output);
        }
        encodeOutput.closeEntry();
    }
}
 
Example 10
Source File: ArrayType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
    if (block.isNull(position)) {
        blockBuilder.appendNull();
    }
    else {
        block.writePositionTo(position, blockBuilder);
    }
}
 
Example 11
Source File: SliceDictionaryColumnWriter.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void writeBlock(Block block)
{
    checkState(!closed);
    checkArgument(block.getPositionCount() > 0, "Block is empty");

    if (directEncoded) {
        directColumnWriter.writeBlock(block);
        return;
    }

    // record values
    values.ensureCapacity(rowGroupValueCount + block.getPositionCount());
    for (int position = 0; position < block.getPositionCount(); position++) {
        int index = dictionary.putIfAbsent(block, position);
        values.set(rowGroupValueCount, index);
        rowGroupValueCount++;
        totalValueCount++;

        if (!block.isNull(position)) {
            // todo min/max statistics only need to be updated if value was not already in the dictionary, but non-null count does
            statisticsBuilder.addValue(type.getSlice(block, position));

            rawBytes += block.getSliceLength(position);
            totalNonNullValueCount++;
        }
    }
}
 
Example 12
Source File: BooleanEncoding.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void encodeColumn(Block block, SliceOutput output, EncodeOutput encodeOutput)
{
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (block.isNull(position)) {
            output.writeBytes(nullSequence);
        }
        else {
            encodeValue(block, position, output);
        }
        encodeOutput.closeEntry();
    }
}
 
Example 13
Source File: VarbinaryType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
    if (block.isNull(position)) {
        blockBuilder.appendNull();
    }
    else {
        block.writeBytesTo(position, 0, block.getSliceLength(position), blockBuilder);
        blockBuilder.closeEntry();
    }
}
 
Example 14
Source File: PartitionTransforms.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Block extractDate(Block block, LongUnaryOperator function)
{
    BlockBuilder builder = INTEGER.createFixedSizeBlockBuilder(block.getPositionCount());
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (block.isNull(position)) {
            builder.appendNull();
            continue;
        }
        long value = DATE.getLong(block, position);
        value = function.applyAsLong(value);
        INTEGER.writeLong(builder, value);
    }
    return builder.build();
}
 
Example 15
Source File: JsonUtil.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, ConnectorSession session)
        throws IOException
{
    if (block.isNull(position)) {
        jsonGenerator.writeNull();
    }
    else {
        int value = toIntExact(DATE.getLong(block, position));
        jsonGenerator.writeString(printDate(value));
    }
}
 
Example 16
Source File: SmallintType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
    if (block.isNull(position)) {
        blockBuilder.appendNull();
    }
    else {
        blockBuilder.writeShort(block.getShort(position, 0)).closeEntry();
    }
}
 
Example 17
Source File: SmallintOperators.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlType(StandardTypes.BOOLEAN)
public static boolean isDistinctFrom(
        @BlockPosition @SqlType(value = StandardTypes.SMALLINT, nativeContainerType = long.class) Block left,
        @BlockIndex int leftPosition,
        @BlockPosition @SqlType(value = StandardTypes.SMALLINT, nativeContainerType = long.class) Block right,
        @BlockIndex int rightPosition)
{
    if (left.isNull(leftPosition) != right.isNull(rightPosition)) {
        return true;
    }
    if (left.isNull(leftPosition)) {
        return false;
    }
    return notEqual(SMALLINT.getLong(left, leftPosition), SMALLINT.getLong(right, rightPosition));
}
 
Example 18
Source File: JsonUtil.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void writeJsonValue(JsonGenerator jsonGenerator, Block block, int position, ConnectorSession session)
        throws IOException
{
    if (block.isNull(position)) {
        jsonGenerator.writeNull();
    }
    else {
        boolean value = BOOLEAN.getBoolean(block, position);
        jsonGenerator.writeBoolean(value);
    }
}
 
Example 19
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);
}
 
Example 20
Source File: MultimapFromEntriesFunction.java    From presto with Apache License 2.0 4 votes vote down vote up
@TypeParameter("K")
@TypeParameter("V")
@SqlType("map(K,array(V))")
@SqlNullable
public Block multimapFromEntries(
        @TypeParameter("map(K,array(V))") MapType mapType,
        @SqlType("array(row(K,V))") Block block)
{
    Type keyType = mapType.getKeyType();
    Type valueType = ((ArrayType) mapType.getValueType()).getElementType();
    RowType rowType = RowType.anonymous(ImmutableList.of(keyType, valueType));

    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }

    int entryCount = block.getPositionCount();
    if (entryCount > entryIndicesList.length) {
        initializeEntryIndicesList(entryCount);
    }
    TypedSet keySet = new TypedSet(keyType, entryCount, NAME);

    for (int i = 0; i < entryCount; i++) {
        if (block.isNull(i)) {
            clearEntryIndices(keySet.size());
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map entry cannot be null");
        }
        Block rowBlock = rowType.getObject(block, i);

        if (rowBlock.isNull(0)) {
            clearEntryIndices(keySet.size());
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
        }

        if (keySet.contains(rowBlock, 0)) {
            entryIndicesList[keySet.positionOf(rowBlock, 0)].add(i);
        }
        else {
            keySet.add(rowBlock, 0);
            entryIndicesList[keySet.size() - 1].add(i);
        }
    }

    BlockBuilder multimapBlockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder singleMapWriter = multimapBlockBuilder.beginBlockEntry();
    for (int i = 0; i < keySet.size(); i++) {
        keyType.appendTo(rowType.getObject(block, entryIndicesList[i].getInt(0)), 0, singleMapWriter);
        BlockBuilder singleArrayWriter = singleMapWriter.beginBlockEntry();
        for (int entryIndex : entryIndicesList[i]) {
            valueType.appendTo(rowType.getObject(block, entryIndex), 1, singleArrayWriter);
        }
        singleMapWriter.closeEntry();
    }

    multimapBlockBuilder.closeEntry();
    pageBuilder.declarePosition();
    clearEntryIndices(keySet.size());
    return mapType.getObject(multimapBlockBuilder, multimapBlockBuilder.getPositionCount() - 1);
}