Search in sources :

Example 1 with PulsarColumnHandle

use of org.apache.pulsar.sql.presto.PulsarColumnHandle in project pulsar by apache.

the class AbstractDecoderTester method getColumnColumnHandles.

protected List<PulsarColumnHandle> getColumnColumnHandles(TopicName topicName, SchemaInfo schemaInfo, PulsarColumnHandle.HandleKeyValueType handleKeyValueType, boolean includeInternalColumn, PulsarDispatchingRowDecoderFactory dispatchingRowDecoderFactory) {
    List<PulsarColumnHandle> columnHandles = new ArrayList<>();
    List<ColumnMetadata> columnMetadata = pulsarMetadata.getPulsarColumns(topicName, schemaInfo, includeInternalColumn, handleKeyValueType);
    columnMetadata.forEach(column -> {
        PulsarColumnMetadata pulsarColumnMetadata = (PulsarColumnMetadata) column;
        columnHandles.add(new PulsarColumnHandle(pulsarConnectorId.toString(), pulsarColumnMetadata.getNameWithCase(), pulsarColumnMetadata.getType(), pulsarColumnMetadata.isHidden(), pulsarColumnMetadata.isInternal(), pulsarColumnMetadata.getDecoderExtraInfo().getMapping(), pulsarColumnMetadata.getDecoderExtraInfo().getDataFormat(), pulsarColumnMetadata.getDecoderExtraInfo().getFormatHint(), pulsarColumnMetadata.getHandleKeyValueType()));
    });
    return columnHandles;
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata) ArrayList(java.util.ArrayList) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata)

Example 2 with PulsarColumnHandle

use of org.apache.pulsar.sql.presto.PulsarColumnHandle 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)

Example 3 with PulsarColumnHandle

use of org.apache.pulsar.sql.presto.PulsarColumnHandle in project pulsar by apache.

the class TestAvroDecoder method testMap.

@Test
public void testMap() {
    DecoderTestMessage message = new DecoderTestMessage();
    message.mapField = new HashMap<String, Long>() {

        {
            put("key1", 2L);
            put("key2", 22L);
        }
    };
    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("mapField");
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
    Type columnType = decoderFactory.getTypeManager().getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(VarcharType.VARCHAR.getTypeSignature()), TypeSignatureParameter.typeParameter(BigintType.BIGINT.getTypeSignature())));
    PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "mapField", columnType, false, false, "mapField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
    checkMapValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
Also used : FieldValueProvider(io.prestosql.decoder.FieldValueProvider) ByteBuf(io.netty.buffer.ByteBuf) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) BigintType(io.prestosql.spi.type.BigintType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) VarcharType(io.prestosql.spi.type.VarcharType) GenericAvroRecord(org.apache.pulsar.client.impl.schema.generic.GenericAvroRecord) DecoderTestMessage(org.apache.pulsar.sql.presto.decoder.DecoderTestMessage) Test(org.testng.annotations.Test)

Example 4 with PulsarColumnHandle

use of org.apache.pulsar.sql.presto.PulsarColumnHandle in project pulsar by apache.

the class TestAvroDecoder method testArray.

@Test
public void testArray() {
    DecoderTestMessage message = new DecoderTestMessage();
    message.arrayField = Arrays.asList("message_1", "message_2", "message_3");
    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("arrayField");
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
    ArrayType columnType = new ArrayType(VARCHAR);
    PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "arrayField", columnType, false, false, "arrayField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
    checkArrayValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) GenericAvroRecord(org.apache.pulsar.client.impl.schema.generic.GenericAvroRecord) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) ByteBuf(io.netty.buffer.ByteBuf) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) DecoderTestMessage(org.apache.pulsar.sql.presto.decoder.DecoderTestMessage) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) Test(org.testng.annotations.Test)

Example 5 with PulsarColumnHandle

use of org.apache.pulsar.sql.presto.PulsarColumnHandle in project pulsar by apache.

the class TestJsonDecoder 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);
    GenericJsonRecord genericRecord = (GenericJsonRecord) GenericJsonSchema.of(schemaInfo).decode(bytes);
    Object fieldValue = genericRecord.getJsonNode().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) ByteBuf(io.netty.buffer.ByteBuf) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) GenericJsonRecord(org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord) DecoderTestMessage(org.apache.pulsar.sql.presto.decoder.DecoderTestMessage) Test(org.testng.annotations.Test)

Aggregations

PulsarColumnHandle (org.apache.pulsar.sql.presto.PulsarColumnHandle)16 DecoderColumnHandle (io.prestosql.decoder.DecoderColumnHandle)15 FieldValueProvider (io.prestosql.decoder.FieldValueProvider)15 Test (org.testng.annotations.Test)15 ByteBuf (io.netty.buffer.ByteBuf)14 DecoderTestMessage (org.apache.pulsar.sql.presto.decoder.DecoderTestMessage)10 ArrayType (io.prestosql.spi.type.ArrayType)6 RowType (io.prestosql.spi.type.RowType)5 GenericAvroRecord (org.apache.pulsar.client.impl.schema.generic.GenericAvroRecord)4 GenericJsonRecord (org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord)4 GenericProtobufNativeRecord (org.apache.pulsar.client.impl.schema.generic.GenericProtobufNativeRecord)3 ImmutableList (com.google.common.collect.ImmutableList)2 Type (io.prestosql.spi.type.Type)2 LocalDate (java.time.LocalDate)2 LocalTime (java.time.LocalTime)2 Timestamp (com.google.protobuf.Timestamp)1 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)1 BigintType (io.prestosql.spi.type.BigintType)1 VarcharType (io.prestosql.spi.type.VarcharType)1 Time (java.sql.Time)1