Search in sources :

Example 21 with ByteArrayDataOutput

use of com.google.common.io.ByteArrayDataOutput in project druid by druid-io.

the class DatasourceInputSplitTest method testSerde.

@Test
public void testSerde() throws Exception {
    Interval interval = Interval.parse("2000/3000");
    DatasourceInputSplit expected = new DatasourceInputSplit(Lists.newArrayList(new WindowedDataSegment(new DataSegment("test", Interval.parse("2000/3000"), "ver", ImmutableMap.<String, Object>of("type", "local", "path", "/tmp/index.zip"), ImmutableList.of("host"), ImmutableList.of("visited_sum", "unique_hosts"), NoneShardSpec.instance(), 9, 12334), interval)), new String[] { "server1", "server2", "server3" });
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    expected.write(out);
    DataInput in = ByteStreams.newDataInput(out.toByteArray());
    DatasourceInputSplit actual = new DatasourceInputSplit();
    actual.readFields(in);
    Assert.assertEquals(expected.getSegments(), actual.getSegments());
    Assert.assertArrayEquals(expected.getLocations(), actual.getLocations());
    Assert.assertEquals(12334, actual.getLength());
}
Also used : DataInput(java.io.DataInput) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 22 with ByteArrayDataOutput

use of com.google.common.io.ByteArrayDataOutput in project presto by prestodb.

the class RaptorTableIdentity method serialize.

@Override
public byte[] serialize() {
    ByteArrayDataOutput output = newDataOutput(SERIALIZED_SIZE);
    output.write(CURRENT_VERSION);
    output.writeLong(tableId);
    return output.toByteArray();
}
Also used : ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput)

Example 23 with ByteArrayDataOutput

use of com.google.common.io.ByteArrayDataOutput in project presto by prestodb.

the class TestRaptorMetadata method testColumnIdentity.

@Test
public void testColumnIdentity() throws Exception {
    // Test ColumnIdentity round trip.
    metadata.createTable(SESSION, getOrdersTable());
    ConnectorTableHandle connectorTableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, connectorTableHandle);
    ColumnIdentity orderKeyColumnIdentity = metadata.getColumnIdentity(columnHandles.get("orderkey"));
    byte[] bytes = orderKeyColumnIdentity.serialize();
    assertEquals(orderKeyColumnIdentity, metadata.deserializeColumnIdentity(bytes));
    // Test one hard coded serialized data for each version.
    byte version = 1;
    long columnId = 123456789012L;
    ByteArrayDataOutput dataOutput = newDataOutput();
    dataOutput.writeByte(version);
    dataOutput.writeLong(columnId);
    byte[] testBytes = dataOutput.toByteArray();
    ColumnIdentity testColumnIdentity = metadata.deserializeColumnIdentity(testBytes);
    assertEquals(testColumnIdentity, new RaptorColumnIdentity(columnId));
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) RaptorColumnIdentity(com.facebook.presto.raptor.RaptorColumnIdentity) RaptorColumnIdentity(com.facebook.presto.raptor.RaptorColumnIdentity) ColumnIdentity(com.facebook.presto.spi.ColumnIdentity) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 24 with ByteArrayDataOutput

use of com.google.common.io.ByteArrayDataOutput in project presto by prestodb.

the class TestRaptorMetadata method testTableIdentity.

@Test
public void testTableIdentity() throws Exception {
    // Test TableIdentity round trip.
    metadata.createTable(SESSION, getOrdersTable());
    ConnectorTableHandle connectorTableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    TableIdentity tableIdentity = metadata.getTableIdentity(connectorTableHandle);
    byte[] bytes = tableIdentity.serialize();
    assertEquals(tableIdentity, metadata.deserializeTableIdentity(bytes));
    // Test one hard coded serialized data for each version.
    byte version = 1;
    long tableId = 12345678L;
    ByteArrayDataOutput dataOutput = newDataOutput();
    dataOutput.writeByte(version);
    dataOutput.writeLong(tableId);
    byte[] testBytes = dataOutput.toByteArray();
    TableIdentity testTableIdentity = metadata.deserializeTableIdentity(testBytes);
    assertEquals(testTableIdentity, new RaptorTableIdentity(tableId));
}
Also used : RaptorTableIdentity(com.facebook.presto.raptor.RaptorTableIdentity) TableIdentity(com.facebook.presto.spi.TableIdentity) RaptorTableIdentity(com.facebook.presto.raptor.RaptorTableIdentity) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 25 with ByteArrayDataOutput

use of com.google.common.io.ByteArrayDataOutput in project presto by prestodb.

the class WrappedRange method toBytes.

@JsonValue
public byte[] toBytes() throws IOException {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    range.write(out);
    return out.toByteArray();
}
Also used : ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) JsonValue(com.fasterxml.jackson.annotation.JsonValue)

Aggregations

ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)39 IOException (java.io.IOException)3 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)2 Test (org.testng.annotations.Test)2 Split (co.cask.cdap.api.data.batch.Split)1 RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)1 RaptorColumnIdentity (com.facebook.presto.raptor.RaptorColumnIdentity)1 RaptorTableIdentity (com.facebook.presto.raptor.RaptorTableIdentity)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ColumnIdentity (com.facebook.presto.spi.ColumnIdentity)1 TableIdentity (com.facebook.presto.spi.TableIdentity)1 JsonValue (com.fasterxml.jackson.annotation.JsonValue)1 Supplier (com.google.common.base.Supplier)1 ByteString (com.google.protobuf.ByteString)1 ServiceException (com.google.protobuf.ServiceException)1 InputRow (io.druid.data.input.InputRow)1 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)1 ParseException (io.druid.java.util.common.parsers.ParseException)1 Aggregator (io.druid.query.aggregation.Aggregator)1 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)1