Search in sources :

Example 6 with TestingTypeManager

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

the class TestHiveMaterializedViewUtils method testDifferenceDataPredicatesEmptyDataPredicates.

@Test
public void testDifferenceDataPredicatesEmptyDataPredicates() {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingSemiTransactionalHiveMetastore testMetastore = TestingSemiTransactionalHiveMetastore.create();
    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");
    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();
    testMetastore.setPartitionNames(viewPartitions);
    MaterializedDataPredicates materializedDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(viewPartitionColumns), DateTimeZone.UTC);
    Map<String, String> materializedViewToBaseColumnMap = ImmutableMap.of();
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-01' AS varchar)"), new TestingPartitionResult("shipmode", VARCHAR, "CAST('air' AS varchar)")));
    MaterializedDataPredicates diffDataPredicates = differenceDataPredicates(baseDataPredicates, materializedDataPredicates, materializedViewToBaseColumnMap);
    assertEquals(diffDataPredicates, getEmptyMaterializedViewDataPredicates());
}
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 7 with TestingTypeManager

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

the class TestHiveMaterializedViewUtils method testMaterializedDataPredicatesWithNullPartitions.

@Test
public void testMaterializedDataPredicatesWithNullPartitions() {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingSemiTransactionalHiveMetastore testMetastore = TestingSemiTransactionalHiveMetastore.create();
    List<String> keys = ImmutableList.of("ds", "category");
    Column dsColumn = new Column("ds", HIVE_STRING, Optional.empty(), Optional.empty());
    Column categoryColumn = new Column("category", HIVE_STRING, Optional.empty(), Optional.empty());
    List<Column> partitionColumns = ImmutableList.of(dsColumn, categoryColumn);
    List<String> partitions = ImmutableList.of("ds=2020-01-01/category=c1", "ds=2020-01-01/category=" + HIVE_DEFAULT_DYNAMIC_PARTITION, "ds=2020-01-02/category=c1", "ds=" + HIVE_DEFAULT_DYNAMIC_PARTITION + "/category=c2");
    testMetastore.setPartitionNames(partitions);
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-01' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c1' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-01' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST(null AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-02' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c1' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST(null AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c2' AS varchar)")));
    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 8 with TestingTypeManager

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

the class TestHiveMaterializedViewUtils method testDifferenceDataPredicatesFullyMaterialized.

@Test
public void testDifferenceDataPredicatesFullyMaterialized() {
    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", "ds=2020-01-02/view_shipmode=air", "ds=2020-01-02/view_shipmode=road");
    testMetastore.setPartitionNames(viewPartitions);
    MaterializedDataPredicates materializedDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(viewPartitionColumns), DateTimeZone.UTC);
    Map<String, String> materializedViewToBaseColumnMap = ImmutableMap.of("ds", "ds", "view_shipmode", "shipmode");
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    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 9 with TestingTypeManager

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

the class TestHiveMaterializedViewUtils method testMaterializedDataPredicates.

@Test
public void testMaterializedDataPredicates() {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingSemiTransactionalHiveMetastore testMetastore = TestingSemiTransactionalHiveMetastore.create();
    List<String> keys = ImmutableList.of("ds", "category");
    Column dsColumn = new Column("ds", HIVE_STRING, Optional.empty(), Optional.empty());
    Column categoryColumn = new Column("category", HIVE_STRING, Optional.empty(), Optional.empty());
    List<Column> partitionColumns = ImmutableList.of(dsColumn, categoryColumn);
    List<String> partitions = ImmutableList.of("ds=2020-01-01/category=c1", "ds=2020-01-01/category=c2", "ds=2020-01-02/category=c1", "ds=2020-01-02/category=c2");
    testMetastore.setPartitionNames(partitions);
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-01' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c1' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-01' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c2' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-02' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c1' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-02' AS varchar)"), new TestingPartitionResult("category", VARCHAR, "CAST('c2' AS varchar)")));
    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 10 with TestingTypeManager

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

the class TestHiveMaterializedViewUtils method testDifferenceDataOuterJoin.

@Test
public void testDifferenceDataOuterJoin() {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingSemiTransactionalHiveMetastore testMetastore = TestingSemiTransactionalHiveMetastore.create();
    List<String> keys = ImmutableList.of("ds");
    Column dsColumn = new Column("ds", HIVE_STRING, Optional.empty(), Optional.empty());
    List<Column> partitionColumns = ImmutableList.of(dsColumn);
    List<String> partitions = ImmutableList.of("ds=2020-01-01", "ds=2020-01-02", "ds=2020-01-03", "ds=2020-01-04", "ds=2020-01-05", "ds=2020-01-06");
    testMetastore.setPartitionNames(partitions);
    MaterializedDataPredicates baseDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(partitionColumns), DateTimeZone.UTC);
    // CREATE MV AS SELECT ds1 as t1.ds, ds2 as t2.ds FROM t1 LEFT JOIN t2 ON t1.ds = t2.ds
    List<String> viewPartitions = ImmutableList.of("ds1=2020-01-02/ds2=2020-01-02", "ds1=2020-01-03/ds2=null", "ds1=2020-01-05/ds2=null", "ds1=2020-01-05/ds2=2020-01-05");
    List<Column> viewPartitionColumns = ImmutableList.of(new Column("ds1", HIVE_STRING, Optional.empty(), Optional.empty()), new Column("ds2", HIVE_STRING, Optional.empty(), Optional.empty()));
    testMetastore.setPartitionNames(viewPartitions);
    MaterializedDataPredicates materializedDataPredicates = getMaterializedDataPredicates(testMetastore, metastoreContext, typeManager, getTable(viewPartitionColumns), DateTimeZone.UTC);
    Map<String, String> materializedViewToBaseColumnMap = ImmutableMap.of("ds2", "ds");
    ImmutableList.Builder<List<TestingPartitionResult>> partitionResults = ImmutableList.builder();
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-01' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-04' AS varchar)")));
    partitionResults.add(ImmutableList.of(new TestingPartitionResult("ds", VARCHAR, "CAST('2020-01-06' AS varchar)")));
    MaterializedDataPredicates diffDataPredicates = differenceDataPredicates(baseDataPredicates, materializedDataPredicates, materializedViewToBaseColumnMap, ImmutableMap.of("ds1", "ds"));
    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)

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