Search in sources :

Example 1 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestConnectorViewDefinition method createTestingViewCodec.

private static JsonCodec<ConnectorViewDefinition> createTestingViewCodec() {
    ObjectMapperProvider provider = new ObjectMapperProvider();
    provider.setJsonDeserializers(ImmutableMap.of(Type.class, new TestingTypeDeserializer(new TestingTypeManager())));
    return new JsonCodecFactory(provider).jsonCodec(ConnectorViewDefinition.class);
}
Also used : Type(io.trino.spi.type.Type) ArrayType(io.trino.spi.type.ArrayType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Example 2 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestAllOrNoneValueSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)));
    AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG);
    assertEquals(all, mapper.readValue(mapper.writeValueAsString(all), AllOrNoneValueSet.class));
    AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG);
    assertEquals(none, mapper.readValue(mapper.writeValueAsString(none), AllOrNoneValueSet.class));
}
Also used : Type(io.trino.spi.type.Type) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 3 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestDomain method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    Domain domain = Domain.all(BIGINT);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.none(DOUBLE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.notNull(BOOLEAN);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.notNull(HYPER_LOG_LOG);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.onlyNull(VARCHAR);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.onlyNull(HYPER_LOG_LOG);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.singleValue(BIGINT, Long.MIN_VALUE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.singleValue(ID, Long.MIN_VALUE);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
    domain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 0L), Range.equal(BIGINT, 1L), Range.range(BIGINT, 2L, true, 3L, true)), true);
    assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
}
Also used : Type(io.trino.spi.type.Type) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) Block(io.trino.spi.block.Block) TestingBlockJsonSerde(io.trino.spi.block.TestingBlockJsonSerde) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 4 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestEquatableValueSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    EquatableValueSet set = EquatableValueSet.all(ID);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.none(ID);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(ID, 1L);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(ID, 1L, 2L);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
    set = EquatableValueSet.of(ID, 1L, 2L).complement();
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
}
Also used : Type(io.trino.spi.type.Type) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) Block(io.trino.spi.block.Block) TestingBlockJsonSerde(io.trino.spi.block.TestingBlockJsonSerde) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 5 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestIcebergSplitSource method createQueryRunner.

@Override
protected QueryRunner createQueryRunner() throws Exception {
    HdfsConfig config = new HdfsConfig();
    HdfsConfiguration configuration = new HiveHdfsConfiguration(new HdfsConfigurationInitializer(config), ImmutableSet.of());
    HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(configuration, config, new NoHdfsAuthentication());
    File tempDir = Files.createTempDirectory("test_iceberg_split_source").toFile();
    this.metastoreDir = new File(tempDir, "iceberg_data");
    HiveMetastore metastore = createTestingFileHiveMetastore(metastoreDir);
    IcebergTableOperationsProvider operationsProvider = new FileMetastoreTableOperationsProvider(new HdfsFileIoProvider(hdfsEnvironment));
    this.catalog = new TrinoHiveCatalog(new CatalogName("hive"), memoizeMetastore(metastore, 1000), hdfsEnvironment, new TestingTypeManager(), operationsProvider, "test", false, false, false);
    return createIcebergQueryRunner(ImmutableMap.of(), ImmutableMap.of(), ImmutableList.of(NATION), Optional.of(metastoreDir));
}
Also used : HdfsConfigurationInitializer(io.trino.plugin.hive.HdfsConfigurationInitializer) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) FileHiveMetastore.createTestingFileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore.createTestingFileHiveMetastore) HdfsConfig(io.trino.plugin.hive.HdfsConfig) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HdfsConfiguration(io.trino.plugin.hive.HdfsConfiguration) NoHdfsAuthentication(io.trino.plugin.hive.authentication.NoHdfsAuthentication) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) FileMetastoreTableOperationsProvider(io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider) TrinoHiveCatalog(io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog) CatalogName(io.trino.plugin.base.CatalogName) IcebergTableOperationsProvider(io.trino.plugin.iceberg.catalog.IcebergTableOperationsProvider) File(java.io.File) TestingTypeManager(io.trino.spi.type.TestingTypeManager)

Aggregations

TestingTypeManager (io.trino.spi.type.TestingTypeManager)21 Type (io.trino.spi.type.Type)14 Test (org.testng.annotations.Test)14 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)8 ArrayType (io.trino.spi.type.ArrayType)7 MapType (io.trino.spi.type.MapType)6 RowType (io.trino.spi.type.RowType)6 TestingTypeDeserializer (io.trino.spi.type.TestingTypeDeserializer)6 Schema (org.apache.avro.Schema)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 Block (io.trino.spi.block.Block)5 CatalogName (io.trino.plugin.base.CatalogName)4 FileMetastoreTableOperationsProvider (io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider)4 TrinoHiveCatalog (io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog)4 TestingBlockEncodingSerde (io.trino.spi.block.TestingBlockEncodingSerde)4 TestingBlockJsonSerde (io.trino.spi.block.TestingBlockJsonSerde)4 JsonCodecFactory (io.airlift.json.JsonCodecFactory)3 HdfsConfig (io.trino.plugin.hive.HdfsConfig)3 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)3