Java Code Examples for io.prestosql.spi.type.Type#equalTo()

The following examples show how to use io.prestosql.spi.type.Type#equalTo() . 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: StructuralTestUtil.java    From presto with Apache License 2.0 6 votes vote down vote up
public static boolean mapBlocksEqual(Type keyType, Type valueType, Block block1, Block block2)
{
    if (block1.getPositionCount() != block2.getPositionCount()) {
        return false;
    }
    for (int i = 0; i < block1.getPositionCount(); i += 2) {
        if (block1.isNull(i) != block2.isNull(i) || block1.isNull(i + 1) != block2.isNull(i + 1)) {
            return false;
        }
        if (!block1.isNull(i) && !keyType.equalTo(block1, i, block2, i)) {
            return false;
        }
        if (!block1.isNull(i + 1) && !valueType.equalTo(block1, i + 1, block2, i + 1)) {
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: StructuralTestUtil.java    From presto with Apache License 2.0 5 votes vote down vote up
public static boolean arrayBlocksEqual(Type elementType, Block block1, Block block2)
{
    if (block1.getPositionCount() != block2.getPositionCount()) {
        return false;
    }
    for (int i = 0; i < block1.getPositionCount(); i++) {
        if (block1.isNull(i) != block2.isNull(i)) {
            return false;
        }
        if (!block1.isNull(i) && !elementType.equalTo(block1, i, block2, i)) {
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: ValueStore.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * This will add an item if not already in the system. It returns a pointer that is unique for multiple instances of the value. If item present,
 * returns the pointer into the system
 */
public int addAndGetPosition(Type type, Block block, int position, long valueHash)
{
    if (values.getPositionCount() >= maxFill) {
        rehash();
    }

    int bucketId = getBucketId(valueHash, mask);
    int valuePointer;

    // look for an empty slot or a slot containing this key
    int probeCount = 1;
    int originalBucketId = bucketId;
    while (true) {
        checkState(probeCount < bucketCount, "could not find match for value nor empty slot in %s buckets", bucketCount);
        valuePointer = buckets.get(bucketId);

        if (valuePointer == EMPTY_BUCKET) {
            valuePointer = values.getPositionCount();
            valueHashes.set(valuePointer, (int) valueHash);
            type.appendTo(block, position, values);
            buckets.set(bucketId, valuePointer);

            return valuePointer;
        }
        else if (type.equalTo(block, position, values, valuePointer)) {
            // value at position
            return valuePointer;
        }
        else {
            int probe = nextProbe(probeCount);
            bucketId = nextBucketId(originalBucketId, mask, probe);
            probeCount++;
        }
    }
}
 
Example 4
Source File: TuplePageFilter.java    From presto with Apache License 2.0 5 votes vote down vote up
private boolean matches(Page page, int position)
{
    for (int channel = 0; channel < inputChannels.size(); channel++) {
        Type type = types.get(channel);
        Block outputBlock = page.getBlock(channel);
        Block singleTupleBlock = tuplePage.getBlock(channel);
        if (!type.equalTo(singleTupleBlock, 0, outputBlock, position)) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: SimplePagesHashStrategy.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean positionEqualsRowIgnoreNulls(int leftBlockIndex, int leftPosition, int rightPosition, Page rightPage)
{
    for (int i = 0; i < hashChannels.size(); i++) {
        int hashChannel = hashChannels.get(i);
        Type type = types.get(hashChannel);
        Block leftBlock = channels.get(hashChannel).get(leftBlockIndex);
        Block rightBlock = rightPage.getBlock(i);
        if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) {
            return false;
        }
    }
    return true;
}
 
Example 6
Source File: SimplePagesHashStrategy.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean positionEqualsPositionIgnoreNulls(int leftBlockIndex, int leftPosition, int rightBlockIndex, int rightPosition)
{
    for (int hashChannel : hashChannels) {
        Type type = types.get(hashChannel);
        List<Block> channel = channels.get(hashChannel);
        Block leftBlock = channel.get(leftBlockIndex);
        Block rightBlock = channel.get(rightBlockIndex);
        if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) {
            return false;
        }
    }
    return true;
}
 
Example 7
Source File: TypeUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
public static boolean positionEqualsPosition(Type type, Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
    boolean leftIsNull = leftBlock.isNull(leftPosition);
    boolean rightIsNull = rightBlock.isNull(rightPosition);
    if (leftIsNull || rightIsNull) {
        return leftIsNull && rightIsNull;
    }
    return type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition);
}