Search in sources :

Example 56 with ArrayType

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);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) Block(com.facebook.presto.spi.block.Block) Test(org.testng.annotations.Test)

Example 57 with ArrayType

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);
}
Also used : ArrayList(java.util.ArrayList) RowType(com.facebook.presto.type.RowType) ArrayType(com.facebook.presto.type.ArrayType) Block(com.facebook.presto.spi.block.Block) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 58 with ArrayType

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();
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Type(com.facebook.presto.spi.type.Type) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 59 with ArrayType

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);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) MinMaxByNStateSerializer(com.facebook.presto.operator.aggregation.state.MinMaxByNStateSerializer) MinMaxByNStateFactory(com.facebook.presto.operator.aggregation.state.MinMaxByNStateFactory) ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) Type(com.facebook.presto.spi.type.Type)

Example 60 with ArrayType

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();
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Type(com.facebook.presto.spi.type.Type) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

ArrayType (com.facebook.presto.type.ArrayType)71 Test (org.testng.annotations.Test)45 MapType (com.facebook.presto.type.MapType)27 Type (com.facebook.presto.spi.type.Type)26 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)15 Block (com.facebook.presto.spi.block.Block)13 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)13 RowType (com.facebook.presto.type.RowType)12 ImmutableList (com.google.common.collect.ImmutableList)11 Signature (com.facebook.presto.metadata.Signature)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)6 MetadataManager (com.facebook.presto.metadata.MetadataManager)6 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)5 Page (com.facebook.presto.spi.Page)5 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4