Search in sources :

Example 26 with ScalarOperator

use of com.facebook.presto.spi.function.ScalarOperator in project presto by prestodb.

the class IpAddressOperators method castFromVarbinaryToIpAddress.

@ScalarOperator(CAST)
@SqlType(StandardTypes.IPADDRESS)
public static Slice castFromVarbinaryToIpAddress(@SqlType("varbinary") Slice slice) {
    if (slice.length() == 4) {
        byte[] address = slice.getBytes();
        byte[] bytes = new byte[16];
        bytes[10] = (byte) 0xff;
        bytes[11] = (byte) 0xff;
        arraycopy(address, 0, bytes, 12, 4);
        return wrappedBuffer(bytes);
    } else if (slice.length() == 16) {
        return slice;
    } else {
        throw new PrestoException(INVALID_CAST_ARGUMENT, "Invalid IP address binary length: " + slice.length());
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)26 SqlType (com.facebook.presto.spi.function.SqlType)24 PrestoException (com.facebook.presto.spi.PrestoException)13 ISOChronology (org.joda.time.chrono.ISOChronology)9 SqlNullable (com.facebook.presto.spi.function.SqlNullable)8 JsonCastException (com.facebook.presto.util.JsonCastException)8 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)8 JsonParser (com.fasterxml.jackson.core.JsonParser)8 IOException (java.io.IOException)8 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)5 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)4 ImmutableList (com.google.common.collect.ImmutableList)2 Slice (io.airlift.slice.Slice)2 UnknownHostException (java.net.UnknownHostException)2 HyperLogLog (com.facebook.airlift.stats.cardinality.HyperLogLog)1 ScalarHeader (com.facebook.presto.operator.scalar.ScalarHeader)1 JsonUtil.currentTokenAsBoolean (com.facebook.presto.util.JsonUtil.currentTokenAsBoolean)1 JsonUtil.currentTokenAsDouble (com.facebook.presto.util.JsonUtil.currentTokenAsDouble)1 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)1 Method (java.lang.reflect.Method)1