Search in sources :

Example 6 with CatalogColumnStatistics

use of org.apache.flink.table.catalog.stats.CatalogColumnStatistics in project flink by apache.

the class GenericInMemoryCatalogTest method testStatistics.

// ------ statistics ------
@Test
public void testStatistics() throws Exception {
    // Table related
    catalog.createDatabase(db1, createDb(), false);
    CatalogTable table = createTable();
    catalog.createTable(path1, table, false);
    CatalogTestUtil.checkEquals(catalog.getTableStatistics(path1), CatalogTableStatistics.UNKNOWN);
    CatalogTestUtil.checkEquals(catalog.getTableColumnStatistics(path1), CatalogColumnStatistics.UNKNOWN);
    CatalogTableStatistics tableStatistics = new CatalogTableStatistics(5, 2, 100, 575);
    catalog.alterTableStatistics(path1, tableStatistics, false);
    CatalogTestUtil.checkEquals(tableStatistics, catalog.getTableStatistics(path1));
    CatalogColumnStatistics columnStatistics = createColumnStats();
    catalog.alterTableColumnStatistics(path1, columnStatistics, false);
    CatalogTestUtil.checkEquals(columnStatistics, catalog.getTableColumnStatistics(path1));
    // Partition related
    catalog.createDatabase(db2, createDb(), false);
    CatalogTable table2 = createPartitionedTable();
    catalog.createTable(path2, table2, false);
    CatalogPartitionSpec partitionSpec = createPartitionSpec();
    catalog.createPartition(path2, partitionSpec, createPartition(), false);
    CatalogTestUtil.checkEquals(catalog.getPartitionStatistics(path2, partitionSpec), CatalogTableStatistics.UNKNOWN);
    CatalogTestUtil.checkEquals(catalog.getPartitionColumnStatistics(path2, partitionSpec), CatalogColumnStatistics.UNKNOWN);
    catalog.alterPartitionStatistics(path2, partitionSpec, tableStatistics, false);
    CatalogTestUtil.checkEquals(tableStatistics, catalog.getPartitionStatistics(path2, partitionSpec));
    catalog.alterPartitionColumnStatistics(path2, partitionSpec, columnStatistics, false);
    CatalogTestUtil.checkEquals(columnStatistics, catalog.getPartitionColumnStatistics(path2, partitionSpec));
    // Clean up
    catalog.dropTable(path1, false);
    catalog.dropDatabase(db1, false, false);
    catalog.dropTable(path2, false);
    catalog.dropDatabase(db2, false, false);
}
Also used : CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics) CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics) Test(org.junit.Test)

Example 7 with CatalogColumnStatistics

use of org.apache.flink.table.catalog.stats.CatalogColumnStatistics in project flink by apache.

the class CatalogStatisticsTest method createPartitionColumnStats.

private void createPartitionColumnStats(String part1, int part2, boolean unknown) throws Exception {
    ObjectPath path = ObjectPath.fromString("default_database.PartT");
    LinkedHashMap<String, String> partSpecMap = new LinkedHashMap<>();
    partSpecMap.put("part1", part1);
    partSpecMap.put("part2", String.valueOf(part2));
    CatalogPartitionSpec partSpec = new CatalogPartitionSpec(partSpecMap);
    CatalogColumnStatisticsDataLong longColStats = new CatalogColumnStatisticsDataLong(-123L, 763322L, 23L, 77L);
    CatalogColumnStatisticsDataString stringColStats = new CatalogColumnStatisticsDataString(152L, 43.5D, 20L, 0L);
    Map<String, CatalogColumnStatisticsDataBase> colStatsMap = new HashMap<>();
    colStatsMap.put("id", unknown ? new CatalogColumnStatisticsDataLong(null, null, null, null) : longColStats);
    colStatsMap.put("name", unknown ? new CatalogColumnStatisticsDataString(null, null, null, null) : stringColStats);
    catalog.alterPartitionColumnStatistics(path, partSpec, new CatalogColumnStatistics(colStatsMap), true);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CatalogColumnStatisticsDataLong(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong) CatalogColumnStatisticsDataBase(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBase) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with CatalogColumnStatistics

use of org.apache.flink.table.catalog.stats.CatalogColumnStatistics in project flink by apache.

the class CatalogStatisticsTest method createColumnStats.

private CatalogColumnStatistics createColumnStats() {
    CatalogColumnStatisticsDataBoolean booleanColStats = new CatalogColumnStatisticsDataBoolean(55L, 45L, 5L);
    CatalogColumnStatisticsDataLong longColStats = new CatalogColumnStatisticsDataLong(-123L, 763322L, 23L, 77L);
    CatalogColumnStatisticsDataString stringColStats = new CatalogColumnStatisticsDataString(152L, 43.5D, 20L, 0L);
    CatalogColumnStatisticsDataDate dateColStats = new CatalogColumnStatisticsDataDate(new Date(71L), new Date(17923L), 100L, 0L);
    CatalogColumnStatisticsDataDouble doubleColStats = new CatalogColumnStatisticsDataDouble(-123.35D, 7633.22D, 73L, 27L);
    Map<String, CatalogColumnStatisticsDataBase> colStatsMap = new HashMap<>(6);
    colStatsMap.put("b1", booleanColStats);
    colStatsMap.put("l2", longColStats);
    colStatsMap.put("s3", stringColStats);
    colStatsMap.put("d4", dateColStats);
    colStatsMap.put("dd5", doubleColStats);
    return new CatalogColumnStatistics(colStatsMap);
}
Also used : CatalogColumnStatisticsDataDate(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate) CatalogColumnStatisticsDataLong(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong) CatalogColumnStatisticsDataDouble(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble) CatalogColumnStatisticsDataBase(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBase) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CatalogColumnStatisticsDataBoolean(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBoolean) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) Date(org.apache.flink.table.catalog.stats.Date) CatalogColumnStatisticsDataDate(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics)

