Search in sources :

Example 6 with CatalogTableStatistics

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

the class CatalogStatisticsTest method createPartitionStats.

private void createPartitionStats(String part1, int part2, long rowCount) 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);
    catalog.createPartition(path, partSpec, new CatalogPartitionImpl(new HashMap<>(), ""), true);
    catalog.alterPartitionStatistics(path, partSpec, new CatalogTableStatistics(rowCount, 10, 1000L, 2000L), true);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec) LinkedHashMap(java.util.LinkedHashMap) CatalogPartitionImpl(org.apache.flink.table.catalog.CatalogPartitionImpl) CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics)

Example 7 with CatalogTableStatistics

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

the class CatalogStatisticsTest method alterTableStatisticsWithUnknownRowCount.

private void alterTableStatisticsWithUnknownRowCount(Catalog catalog, String tableName) throws TableNotExistException, TablePartitionedException {
    catalog.alterTableStatistics(new ObjectPath(databaseName, tableName), new CatalogTableStatistics(CatalogTableStatistics.UNKNOWN.getRowCount(), 1, 10000, 200000), true);
    catalog.alterTableColumnStatistics(new ObjectPath(databaseName, tableName), createColumnStats(), true);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics)

Example 8 with CatalogTableStatistics

use of org.apache.flink.table.catalog.stats.CatalogTableStatistics in project flink-mirror by flink-ci.

the class HiveCatalogHiveMetadataTest method checkStatistics.

private void checkStatistics(int inputStat, int expectStat) throws Exception {
    catalog.dropTable(path1, true);
    Map<String, String> properties = new HashMap<>();
    properties.put(FactoryUtil.CONNECTOR.key(), SqlCreateHiveTable.IDENTIFIER);
    properties.put(StatsSetupConst.ROW_COUNT, String.valueOf(inputStat));
    properties.put(StatsSetupConst.NUM_FILES, String.valueOf(inputStat));
    properties.put(StatsSetupConst.TOTAL_SIZE, String.valueOf(inputStat));
    properties.put(StatsSetupConst.RAW_DATA_SIZE, String.valueOf(inputStat));
    CatalogTable catalogTable = new CatalogTableImpl(TableSchema.builder().field("f0", DataTypes.INT()).build(), properties, "");
    catalog.createTable(path1, catalogTable, false);
    CatalogTableStatistics statistics = catalog.getTableStatistics(path1);
    assertEquals(expectStat, statistics.getRowCount());
    assertEquals(expectStat, statistics.getFileCount());
    assertEquals(expectStat, statistics.getRawDataSize());
    assertEquals(expectStat, statistics.getTotalSize());
}
Also used : HashMap(java.util.HashMap) CatalogTableImpl(org.apache.flink.table.catalog.CatalogTableImpl) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogTable(org.apache.flink.table.catalog.CatalogTable) CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics)

Example 9 with CatalogTableStatistics

use of org.apache.flink.table.catalog.stats.CatalogTableStatistics in project flink-mirror by flink-ci.

the class DatabaseCalciteSchema method extractTableStats.

private TableStats extractTableStats(ContextResolvedTable lookupResult, ObjectIdentifier identifier) {
    if (lookupResult.isTemporary()) {
        return TableStats.UNKNOWN;
    }
    final Catalog catalog = lookupResult.getCatalog().orElseThrow(IllegalStateException::new);
    final ObjectPath tablePath = identifier.toObjectPath();
    try {
        final CatalogTableStatistics tableStatistics = catalog.getTableStatistics(tablePath);
        final CatalogColumnStatistics columnStatistics = catalog.getTableColumnStatistics(tablePath);
        return convertToTableStats(tableStatistics, columnStatistics);
    } catch (TableNotExistException e) {
        throw new ValidationException(format("Could not get statistic for table: [%s, %s, %s]", identifier.getCatalogName(), tablePath.getDatabaseName(), tablePath.getObjectName()), e);
    }
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) ValidationException(org.apache.flink.table.api.ValidationException) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) Catalog(org.apache.flink.table.catalog.Catalog) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics) CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics)

Example 10 with CatalogTableStatistics

use of org.apache.flink.table.catalog.stats.CatalogTableStatistics in project flink-mirror by flink-ci.

the class CatalogTest method testAlterTableStats.

@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());
}
Also used : CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics) Test(org.junit.Test)

Aggregations

CatalogTableStatistics (org.apache.flink.table.catalog.stats.CatalogTableStatistics)39 Test (org.junit.Test)15 ObjectPath (org.apache.flink.table.catalog.ObjectPath)12 CatalogColumnStatistics (org.apache.flink.table.catalog.stats.CatalogColumnStatistics)12 HashMap (java.util.HashMap)9 CatalogColumnStatisticsDataString (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString)9 CatalogPartitionSpec (org.apache.flink.table.catalog.CatalogPartitionSpec)6 PartitionNotExistException (org.apache.flink.table.catalog.exceptions.PartitionNotExistException)6 LinkedHashMap (java.util.LinkedHashMap)3 ValidationException (org.apache.flink.table.api.ValidationException)3 Catalog (org.apache.flink.table.catalog.Catalog)3 CatalogPartitionImpl (org.apache.flink.table.catalog.CatalogPartitionImpl)3 CatalogTable (org.apache.flink.table.catalog.CatalogTable)3 CatalogTableImpl (org.apache.flink.table.catalog.CatalogTableImpl)3 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)3 CatalogColumnStatisticsDataBase (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBase)3 CatalogColumnStatisticsDataDate (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate)3 CatalogColumnStatisticsDataDouble (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble)3 CatalogColumnStatisticsDataLong (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong)3 TableStats (org.apache.flink.table.plan.stats.TableStats)3