Search in sources :

Example 26 with SqlType

use of io.prestosql.spi.function.SqlType in project hetu-core by openlookeng.

the class SetDigestFunctions method hashCounts.

@ScalarFunction
@SqlType("map(bigint,smallint)")
public static Block hashCounts(@TypeParameter("map<bigint,smallint>") Type mapType, @SqlType(SetDigestType.NAME) Slice slice) {
    SetDigest digest = SetDigest.newInstance(slice);
    // Maybe use static BlockBuilderStatus in order avoid `new`?
    BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 1);
    BlockBuilder singleMapBlockBuilder = blockBuilder.beginBlockEntry();
    for (Map.Entry<Long, Short> entry : digest.getHashCounts().entrySet()) {
        BIGINT.writeLong(singleMapBlockBuilder, entry.getKey());
        SMALLINT.writeLong(singleMapBlockBuilder, entry.getValue());
    }
    blockBuilder.closeEntry();
    return (Block) mapType.getObject(blockBuilder, 0);
}
Also used : Block(io.prestosql.spi.block.Block) Map(java.util.Map) BlockBuilder(io.prestosql.spi.block.BlockBuilder) ScalarFunction(io.prestosql.spi.function.ScalarFunction) SqlType(io.prestosql.spi.function.SqlType)

Example 27 with SqlType

use of io.prestosql.spi.function.SqlType in project hetu-core by openlookeng.

the class TimestampOperators method castToTimestampWithTimeZone.

@ScalarOperator(CAST)
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long castToTimestampWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long value) {
    TimeZoneKey timeZoneKey = session.getTimeZoneKey();
    ISOChronology localChronology = getChronology(timeZoneKey);
    // its UTC representation we need to shift the value by the offset of TZ.
    return packDateTimeWithZone(localChronology.getZone().convertLocalToUTC(value, false), timeZoneKey);
}
Also used : ISOChronology(org.joda.time.chrono.ISOChronology) TimeZoneKey(io.prestosql.spi.type.TimeZoneKey) ScalarOperator(io.prestosql.spi.function.ScalarOperator) SqlType(io.prestosql.spi.function.SqlType)

Example 28 with SqlType

use of io.prestosql.spi.function.SqlType in project hetu-core by openlookeng.

the class HyperLogLogOperators method castToP4Hll.

@ScalarOperator(CAST)
@SqlType(StandardTypes.P4_HYPER_LOG_LOG)
public static Slice castToP4Hll(@SqlType(StandardTypes.HYPER_LOG_LOG) Slice slice) {
    HyperLogLog hll = HyperLogLog.newInstance(slice);
    hll.makeDense();
    return hll.serialize();
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) ScalarOperator(io.prestosql.spi.function.ScalarOperator) SqlType(io.prestosql.spi.function.SqlType)

Example 29 with SqlType

use of io.prestosql.spi.function.SqlType in project hetu-core by openlookeng.

the class BenchmarkArrayDistinct method oldArrayDistinct.

@ScalarFunction
@SqlType("array(varchar)")
public static Block oldArrayDistinct(@SqlType("array(varchar)") Block array) {
    if (array.getPositionCount() == 0) {
        return array;
    }
    TypedSet typedSet = new TypedSet(VARCHAR, array.getPositionCount(), "old_array_distinct");
    BlockBuilder distinctElementBlockBuilder = VARCHAR.createBlockBuilder(null, array.getPositionCount());
    for (int i = 0; i < array.getPositionCount(); i++) {
        if (!typedSet.contains(array, i)) {
            typedSet.add(array, i);
            VARCHAR.appendTo(array, i, distinctElementBlockBuilder);
        }
    }
    return distinctElementBlockBuilder.build();
}
Also used : TypedSet(io.prestosql.operator.aggregation.TypedSet) BlockBuilder(io.prestosql.spi.block.BlockBuilder) ScalarFunction(io.prestosql.spi.function.ScalarFunction) SqlType(io.prestosql.spi.function.SqlType)

Example 30 with SqlType

use of io.prestosql.spi.function.SqlType in project hetu-core by openlookeng.

the class BenchmarkArraySort method oldArraySort.

@ScalarFunction
@SqlType("array(varchar)")
public static Block oldArraySort(@SqlType("array(varchar)") Block block) {
    List<Integer> positions = Ints.asList(new int[block.getPositionCount()]);
    for (int i = 0; i < block.getPositionCount(); i++) {
        positions.set(i, i);
    }
    positions.sort((p1, p2) -> {
        // TODO: This could be quite slow, it should use parametric equals
        return VARCHAR.compareTo(block, p1, block, p2);
    });
    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, block.getPositionCount());
    for (int position : positions) {
        VARCHAR.appendTo(block, position, blockBuilder);
    }
    return blockBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) ScalarFunction(io.prestosql.spi.function.ScalarFunction) SqlType(io.prestosql.spi.function.SqlType)

Aggregations

SqlType (io.prestosql.spi.function.SqlType)138 ScalarFunction (io.prestosql.spi.function.ScalarFunction)96 Description (io.prestosql.spi.function.Description)76 SqlNullable (io.prestosql.spi.function.SqlNullable)52 BlockBuilder (io.prestosql.spi.block.BlockBuilder)42 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)40 PrestoException (io.prestosql.spi.PrestoException)27 Slice (io.airlift.slice.Slice)25 LiteralParameters (io.prestosql.spi.function.LiteralParameters)24 TypeParameter (io.prestosql.spi.function.TypeParameter)20 ScalarOperator (io.prestosql.spi.function.ScalarOperator)16 Constraint (io.prestosql.type.Constraint)16 JsonParser (com.fasterxml.jackson.core.JsonParser)15 JsonUtil.createJsonParser (io.prestosql.util.JsonUtil.createJsonParser)15 IOException (java.io.IOException)15 Point (com.esri.core.geometry.Point)14 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)14 MultiPoint (com.esri.core.geometry.MultiPoint)12 Block (io.prestosql.spi.block.Block)9 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)8