Example 9 with CatalogColumnStatistics

use of org.apache.flink.table.catalog.stats.CatalogColumnStatistics in project flink by apache.

the class GenericInMemoryCatalogTest method createColumnStats.

private CatalogColumnStatistics createColumnStats() {
    CatalogColumnStatisticsDataBoolean booleanColStats = new CatalogColumnStatisticsDataBoolean(55L, 45L, 5L);
    CatalogColumnStatisticsDataLong longColStats = new CatalogColumnStatisticsDataLong(-123L, 763322L, 23L, 79L);
    CatalogColumnStatisticsDataString stringColStats = new CatalogColumnStatisticsDataString(152L, 43.5D, 20L, 0L);
    CatalogColumnStatisticsDataDate dateColStats = new CatalogColumnStatisticsDataDate(new Date(71L), new Date(17923L), 1321L, 0L);
    CatalogColumnStatisticsDataDouble doubleColStats = new CatalogColumnStatisticsDataDouble(-123.35D, 7633.22D, 23L, 79L);
    CatalogColumnStatisticsDataBinary binaryColStats = new CatalogColumnStatisticsDataBinary(755L, 43.5D, 20L);
    Map<String, CatalogColumnStatisticsDataBase> colStatsMap = new HashMap<>(6);
    colStatsMap.put("b1", booleanColStats);
    colStatsMap.put("l2", longColStats);
    colStatsMap.put("s3", stringColStats);
    colStatsMap.put("d4", dateColStats);
    colStatsMap.put("dd5", doubleColStats);
    colStatsMap.put("bb6", binaryColStats);
    return new CatalogColumnStatistics(colStatsMap);
}
Also used : CatalogColumnStatisticsDataDate(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate) CatalogColumnStatisticsDataLong(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong) CatalogColumnStatisticsDataDouble(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble) CatalogColumnStatisticsDataBase(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBase) HashMap(java.util.HashMap) CatalogColumnStatisticsDataBoolean(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBoolean) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogColumnStatisticsDataBinary(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBinary) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) Date(org.apache.flink.table.catalog.stats.Date) CatalogColumnStatisticsDataDate(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics)

Example 10 with CatalogColumnStatistics

use of org.apache.flink.table.catalog.stats.CatalogColumnStatistics in project flink by apache.

the class GenericInMemoryCatalog method getTableColumnStatistics.

@Override
public CatalogColumnStatistics getTableColumnStatistics(ObjectPath tablePath) throws TableNotExistException {
    checkNotNull(tablePath);
    if (!tableExists(tablePath)) {
        throw new TableNotExistException(getName(), tablePath);
    }
    CatalogColumnStatistics result = tableColumnStats.get(tablePath);
    return result != null ? result.copy() : CatalogColumnStatistics.UNKNOWN;
}
Also used : TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics)

Aggregations

CatalogColumnStatistics (org.apache.flink.table.catalog.stats.CatalogColumnStatistics)12 HashMap (java.util.HashMap)6 CatalogColumnStatisticsDataBase (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBase)6 CatalogColumnStatisticsDataString (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString)6 CatalogColumnStatisticsDataLong (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong)5 CatalogColumnStatisticsDataDate (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate)4 CatalogColumnStatisticsDataDouble (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble)4 CatalogTableStatistics (org.apache.flink.table.catalog.stats.CatalogTableStatistics)4 CatalogPartitionSpec (org.apache.flink.table.catalog.CatalogPartitionSpec)3 CatalogTable (org.apache.flink.table.catalog.CatalogTable)3 PartitionNotExistException (org.apache.flink.table.catalog.exceptions.PartitionNotExistException)3 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)3 CatalogColumnStatisticsDataBoolean (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBoolean)3 Date (org.apache.flink.table.catalog.stats.Date)3 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 ObjectPath (org.apache.flink.table.catalog.ObjectPath)2 CatalogColumnStatisticsDataBinary (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBinary)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1