private static CatalogColumnStatisticsDataBase getPartitionColumnStats()

in flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/util/HiveStatsUtil.java [174:281]


    private static CatalogColumnStatisticsDataBase getPartitionColumnStats(
            HiveMetastoreClientWrapper client,
            Table hiveTable,
            LogicalType logicalType,
            Object partitionValue,
            int partitionColIndex,
            String defaultPartitionName) {
        switch (logicalType.getTypeRoot()) {
            case CHAR:
            case VARCHAR:
                {
                    Long maxLength = null;
                    Double avgLength = null;
                    Long nullCount = 0L;
                    if (partitionValue == null) {
                        nullCount =
                                getPartitionColumnNullCount(
                                        client, hiveTable, partitionColIndex, defaultPartitionName);
                    } else {
                        long valLength = ((String) partitionValue).length();
                        maxLength = valLength;
                        avgLength = (double) valLength;
                    }
                    return new CatalogColumnStatisticsDataString(
                            maxLength, avgLength, 1L, nullCount);
                }
            case BOOLEAN:
                {
                    long trueCount = 0L;
                    long falseCount = 0L;
                    Long nullCount = 0L;
                    if (partitionValue == null) {
                        nullCount =
                                getPartitionColumnNullCount(
                                        client, hiveTable, partitionColIndex, defaultPartitionName);
                    } else {
                        Boolean boolVal = (Boolean) partitionValue;
                        if (boolVal) {
                            trueCount = 1L;
                        } else {
                            falseCount = 1L;
                        }
                    }
                    return new CatalogColumnStatisticsDataBoolean(trueCount, falseCount, nullCount);
                }
            case TINYINT:
            case SMALLINT:
            case INTEGER:
            case BIGINT:
                {
                    Long min = null;
                    Long max = null;
                    Long nullCount = 0L;
                    if (partitionValue == null) {
                        nullCount =
                                getPartitionColumnNullCount(
                                        client, hiveTable, partitionColIndex, defaultPartitionName);
                    } else {
                        min = ((Number) partitionValue).longValue();
                        max = min;
                    }
                    return new CatalogColumnStatisticsDataLong(min, max, 1L, nullCount);
                }
            case FLOAT:
            case DOUBLE:
            case DECIMAL:
                {
                    Double min = null;
                    Double max = null;
                    Long nullCount = 0L;
                    if (partitionValue == null) {
                        nullCount =
                                getPartitionColumnNullCount(
                                        client, hiveTable, partitionColIndex, defaultPartitionName);
                    } else {
                        min = ((Number) partitionValue).doubleValue();
                        max = min;
                    }
                    return new CatalogColumnStatisticsDataDouble(min, max, 1L, nullCount);
                }
            case DATE:
            case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
                {
                    Date min = null;
                    Date max = null;
                    Long nullCount = 0L;
                    if (partitionValue == null) {
                        nullCount =
                                getPartitionColumnNullCount(
                                        client, hiveTable, partitionColIndex, defaultPartitionName);
                    } else {
                        if (partitionValue instanceof LocalDate) {
                            min = new Date(((LocalDate) partitionValue).toEpochDay());
                        } else if (partitionValue instanceof LocalDateTime) {
                            min =
                                    new Date(
                                            ((LocalDateTime) partitionValue)
                                                    .toLocalDate()
                                                    .toEpochDay());
                        }
                        max = min;
                    }
                    return new CatalogColumnStatisticsDataDate(min, max, 1L, nullCount);
                }
            default:
                return null;
        }
    }