use of io.trino.spi.function.TypeParameter in project trino by trinodb.
the class ArrayFilterFunction method filterObject.
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = Object.class)
@SqlType("array(T)")
public static Block filterObject(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") ObjectToBooleanFunction function) {
int positionCount = arrayBlock.getPositionCount();
BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
Object input = null;
if (!arrayBlock.isNull(position)) {
input = elementType.getObject(arrayBlock, position);
}
Boolean keep = function.apply(input);
if (TRUE.equals(keep)) {
elementType.appendTo(arrayBlock, position, resultBuilder);
}
}
return resultBuilder.build();
}
use of io.trino.spi.function.TypeParameter in project trino by trinodb.
the class ArrayFilterFunction method filterBoolean.
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class)
@SqlType("array(T)")
public static Block filterBoolean(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") BooleanToBooleanFunction function) {
int positionCount = arrayBlock.getPositionCount();
BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
Boolean input = null;
if (!arrayBlock.isNull(position)) {
input = elementType.getBoolean(arrayBlock, position);
}
Boolean keep = function.apply(input);
if (TRUE.equals(keep)) {
elementType.appendTo(arrayBlock, position, resultBuilder);
}
}
return resultBuilder.build();
}
use of io.trino.spi.function.TypeParameter in project trino by trinodb.
the class RepeatFunction method repeat.
@TypeParameter("T")
@SqlType("array(T)")
public static Block repeat(@TypeParameter("T") Type type, @SqlNullable @SqlType("T") Object element, @SqlType(StandardTypes.INTEGER) long count) {
BlockBuilder blockBuilder = createBlockBuilder(type, count);
if (element == null) {
return repeatNullValues(blockBuilder, count);
}
if (count > 0) {
type.writeObject(blockBuilder, element);
checkMaxSize(blockBuilder.getSizeInBytes(), count);
}
for (int i = 1; i < count; i++) {
type.writeObject(blockBuilder, element);
}
return blockBuilder.build();
}
use of io.trino.spi.function.TypeParameter in project trino by trinodb.
the class ApproximateSetGenericAggregation method input.
@InputFunction
@TypeParameter("T")
public static void input(@OperatorDependency(operator = XX_HASH_64, argumentTypes = "T", convention = @Convention(arguments = NEVER_NULL, result = FAIL_ON_NULL)) MethodHandle methodHandle, @AggregationState HyperLogLogState state, @SqlType("T") long value) {
HyperLogLog hll = getOrCreateHyperLogLog(state);
state.addMemoryUsage(-hll.estimatedInMemorySize());
long hash;
try {
hash = (long) methodHandle.invoke(value);
} catch (Throwable t) {
throw internalError(t);
}
hll.addHash(hash);
state.addMemoryUsage(hll.estimatedInMemorySize());
}
use of io.trino.spi.function.TypeParameter in project trino by trinodb.
the class ApproximateSetGenericAggregation method input.
@InputFunction
@TypeParameter("T")
public static void input(@OperatorDependency(operator = XX_HASH_64, argumentTypes = "T", convention = @Convention(arguments = NEVER_NULL, result = FAIL_ON_NULL)) MethodHandle methodHandle, @AggregationState HyperLogLogState state, @SqlType("T") double value) {
HyperLogLog hll = getOrCreateHyperLogLog(state);
state.addMemoryUsage(-hll.estimatedInMemorySize());
long hash;
try {
hash = (long) methodHandle.invoke(value);
} catch (Throwable t) {
throw internalError(t);
}
hll.addHash(hash);
state.addMemoryUsage(hll.estimatedInMemorySize());
}
Aggregations