use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class TestField method testArray.
@Test
public void testArray() throws Exception {
Type type = new ArrayType(VARCHAR);
Block expected = AccumuloRowSerializer.getBlockFromArray(VARCHAR, ImmutableList.of("a", "b", "c"));
Field f1 = new Field(expected, type);
assertEquals(f1.getArray(), expected);
assertEquals(f1.getObject(), expected);
assertEquals(f1.getType(), type);
assertEquals(f1.toString(), "ARRAY ['a','b','c']");
Field f2 = new Field(f1);
assertEquals(f2, f1);
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class TestSerDeUtils method testListBlock.
@Test
public void testListBlock() {
List<InnerStruct> array = new ArrayList<>(2);
array.add(new InnerStruct(8, 9L));
array.add(new InnerStruct(10, 11L));
ListHolder listHolder = new ListHolder();
listHolder.array = array;
com.facebook.presto.spi.type.Type rowType = new RowType(ImmutableList.of(INTEGER, BIGINT), Optional.empty());
com.facebook.presto.spi.type.Type arrayOfRowType = new RowType(ImmutableList.of(new ArrayType(rowType)), Optional.empty());
Block actual = toBinaryBlock(arrayOfRowType, listHolder, getInspector(ListHolder.class));
BlockBuilder blockBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), 1024);
rowType.writeObject(blockBuilder, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 8, 9L));
rowType.writeObject(blockBuilder, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 10, 11L));
Block expected = rowBlockOf(ImmutableList.of(new ArrayType(rowType)), blockBuilder.build());
assertBlockEquals(actual, expected);
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class AbstractMinMaxByNAggregationFunction method output.
public static void output(ArrayType outputType, MinMaxByNState state, BlockBuilder out) {
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null || heap.isEmpty()) {
out.appendNull();
return;
}
Type elementType = outputType.getElementType();
BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), heap.getCapacity());
long startSize = heap.getEstimatedSize();
heap.popAll(reversedBlockBuilder);
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) {
elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder);
}
out.closeEntry();
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class AbstractMinMaxByNAggregationFunction method generateAggregation.
protected InternalAggregationFunction generateAggregation(Type valueType, Type keyType) {
DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxNAggregationFunction.class.getClassLoader());
BlockComparator comparator = typeToComparator.apply(keyType);
List<Type> inputTypes = ImmutableList.of(valueType, keyType, BIGINT);
MinMaxByNStateSerializer stateSerializer = new MinMaxByNStateSerializer(comparator, keyType, valueType);
Type intermediateType = stateSerializer.getSerializedType();
ArrayType outputType = new ArrayType(valueType);
List<AggregationMetadata.ParameterMetadata> inputParameterMetadata = ImmutableList.of(new AggregationMetadata.ParameterMetadata(STATE), new AggregationMetadata.ParameterMetadata(NULLABLE_BLOCK_INPUT_CHANNEL, valueType), new AggregationMetadata.ParameterMetadata(BLOCK_INPUT_CHANNEL, keyType), new AggregationMetadata.ParameterMetadata(BLOCK_INDEX), new AggregationMetadata.ParameterMetadata(INPUT_CHANNEL, BIGINT));
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(name, valueType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, INPUT_FUNCTION.bindTo(comparator).bindTo(valueType).bindTo(keyType), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(outputType), MinMaxByNState.class, stateSerializer, new MinMaxByNStateFactory(), outputType);
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(name, inputTypes, intermediateType, outputType, true, factory);
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class AbstractMinMaxNAggregationFunction method output.
public static void output(ArrayType outputType, MinMaxNState state, BlockBuilder out) {
TypedHeap heap = state.getTypedHeap();
if (heap == null || heap.isEmpty()) {
out.appendNull();
return;
}
Type elementType = outputType.getElementType();
BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), heap.getCapacity());
long startSize = heap.getEstimatedSize();
heap.popAll(reversedBlockBuilder);
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) {
elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder);
}
out.closeEntry();
}
Aggregations