Search in sources :

Example 21 with RowType

use of io.prestosql.spi.type.RowType in project hetu-core by openlookeng.

the class TestMapAggAggregation method testDoubleRowMap.

@Test
public void testDoubleRowMap() {
    RowType innerRowType = RowType.from(ImmutableList.of(RowType.field("f1", INTEGER), RowType.field("f2", DOUBLE)));
    MapType mapType = mapType(DOUBLE, innerRowType);
    InternalAggregationFunction aggFunc = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction(NAME), AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE), innerRowType.getTypeSignature()));
    BlockBuilder builder = innerRowType.createBlockBuilder(null, 3);
    innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 1L, 1.0));
    innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 2L, 2.0));
    innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 3L, 3.0));
    assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableList.of(1, 1.0), 2.0, ImmutableList.of(2, 2.0), 3.0, ImmutableList.of(3, 3.0)), createDoublesBlock(1.0, 2.0, 3.0), builder.build());
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) RowType(io.prestosql.spi.type.RowType) MapType(io.prestosql.spi.type.MapType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 22 with RowType

use of io.prestosql.spi.type.RowType in project pulsar by apache.

the class PulsarJsonFieldDecoder method isSupportedType.

private boolean isSupportedType(Type type) {
    if (isVarcharType(type)) {
        return true;
    }
    if (ImmutableList.of(BIGINT, INTEGER, SMALLINT, TINYINT, BOOLEAN, DOUBLE, TIMESTAMP, DATE, TIME, REAL).contains(type)) {
        return true;
    }
    if (type instanceof ArrayType) {
        checkArgument(type.getTypeParameters().size() == 1, "expecting exactly one type parameter for array");
        return isSupportedType(type.getTypeParameters().get(0));
    }
    if (type instanceof MapType) {
        List<Type> typeParameters = type.getTypeParameters();
        checkArgument(typeParameters.size() == 2, "expecting exactly two type parameters for map");
        return isSupportedType(type.getTypeParameters().get(0)) && isSupportedType(type.getTypeParameters().get(1));
    }
    if (type instanceof RowType) {
        for (Type fieldType : type.getTypeParameters()) {
            if (!isSupportedType(fieldType)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) RealType(io.prestosql.spi.type.RealType) ArrayType(io.prestosql.spi.type.ArrayType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TimestampType(io.prestosql.spi.type.TimestampType) BigintType(io.prestosql.spi.type.BigintType) MapType(io.prestosql.spi.type.MapType) DoubleType(io.prestosql.spi.type.DoubleType) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) TimeType(io.prestosql.spi.type.TimeType) TinyintType(io.prestosql.spi.type.TinyintType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) RowType(io.prestosql.spi.type.RowType) MapType(io.prestosql.spi.type.MapType)

Example 23 with RowType

use of io.prestosql.spi.type.RowType in project pulsar by apache.

the class PulsarProtobufNativeColumnDecoder method isSupportedType.

private static boolean isSupportedType(Type type) {
    if (isSupportedPrimitive(type)) {
        return true;
    }
    if (type instanceof ArrayType) {
        checkArgument(type.getTypeParameters().size() == 1, "expecting exactly one type parameter for array");
        return isSupportedType(type.getTypeParameters().get(0));
    }
    if (type instanceof MapType) {
        List<Type> typeParameters = type.getTypeParameters();
        checkArgument(typeParameters.size() == 2, "expecting exactly two type parameters for map");
        return isSupportedType(typeParameters.get(1)) && isSupportedType(typeParameters.get(0));
    }
    if (type instanceof RowType) {
        for (Type fieldType : type.getTypeParameters()) {
            if (!isSupportedType(fieldType)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BigintType(io.prestosql.spi.type.BigintType) MapType(io.prestosql.spi.type.MapType) DoubleType(io.prestosql.spi.type.DoubleType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) RealType(io.prestosql.spi.type.RealType) ArrayType(io.prestosql.spi.type.ArrayType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TinyintType(io.prestosql.spi.type.TinyintType) TimestampType(io.prestosql.spi.type.TimestampType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) RowType(io.prestosql.spi.type.RowType) MapType(io.prestosql.spi.type.MapType)

Example 24 with RowType

use of io.prestosql.spi.type.RowType in project pulsar by apache.

the class PulsarProtobufNativeColumnDecoder method serializeRow.

private static Block serializeRow(BlockBuilder parentBlockBuilder, Object value, Type type, String columnName) {
    if (value == null) {
        checkState(parentBlockBuilder != null, "parent block builder is null");
        parentBlockBuilder.appendNull();
        return null;
    }
    BlockBuilder blockBuilder;
    if (parentBlockBuilder != null) {
        blockBuilder = parentBlockBuilder;
    } else {
        blockBuilder = type.createBlockBuilder(null, 1);
    }
    BlockBuilder singleRowBuilder = blockBuilder.beginBlockEntry();
    checkState(value instanceof DynamicMessage, "Row Field value should be DynamicMessage type.");
    DynamicMessage record = (DynamicMessage) value;
    List<Field> fields = ((RowType) type).getFields();
    for (Field field : fields) {
        checkState(field.getName().isPresent(), "field name not found");
        serializeObject(singleRowBuilder, record.getField(((DynamicMessage) value).getDescriptorForType().findFieldByName(field.getName().get())), field.getType(), columnName);
    }
    blockBuilder.closeEntry();
    if (parentBlockBuilder == null) {
        return blockBuilder.getObject(0, Block.class);
    }
    return null;
}
Also used : Field(io.prestosql.spi.type.RowType.Field) RowType(io.prestosql.spi.type.RowType) DynamicMessage(com.google.protobuf.DynamicMessage) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 25 with RowType

use of io.prestosql.spi.type.RowType in project pulsar by apache.

the class TestAvroDecoder method testRow.

@Test
public void testRow() {
    DecoderTestMessage message = new DecoderTestMessage();
    message.stringField = "message_2";
    DecoderTestMessage.TestRow testRow = new DecoderTestMessage.TestRow();
    message.rowField = testRow;
    testRow.intField = 22;
    testRow.stringField = "message_2_testRow";
    DecoderTestMessage.NestedRow nestedRow = new DecoderTestMessage.NestedRow();
    nestedRow.longField = 222L;
    nestedRow.stringField = "message_2_nestedRow";
    testRow.nestedRow = nestedRow;
    byte[] bytes = schema.encode(message);
    ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(bytes);
    GenericAvroRecord genericRecord = (GenericAvroRecord) GenericAvroSchema.of(schemaInfo).decode(bytes);
    Object fieldValue = genericRecord.getAvroRecord().get("rowField");
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
    RowType columnType = RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("intField", INTEGER)).add(RowType.field("nestedRow", RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("longField", BIGINT)).add(RowType.field("stringField", VARCHAR)).build()))).add(RowType.field("stringField", VARCHAR)).build());
    PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "rowField", columnType, false, false, "rowField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
    checkRowValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
Also used : FieldValueProvider(io.prestosql.decoder.FieldValueProvider) RowType(io.prestosql.spi.type.RowType) ByteBuf(io.netty.buffer.ByteBuf) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) GenericAvroRecord(org.apache.pulsar.client.impl.schema.generic.GenericAvroRecord) DecoderTestMessage(org.apache.pulsar.sql.presto.decoder.DecoderTestMessage) Test(org.testng.annotations.Test)

Aggregations

RowType (io.prestosql.spi.type.RowType)76 ArrayType (io.prestosql.spi.type.ArrayType)38 Type (io.prestosql.spi.type.Type)35 MapType (io.prestosql.spi.type.MapType)29 Test (org.testng.annotations.Test)25 List (java.util.List)19 ImmutableList (com.google.common.collect.ImmutableList)18 VarcharType (io.prestosql.spi.type.VarcharType)17 Block (io.prestosql.spi.block.Block)16 BlockBuilder (io.prestosql.spi.block.BlockBuilder)15 Map (java.util.Map)12 BigintType (io.prestosql.spi.type.BigintType)11 DecimalType (io.prestosql.spi.type.DecimalType)11 DoubleType (io.prestosql.spi.type.DoubleType)11 BooleanType (io.prestosql.spi.type.BooleanType)10 IntegerType (io.prestosql.spi.type.IntegerType)10 RealType (io.prestosql.spi.type.RealType)10 SmallintType (io.prestosql.spi.type.SmallintType)10 TimestampType (io.prestosql.spi.type.TimestampType)10 VarbinaryType (io.prestosql.spi.type.VarbinaryType)10