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);
}
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);
}
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();
}
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();
}
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();
}
Aggregations