Search in sources :

Example 1 with TypeDeserializer

use of io.trino.plugin.base.TypeDeserializer in project trino by trinodb.

the class TestCassandraColumnHandle method setup.

@BeforeClass
public void setup() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(TESTING_TYPE_MANAGER)));
    codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(CassandraColumnHandle.class);
}
Also used : Type(io.trino.spi.type.Type) TypeDeserializer(io.trino.plugin.base.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with TypeDeserializer

use of io.trino.plugin.base.TypeDeserializer in project trino by trinodb.

the class TestHiveSplit method testJsonRoundTrip.

@Test
public void testJsonRoundTrip() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TestingTypeManager())));
    JsonCodec<HiveSplit> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveSplit.class);
    Properties schema = new Properties();
    schema.setProperty("foo", "bar");
    schema.setProperty("bar", "baz");
    ImmutableList<HivePartitionKey> partitionKeys = ImmutableList.of(new HivePartitionKey("a", "apple"), new HivePartitionKey("b", "42"));
    ImmutableList<HostAddress> addresses = ImmutableList.of(HostAddress.fromParts("127.0.0.1", 44), HostAddress.fromParts("127.0.0.1", 45));
    AcidInfo.Builder acidInfoBuilder = AcidInfo.builder(new Path("file:///data/fullacid"));
    acidInfoBuilder.addDeleteDelta(new Path("file:///data/fullacid/delete_delta_0000004_0000004_0000"));
    acidInfoBuilder.addDeleteDelta(new Path("file:///data/fullacid/delete_delta_0000007_0000007_0000"));
    AcidInfo acidInfo = acidInfoBuilder.build().get();
    HiveSplit expected = new HiveSplit("db", "table", "partitionId", "path", 42, 87, 88, Instant.now().toEpochMilli(), schema, partitionKeys, addresses, OptionalInt.empty(), 0, true, TableToPartitionMapping.mapColumnsByIndex(ImmutableMap.of(1, new HiveTypeName("string"))), Optional.of(new HiveSplit.BucketConversion(BUCKETING_V1, 32, 16, ImmutableList.of(createBaseColumn("col", 5, HIVE_LONG, BIGINT, ColumnType.REGULAR, Optional.of("comment"))))), Optional.empty(), false, Optional.of(acidInfo), 555534, // some non-standard value
    SplitWeight.fromProportion(2.0));
    String json = codec.toJson(expected);
    HiveSplit actual = codec.fromJson(json);
    assertEquals(actual.getDatabase(), expected.getDatabase());
    assertEquals(actual.getTable(), expected.getTable());
    assertEquals(actual.getPartitionName(), expected.getPartitionName());
    assertEquals(actual.getPath(), expected.getPath());
    assertEquals(actual.getStart(), expected.getStart());
    assertEquals(actual.getLength(), expected.getLength());
    assertEquals(actual.getEstimatedFileSize(), expected.getEstimatedFileSize());
    assertEquals(actual.getSchema(), expected.getSchema());
    assertEquals(actual.getPartitionKeys(), expected.getPartitionKeys());
    assertEquals(actual.getAddresses(), expected.getAddresses());
    assertEquals(actual.getTableToPartitionMapping().getPartitionColumnCoercions(), expected.getTableToPartitionMapping().getPartitionColumnCoercions());
    assertEquals(actual.getTableToPartitionMapping().getTableToPartitionColumns(), expected.getTableToPartitionMapping().getTableToPartitionColumns());
    assertEquals(actual.getBucketConversion(), expected.getBucketConversion());
    assertEquals(actual.isForceLocalScheduling(), expected.isForceLocalScheduling());
    assertEquals(actual.isS3SelectPushdownEnabled(), expected.isS3SelectPushdownEnabled());
    assertEquals(actual.getAcidInfo().get(), expected.getAcidInfo().get());
    assertEquals(actual.getSplitNumber(), expected.getSplitNumber());
    assertEquals(actual.getSplitWeight(), expected.getSplitWeight());
}
Also used : Path(org.apache.hadoop.fs.Path) Properties(java.util.Properties) HostAddress(io.trino.spi.HostAddress) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Type(io.trino.spi.type.Type) ColumnType(io.trino.plugin.hive.HiveColumnHandle.ColumnType) TypeDeserializer(io.trino.plugin.base.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 3 with TypeDeserializer

use of io.trino.plugin.base.TypeDeserializer in project trino by trinodb.

the class TestHiveColumnHandle method testRoundTrip.

private void testRoundTrip(HiveColumnHandle expected) {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(TESTING_TYPE_MANAGER)));
    JsonCodec<HiveColumnHandle> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveColumnHandle.class);
    String json = codec.toJson(expected);
    HiveColumnHandle actual = codec.fromJson(json);
    assertEquals(actual.getBaseColumnName(), expected.getBaseColumnName());
    assertEquals(actual.getBaseHiveColumnIndex(), expected.getBaseHiveColumnIndex());
    assertEquals(actual.getBaseType(), expected.getBaseType());
    assertEquals(actual.getBaseHiveType(), expected.getBaseHiveType());
    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getType(), expected.getType());
    assertEquals(actual.getHiveType(), expected.getHiveType());
    assertEquals(actual.getHiveColumnProjectionInfo(), expected.getHiveColumnProjectionInfo());
    assertEquals(actual.isPartitionKey(), expected.isPartitionKey());
}
Also used : RowType(io.trino.spi.type.RowType) Type(io.trino.spi.type.Type) HiveType.toHiveType(io.trino.plugin.hive.HiveType.toHiveType) TypeDeserializer(io.trino.plugin.base.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Example 4 with TypeDeserializer

use of io.trino.plugin.base.TypeDeserializer in project trino by trinodb.

the class TestRecordingHiveMetastore method createJsonCodec.

private JsonCodec<HiveMetastoreRecording.Recording> createJsonCodec() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    TypeDeserializer typeDeserializer = new TypeDeserializer(new TestingTypeManager());
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Block.class, new TestingBlockJsonSerde.Deserializer(new HiveBlockEncodingSerde()), Type.class, typeDeserializer));
    objectMapperProvider.setJsonSerializers(ImmutableMap.of(Block.class, new TestingBlockJsonSerde.Serializer(new HiveBlockEncodingSerde())));
    JsonCodec<HiveMetastoreRecording.Recording> jsonCodec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveMetastoreRecording.Recording.class);
    return jsonCodec;
}
Also used : ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) HiveType(io.trino.plugin.hive.HiveType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) HiveBlockEncodingSerde(io.trino.plugin.hive.util.HiveBlockEncodingSerde) TypeDeserializer(io.trino.plugin.base.TypeDeserializer) Block(io.trino.spi.block.Block) TypeDeserializer(io.trino.plugin.base.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Aggregations

JsonCodecFactory (io.airlift.json.JsonCodecFactory)4 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)4 TypeDeserializer (io.trino.plugin.base.TypeDeserializer)4 Type (io.trino.spi.type.Type)4 TestingTypeManager (io.trino.spi.type.TestingTypeManager)2 ColumnType (io.trino.plugin.hive.HiveColumnHandle.ColumnType)1 HiveType (io.trino.plugin.hive.HiveType)1 HiveType.toHiveType (io.trino.plugin.hive.HiveType.toHiveType)1 HiveBlockEncodingSerde (io.trino.plugin.hive.util.HiveBlockEncodingSerde)1 HostAddress (io.trino.spi.HostAddress)1 Block (io.trino.spi.block.Block)1 ColumnStatisticType (io.trino.spi.statistics.ColumnStatisticType)1 RowType (io.trino.spi.type.RowType)1 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)1 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)1 Properties (java.util.Properties)1 Path (org.apache.hadoop.fs.Path)1 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1