Search in sources :

Example 6 with ScalarFunction

use of io.trino.spi.function.ScalarFunction in project trino by trinodb.

the class UrlFunctions method urlExtractParameter.

@SqlNullable
@Description("Extract query parameter from url")
@ScalarFunction
@LiteralParameters({ "x", "y" })
@SqlType("varchar(x)")
public static Slice urlExtractParameter(@SqlType("varchar(x)") Slice url, @SqlType("varchar(y)") Slice parameterName) {
    URI uri = parseUrl(url);
    if ((uri == null) || (uri.getRawQuery() == null)) {
        return null;
    }
    String parameter = parameterName.toStringUtf8();
    Iterable<String> queryArgs = QUERY_SPLITTER.split(uri.getRawQuery());
    for (String queryArg : queryArgs) {
        Iterator<String> arg = ARG_SPLITTER.split(queryArg).iterator();
        if (arg.next().equals(parameter)) {
            if (arg.hasNext()) {
                return decodeUrl(arg.next());
            }
            // first matched key is empty
            return Slices.EMPTY_SLICE;
        }
    }
    // no key matched
    return null;
}
Also used : URI(java.net.URI) SqlNullable(io.trino.spi.function.SqlNullable) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) LiteralParameters(io.trino.spi.function.LiteralParameters) SqlType(io.trino.spi.function.SqlType)

Example 7 with ScalarFunction

use of io.trino.spi.function.ScalarFunction in project trino by trinodb.

the class VarbinaryFunctions method toIEEE754Binary64.

@Description("Encode value as a big endian varbinary according to IEEE 754 double-precision floating-point format")
@ScalarFunction("to_ieee754_64")
@SqlType(StandardTypes.VARBINARY)
public static Slice toIEEE754Binary64(@SqlType(StandardTypes.DOUBLE) double value) {
    Slice slice = Slices.allocate(Double.BYTES);
    slice.setLong(0, Long.reverseBytes(Double.doubleToLongBits(value)));
    return slice;
}
Also used : Slice(io.airlift.slice.Slice) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 8 with ScalarFunction

use of io.trino.spi.function.ScalarFunction in project trino by trinodb.

the class VarbinaryFunctions method toBigEndian32.

@Description("Encode value as a 32-bit 2's complement big endian varbinary")
@ScalarFunction("to_big_endian_32")
@SqlType(StandardTypes.VARBINARY)
public static Slice toBigEndian32(@SqlType(StandardTypes.INTEGER) long value) {
    Slice slice = Slices.allocate(Integer.BYTES);
    slice.setInt(0, Integer.reverseBytes((int) value));
    return slice;
}
Also used : Slice(io.airlift.slice.Slice) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 9 with ScalarFunction

use of io.trino.spi.function.ScalarFunction in project trino by trinodb.

the class VarbinaryFunctions method spookyHashV2_32.

@Description("Compute SpookyHashV2 32-bit hash")
@ScalarFunction
@SqlType(StandardTypes.VARBINARY)
public static Slice spookyHashV2_32(@SqlType(StandardTypes.VARBINARY) Slice slice) {
    Slice hash = Slices.allocate(Integer.BYTES);
    hash.setInt(0, Integer.reverseBytes(SpookyHashV2.hash32(slice, 0, slice.length(), 0)));
    return hash;
}
Also used : Slice(io.airlift.slice.Slice) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Example 10 with ScalarFunction

use of io.trino.spi.function.ScalarFunction in project trino by trinodb.

the class VarbinaryFunctions method toIEEE754Binary32.

@Description("Encode value as a big endian varbinary according to IEEE 754 single-precision floating-point format")
@ScalarFunction("to_ieee754_32")
@SqlType(StandardTypes.VARBINARY)
public static Slice toIEEE754Binary32(@SqlType(StandardTypes.REAL) long value) {
    Slice slice = Slices.allocate(Float.BYTES);
    slice.setInt(0, Integer.reverseBytes((int) value));
    return slice;
}
Also used : Slice(io.airlift.slice.Slice) ScalarFunction(io.trino.spi.function.ScalarFunction) Description(io.trino.spi.function.Description) SqlType(io.trino.spi.function.SqlType)

Aggregations

ScalarFunction (io.trino.spi.function.ScalarFunction)108 SqlType (io.trino.spi.function.SqlType)107 Description (io.trino.spi.function.Description)90 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)46 SqlNullable (io.trino.spi.function.SqlNullable)44 LiteralParameters (io.trino.spi.function.LiteralParameters)25 BlockBuilder (io.trino.spi.block.BlockBuilder)21 Constraint (io.trino.type.Constraint)21 Point (com.esri.core.geometry.Point)17 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)17 Slice (io.airlift.slice.Slice)17 TrinoException (io.trino.spi.TrinoException)17 MultiPoint (com.esri.core.geometry.MultiPoint)15 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)10 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)9 Matcher (io.airlift.joni.Matcher)8 GeometryType (io.trino.geospatial.GeometryType)7 JsonParser (com.fasterxml.jackson.core.JsonParser)6 JsonToken (com.fasterxml.jackson.core.JsonToken)6 Envelope (com.esri.core.geometry.Envelope)5