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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations