Search in sources :

Example 1 with SingleMapBlock

use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.

the class MapElementAtFunction method elementAt.

@UsedByGeneratedCode
public static Object elementAt(MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, Block map, long key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition;
    try {
        valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
    } catch (NotSupportedException e) {
        throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
    }
    if (valuePosition == -1) {
        return null;
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 2 with SingleMapBlock

use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.

the class MapElementAtFunction method elementAt.

@UsedByGeneratedCode
public static Object elementAt(MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, Block map, boolean key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition;
    try {
        valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
    } catch (NotSupportedException e) {
        throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
    }
    if (valuePosition == -1) {
        return null;
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 3 with SingleMapBlock

use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.

the class MapSubscriptOperator method subscript.

@UsedByGeneratedCode
public static Object subscript(boolean legacyMissingKey, MissingKeyExceptionFactory missingKeyExceptionFactory, MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, SqlFunctionProperties properties, Block map, long key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition;
    try {
        valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
    } catch (NotSupportedException e) {
        throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
    }
    if (valuePosition == -1) {
        if (legacyMissingKey) {
            return null;
        }
        throw missingKeyExceptionFactory.create(properties, key);
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 4 with SingleMapBlock

use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.

the class MapSubscriptOperator method subscript.

@UsedByGeneratedCode
public static Object subscript(boolean legacyMissingKey, MissingKeyExceptionFactory missingKeyExceptionFactory, MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, SqlFunctionProperties properties, Block map, double key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition;
    try {
        valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
    } catch (NotSupportedException e) {
        throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
    }
    if (valuePosition == -1) {
        if (legacyMissingKey) {
            return null;
        }
        throw missingKeyExceptionFactory.create(properties, key);
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 5 with SingleMapBlock

use of com.facebook.presto.common.block.SingleMapBlock in project presto by prestodb.

the class MapSubscriptOperator method subscript.

@UsedByGeneratedCode
public static Object subscript(boolean legacyMissingKey, MissingKeyExceptionFactory missingKeyExceptionFactory, MethodHandle keyNativeHashCode, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockHashCode, Type valueType, SqlFunctionProperties properties, Block map, boolean key) {
    SingleMapBlock mapBlock = (SingleMapBlock) map;
    int valuePosition;
    try {
        valuePosition = mapBlock.seekKeyExact(key, keyNativeHashCode, keyBlockNativeEquals, keyBlockHashCode);
    } catch (NotSupportedException e) {
        throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
    }
    if (valuePosition == -1) {
        if (legacyMissingKey) {
            return null;
        }
        throw missingKeyExceptionFactory.create(properties, key);
    }
    return readNativeValue(valueType, mapBlock, valuePosition);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) NotSupportedException(com.facebook.presto.common.NotSupportedException) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Aggregations

SingleMapBlock (com.facebook.presto.common.block.SingleMapBlock)26 NotSupportedException (com.facebook.presto.common.NotSupportedException)12 PrestoException (com.facebook.presto.spi.PrestoException)12 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)11 Test (org.testng.annotations.Test)8 MapType (com.facebook.presto.common.type.MapType)7 Block (com.facebook.presto.common.block.Block)6 MapBlock (com.facebook.presto.common.block.MapBlock)6 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)6 AbstractMapBlock (com.facebook.presto.common.block.AbstractMapBlock)5 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)5 HashMap (java.util.HashMap)4 Type (com.facebook.presto.common.type.Type)3 TestingEnvironment.getOperatorMethodHandle (com.facebook.presto.testing.TestingEnvironment.getOperatorMethodHandle)3 MethodHandle (java.lang.invoke.MethodHandle)3 ArrayType (com.facebook.presto.common.type.ArrayType)2 Map (java.util.Map)2 BlockAssertions.createLongDictionaryBlock (com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock)1 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)1