Search in sources :

Example 16 with TestingTypeManager

use of com.facebook.presto.common.type.TestingTypeManager in project presto by prestodb.

the class TestHiveMaterializedViewUtils method testMaterializedDataPredicatesWithIntParitionType.

@Test
public void testMaterializedDataPredicatesWithIntParitionType() {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingSemiTransactionalHiveMetastore testMetastore = TestingSemiTransactionalHiveMetastore.create();
    List<String> keys = ImmutableList.of("ds", "code");
    Column dsColumn = new Column("ds", HIVE_STRING, Optional.empty(), Optional.empty());
    Column codeColumn = new Column("code", HIVE_INT, Optional.empty(), Optional.empty());
    List<Column> partitionColumns = ImmutableList.of(dsColumn, codeColumn);
    List<String> partitions = ImmutableList.of("ds=2021-01-01/code=1", "ds=2021-01-01/code=2", "ds=2021-01-02/code=1", "ds=2021-01-02/code=2");
    testMetastore.setPartitionNames(partitions);
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2021-01-01' AS varchar)"), new TestingPartitionResult("code", INTEGER, "1")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2021-01-01' AS varchar)"), new TestingPartitionResult("code", INTEGER, "2")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2021-01-02' AS varchar)"), new TestingPartitionResult("code", INTEGER, "1")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2021-01-02' AS varchar)"), new TestingPartitionResult("code", INTEGER, "2")));
    MaterializedDataPredicates materializedDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(partitionColumns), DateTimeZone.UTC);
    comparePredicates(materializedDataPredicates, keys, partitionResults.build());
}
Also used : Column(com.facebook.presto.hive.metastore.Column) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HiveMaterializedViewUtils.getMaterializedDataPredicates(com.facebook.presto.hive.HiveMaterializedViewUtils.getMaterializedDataPredicates) MaterializedDataPredicates(com.facebook.presto.spi.MaterializedViewStatus.MaterializedDataPredicates) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 17 with TestingTypeManager

use of com.facebook.presto.common.type.TestingTypeManager in project presto by prestodb.

the class TestHiveMaterializedViewUtils method testDifferenceDataPredicatesWithDifferentExtraPartitions.

@Test
public void testDifferenceDataPredicatesWithDifferentExtraPartitions() {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingSemiTransactionalHiveMetastore testMetastore = TestingSemiTransactionalHiveMetastore.create();
    List<String> keys = ImmutableList.of("ds", "shipmode");
    Column dsColumn = new Column("ds", HIVE_STRING, Optional.empty(), Optional.empty());
    Column shipmodeColumn = new Column("shipmode", HIVE_STRING, Optional.empty(), Optional.empty());
    List<Column> partitionColumns = ImmutableList.of(dsColumn, shipmodeColumn);
    List<String> partitions = ImmutableList.of("ds=2020-01-01/shipmode=air", "ds=2020-01-01/shipmode=road", "ds=2020-01-02/shipmode=air", "ds=2020-01-02/shipmode=road");
    testMetastore.setPartitionNames(partitions);
    MaterializedDataPredicates baseDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(partitionColumns), DateTimeZone.UTC);
    Column viewShipModeColumn = new Column("view_shipmode", HIVE_STRING, Optional.empty(), Optional.empty());
    List<Column> viewPartitionColumns = ImmutableList.of(dsColumn, viewShipModeColumn);
    List<String> viewPartitions = ImmutableList.of("ds=2020-01-01/view_shipmode=air", "ds=2020-01-01/view_shipmode=road");
    testMetastore.setPartitionNames(viewPartitions);
    MaterializedDataPredicates materializedDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(viewPartitionColumns), DateTimeZone.UTC);
    Map<String, String> materializedViewToBaseColumnMap = ImmutableMap.of("ds", "ds");
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-02' AS varchar)"), new TestingPartitionResult("shipmode", VARCHAR, "CAST('air' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-02' AS varchar)"), new TestingPartitionResult("shipmode", VARCHAR, "CAST('road' AS varchar)")));
    MaterializedDataPredicates diffDataPredicates = differenceDataPredicates(baseDataPredicates, materializedDataPredicates, materializedViewToBaseColumnMap);
    comparePredicates(diffDataPredicates, keys, partitionResults.build());
}
Also used : Column(com.facebook.presto.hive.metastore.Column) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HiveMaterializedViewUtils.getMaterializedDataPredicates(com.facebook.presto.hive.HiveMaterializedViewUtils.getMaterializedDataPredicates) MaterializedDataPredicates(com.facebook.presto.spi.MaterializedViewStatus.MaterializedDataPredicates) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 18 with TestingTypeManager

use of com.facebook.presto.common.type.TestingTypeManager in project presto by prestodb.

the class TestAllOrNoneValueSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    ObjectMapper mapper = new JsonObjectMapperProvider().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(com.facebook.presto.common.type.Type) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.testng.annotations.Test)

Example 19 with TestingTypeManager

use of com.facebook.presto.common.type.TestingTypeManager in project presto by prestodb.

the class TestSortedRangeSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    SortedRangeSet set = SortedRangeSet.all(BIGINT);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.none(DOUBLE);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(VARCHAR, utf8Slice("abc"));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(Range.equal(BOOLEAN, true), Range.equal(BOOLEAN, false));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
}
Also used : Type(com.facebook.presto.common.type.Type) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) TestingBlockEncodingSerde(com.facebook.presto.common.block.TestingBlockEncodingSerde) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) Block(com.facebook.presto.common.block.Block) TestingBlockJsonSerde(com.facebook.presto.common.block.TestingBlockJsonSerde) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.testng.annotations.Test)

Example 20 with TestingTypeManager

use of com.facebook.presto.common.type.TestingTypeManager in project presto by prestodb.

the class TestDomain method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new JsonObjectMapperProvider().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(com.facebook.presto.common.type.Type) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) TestingBlockEncodingSerde(com.facebook.presto.common.block.TestingBlockEncodingSerde) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TestingTypeDeserializer(com.facebook.presto.common.type.TestingTypeDeserializer) Block(com.facebook.presto.common.block.Block) TestingBlockJsonSerde(com.facebook.presto.common.block.TestingBlockJsonSerde) TestingTypeManager(com.facebook.presto.common.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.testng.annotations.Test)

Aggregations

TestingTypeManager (com.facebook.presto.common.type.TestingTypeManager)21 Test (org.testng.annotations.Test)21 Column (com.facebook.presto.hive.metastore.Column)12 HiveMaterializedViewUtils.getMaterializedDataPredicates (com.facebook.presto.hive.HiveMaterializedViewUtils.getMaterializedDataPredicates)11 MaterializedDataPredicates (com.facebook.presto.spi.MaterializedViewStatus.MaterializedDataPredicates)11 ImmutableList (com.google.common.collect.ImmutableList)11 List (java.util.List)11 JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)7 TestingTypeDeserializer (com.facebook.presto.common.type.TestingTypeDeserializer)7 Type (com.facebook.presto.common.type.Type)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 Block (com.facebook.presto.common.block.Block)6 TestingBlockEncodingSerde (com.facebook.presto.common.block.TestingBlockEncodingSerde)6 TestingBlockJsonSerde (com.facebook.presto.common.block.TestingBlockJsonSerde)6 Storage (com.facebook.presto.hive.metastore.Storage)3 CacheConfig (com.facebook.presto.cache.CacheConfig)2 StorageFormat (com.facebook.presto.hive.metastore.StorageFormat)2 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2