Search in sources :

Example 1 with DecoderColumnHandle

use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.

the class TestRawDecoder method testFixedWithString.

@Test
public void testFixedWithString() {
    String str = "Ich bin zwei Oeltanks";
    byte[] row = str.getBytes(StandardCharsets.UTF_8);
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(100), null, null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", createVarcharType(100), "0", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", createVarcharType(100), "0:4", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", createVarcharType(100), "5:8", null, null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row, null).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkValue(decodedRow, row1, str);
    checkValue(decodedRow, row2, str);
    // these only work for single byte encodings...
    checkValue(decodedRow, row3, str.substring(0, 4));
    checkValue(decodedRow, row4, str.substring(5, 8));
}
Also used : DecoderTestColumnHandle(io.prestosql.decoder.DecoderTestColumnHandle) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) RowDecoder(io.prestosql.decoder.RowDecoder) Test(org.testng.annotations.Test)

Example 2 with DecoderColumnHandle

use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.

the class TestRawDecoder method testEmptyRecord.

@Test
public void testEmptyRecord() {
    byte[] emptyRow = new byte[0];
    DecoderTestColumnHandle column = new DecoderTestColumnHandle(0, "row1", createUnboundedVarcharType(), null, "BYTE", null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(column);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(emptyRow, null).orElseThrow(AssertionError::new);
    checkIsNull(decodedRow, column);
}
Also used : DecoderTestColumnHandle(io.prestosql.decoder.DecoderTestColumnHandle) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) RowDecoder(io.prestosql.decoder.RowDecoder) Test(org.testng.annotations.Test)

Example 3 with DecoderColumnHandle

use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.

the class TestRawDecoder method testSimple.

@Test
public void testSimple() {
    ByteBuffer buf = ByteBuffer.allocate(100);
    // 0 - 7
    buf.putLong(4815162342L);
    // 8 - 11
    buf.putInt(12345678);
    // 12 - 13
    buf.putShort((short) 4567);
    // 14
    buf.put((byte) 123);
    // 15+
    buf.put("Ich bin zwei Oeltanks".getBytes(StandardCharsets.UTF_8));
    byte[] row = new byte[buf.position()];
    System.arraycopy(buf.array(), 0, row, 0, buf.position());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", BigintType.BIGINT, "0", "LONG", null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", BigintType.BIGINT, "8", "INT", null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", BigintType.BIGINT, "12", "SHORT", null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BigintType.BIGINT, "14", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle(4, "row5", createVarcharType(10), "15", null, null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row, null).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkValue(decodedRow, row1, 4815162342L);
    checkValue(decodedRow, row2, 12345678);
    checkValue(decodedRow, row3, 4567);
    checkValue(decodedRow, row4, 123);
    checkValue(decodedRow, row5, "Ich bin zw");
}
Also used : DecoderTestColumnHandle(io.prestosql.decoder.DecoderTestColumnHandle) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) RowDecoder(io.prestosql.decoder.RowDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 4 with DecoderColumnHandle

use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.

the class TestAvroDecoder method testSchemaEvolutionIntToDouble.

@Test
public void testSchemaEvolutionIntToDouble() throws Exception {
    byte[] originalIntData = buildAvroData(new Schema.Parser().parse(getAvroSchema("int_to_double_field", "\"int\"")), "int_to_double_field", 100);
    DecoderTestColumnHandle doubleColumnReadingIntData = new DecoderTestColumnHandle(0, "row0", DOUBLE, "int_to_double_field", null, null, false, false, false);
    String changedTypeSchema = getAvroSchema("int_to_double_field", "\"double\"");
    Map<DecoderColumnHandle, FieldValueProvider> decodedEvolvedRow = decodeRow(originalIntData, ImmutableSet.of(doubleColumnReadingIntData), ImmutableMap.of(DATA_SCHEMA, changedTypeSchema));
    assertEquals(decodedEvolvedRow.size(), 1);
    checkValue(decodedEvolvedRow, doubleColumnReadingIntData, 100.0);
}
Also used : DecoderTestColumnHandle(io.prestosql.decoder.DecoderTestColumnHandle) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 5 with DecoderColumnHandle

use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.

the class TestAvroDecoder method testRuntimeDecodingFailure.

@Test
public void testRuntimeDecodingFailure() {
    DecoderTestColumnHandle booleanColumn = new DecoderTestColumnHandle(0, "some_column", BOOLEAN, "long_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(booleanColumn, "long_field", "\"long\"", (long) 1);
    assertThatThrownBy(decodedRow.get(booleanColumn)::getBoolean).isInstanceOf(PrestoException.class).hasMessageMatching("cannot decode object of 'class java.lang.Long' as 'boolean' for column 'some_column'");
}
Also used : DecoderTestColumnHandle(io.prestosql.decoder.DecoderTestColumnHandle) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) PrestoException(io.prestosql.spi.PrestoException) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Aggregations

DecoderColumnHandle (io.prestosql.decoder.DecoderColumnHandle)52 FieldValueProvider (io.prestosql.decoder.FieldValueProvider)51 Test (org.testng.annotations.Test)46 DecoderTestColumnHandle (io.prestosql.decoder.DecoderTestColumnHandle)33 ByteBuf (io.netty.buffer.ByteBuf)15 PulsarColumnHandle (org.apache.pulsar.sql.presto.PulsarColumnHandle)15 RowDecoder (io.prestosql.decoder.RowDecoder)14 DecoderTestMessage (org.apache.pulsar.sql.presto.decoder.DecoderTestMessage)10 ArrayType (io.prestosql.spi.type.ArrayType)8 HashMap (java.util.HashMap)6 RowType (io.prestosql.spi.type.RowType)5 Type (io.prestosql.spi.type.Type)5 Map (java.util.Map)5 GenericJsonRecord (org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord)5 ByteBuffer (java.nio.ByteBuffer)3 GenericAvroRecord (org.apache.pulsar.client.impl.schema.generic.GenericAvroRecord)3 GenericProtobufNativeRecord (org.apache.pulsar.client.impl.schema.generic.GenericProtobufNativeRecord)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ImmutableList (com.google.common.collect.ImmutableList)2 Slice (io.airlift.slice.Slice)2