bowenli86 commented on a change in pull request #8636: [FLINK-12237][hive]Support Hive table stats related operations in HiveCatalog URL: https://github.com/apache/flink/pull/8636#discussion_r298298588
########## File path: flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTest.java ########## @@ -1069,6 +1070,84 @@ public void testListPartitionPartialSpec() throws Exception { assertEquals(1, catalog.listPartitions(path1, createAnotherPartitionSpecSubset()).size()); } + + // ------ table and column stats ------ + + @Test + public void testGetTableStats_TableNotExistException() throws Exception{ + catalog.createDatabase(db1, createDb(), false); + exception.expect(org.apache.flink.table.catalog.exceptions.TableNotExistException.class); + catalog.getTableStatistics(path1); + } + + @Test + public void testGetPartitionStats() throws Exception{ + catalog.createDatabase(db1, createDb(), false); + catalog.createTable(path1, createPartitionedTable(), false); + catalog.createPartition(path1, createPartitionSpec(), createPartition(), false); + CatalogTableStatistics tableStatistics = catalog.getPartitionStatistics(path1, createPartitionSpec()); + assertEquals(0, tableStatistics.getFileCount()); + assertEquals(0, tableStatistics.getRawDataSize()); + assertEquals(0, tableStatistics.getTotalSize()); + assertEquals(0, tableStatistics.getRowCount()); + } + + @Test + public void testAlterTableStats() throws Exception{ + // Non-partitioned table + catalog.createDatabase(db1, createDb(), false); + CatalogTable table = createTable(); + catalog.createTable(path1, table, false); + CatalogTableStatistics tableStats = new CatalogTableStatistics(100, 10, 1000, 10000); + catalog.alterTableStatistics(path1, tableStats, false); + CatalogTableStatistics actual = catalog.getTableStatistics(path1); + + // we don't check fileCount and totalSize here for hive will automatically calc and set to real num. + assertEquals(tableStats.getRowCount(), actual.getRowCount()); + assertEquals(tableStats.getRawDataSize(), actual.getRawDataSize()); + } + + @Test + public void testAlterTableStats_partitionedTable() throws Exception { + // alterTableStats() should do nothing for partitioned tables + // getTableStats() should return empty column stats for partitioned tables + catalog.createDatabase(db1, createDb(), false); + CatalogTable catalogTable = createPartitionedTable(); + catalog.createTable(path1, catalogTable, false); + Review comment: add another assertEquals(CatalogTableStatistics.UNKNOWN, catalog.getTableStatistics(path1)); here to reflect the comment that // alterTableStats() should do nothing for partitioned tables // getTableStats() should return empty column stats for partitioned tables ? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services