Search in sources :

Example 1 with RowDecoder

use of io.trino.decoder.RowDecoder in project trino by trinodb.

the class TestJsonDecoder method testSimple.

@Test
public void testSimple() throws Exception {
    byte[] json = ByteStreams.toByteArray(TestJsonDecoder.class.getResourceAsStream("/decoder/json/message.json"));
    DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(100), "source", null, null, false, false, false);
    DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", createVarcharType(10), "user/screen_name", null, null, false, false, false);
    DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", BIGINT, "id", null, null, false, false, false);
    DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(3, "column4", BIGINT, "user/statuses_count", null, null, false, false, false);
    DecoderTestColumnHandle column5 = new DecoderTestColumnHandle(4, "column5", BOOLEAN, "user/geo_enabled", null, null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4, column5);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(json).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkValue(decodedRow, column1, "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>");
    checkValue(decodedRow, column2, "EKentuckyN");
    checkValue(decodedRow, column3, 493857959588286460L);
    checkValue(decodedRow, column4, 7630);
    checkValue(decodedRow, column5, true);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) RowDecoder(io.trino.decoder.RowDecoder) Test(org.testng.annotations.Test)

Example 2 with RowDecoder

use of io.trino.decoder.RowDecoder in project trino by trinodb.

the class TestRawDecoder method testFloatStuff.

@SuppressWarnings("NumericCastThatLosesPrecision")
@Test
public void testFloatStuff() {
    ByteBuffer buf = ByteBuffer.allocate(20);
    buf.putDouble(Math.PI);
    buf.putFloat((float) Math.E);
    buf.putDouble(Math.E);
    byte[] row = new byte[buf.position()];
    System.arraycopy(buf.array(), 0, row, 0, buf.position());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", DOUBLE, null, "DOUBLE", null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", DOUBLE, "8", "FLOAT", null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkValue(decodedRow, row1, Math.PI);
    checkValue(decodedRow, row2, Math.E);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) RowDecoder(io.trino.decoder.RowDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 3 with RowDecoder

use of io.trino.decoder.RowDecoder in project trino by trinodb.

the class TestRawDecoder method testSimple.

@Test
public void testSimple() {
    ByteBuffer buf = ByteBuffer.allocate(36);
    // 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).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.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) RowDecoder(io.trino.decoder.RowDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 4 with RowDecoder

use of io.trino.decoder.RowDecoder in project trino by trinodb.

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).orElseThrow(AssertionError::new);
    checkIsNull(decodedRow, column);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) RowDecoder(io.trino.decoder.RowDecoder) Test(org.testng.annotations.Test)

Example 5 with RowDecoder

use of io.trino.decoder.RowDecoder in project trino by trinodb.

the class TestCsvDecoder method fieldValueDecoderFor.

private FieldValueProvider fieldValueDecoderFor(BigintType type, String csv) {
    DecoderTestColumnHandle column = new DecoderTestColumnHandle(0, "column", type, "0", null, null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(column);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8)).orElseThrow(AssertionError::new);
    return decodedRow.get(column);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) RowDecoder(io.trino.decoder.RowDecoder)

Aggregations

RowDecoder (io.trino.decoder.RowDecoder)20 DecoderColumnHandle (io.trino.decoder.DecoderColumnHandle)17 DecoderTestColumnHandle (io.trino.decoder.DecoderTestColumnHandle)15 Test (org.testng.annotations.Test)15 FieldValueProvider (io.trino.decoder.FieldValueProvider)14 ByteBuffer (java.nio.ByteBuffer)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 DispatchingRowDecoderFactory (io.trino.decoder.DispatchingRowDecoderFactory)3 ColumnHandle (io.trino.spi.connector.ColumnHandle)3 ConnectorRecordSetProvider (io.trino.spi.connector.ConnectorRecordSetProvider)3 ConnectorSession (io.trino.spi.connector.ConnectorSession)3 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)3 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)3 RecordSet (io.trino.spi.connector.RecordSet)3 Collections.emptyMap (java.util.Collections.emptyMap)3 List (java.util.List)3 Map (java.util.Map)3 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)2