Search in sources :

Example 6 with CatalogColumnStatisticsDataDate

use of org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate 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 7 with CatalogColumnStatisticsDataDate

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

the class CatalogTableStatisticsConverter method convertToColumnStats.

private static ColumnStats convertToColumnStats(CatalogColumnStatisticsDataBase columnStatisticsData) {
    Long ndv = null;
    Long nullCount = columnStatisticsData.getNullCount();
    Double avgLen = null;
    Integer maxLen = null;
    Comparable<?> max = null;
    Comparable<?> min = null;
    if (columnStatisticsData instanceof CatalogColumnStatisticsDataBoolean) {
        CatalogColumnStatisticsDataBoolean booleanData = (CatalogColumnStatisticsDataBoolean) columnStatisticsData;
        avgLen = 1.0;
        maxLen = 1;
        if (null == booleanData.getFalseCount() || null == booleanData.getTrueCount()) {
            ndv = 2L;
        } else if ((booleanData.getFalseCount() == 0 && booleanData.getTrueCount() > 0) || (booleanData.getFalseCount() > 0 && booleanData.getTrueCount() == 0)) {
            ndv = 1L;
        } else {
            ndv = 2L;
        }
    } else if (columnStatisticsData instanceof CatalogColumnStatisticsDataLong) {
        CatalogColumnStatisticsDataLong longData = (CatalogColumnStatisticsDataLong) columnStatisticsData;
        ndv = longData.getNdv();
        avgLen = 8.0;
        maxLen = 8;
        max = longData.getMax();
        min = longData.getMin();
    } else if (columnStatisticsData instanceof CatalogColumnStatisticsDataDouble) {
        CatalogColumnStatisticsDataDouble doubleData = (CatalogColumnStatisticsDataDouble) columnStatisticsData;
        ndv = doubleData.getNdv();
        avgLen = 8.0;
        maxLen = 8;
        max = doubleData.getMax();
        min = doubleData.getMin();
    } else if (columnStatisticsData instanceof CatalogColumnStatisticsDataString) {
        CatalogColumnStatisticsDataString strData = (CatalogColumnStatisticsDataString) columnStatisticsData;
        ndv = strData.getNdv();
        avgLen = strData.getAvgLength();
        maxLen = null == strData.getMaxLength() ? null : strData.getMaxLength().intValue();
    } else if (columnStatisticsData instanceof CatalogColumnStatisticsDataBinary) {
        CatalogColumnStatisticsDataBinary binaryData = (CatalogColumnStatisticsDataBinary) columnStatisticsData;
        avgLen = binaryData.getAvgLength();
        maxLen = null == binaryData.getMaxLength() ? null : binaryData.getMaxLength().intValue();
    } else if (columnStatisticsData instanceof CatalogColumnStatisticsDataDate) {
        CatalogColumnStatisticsDataDate dateData = (CatalogColumnStatisticsDataDate) columnStatisticsData;
        ndv = dateData.getNdv();
        if (dateData.getMax() != null) {
            max = Date.valueOf(DateTimeUtils.unixDateToString((int) dateData.getMax().getDaysSinceEpoch()));
        }
        if (dateData.getMin() != null) {
            min = Date.valueOf(DateTimeUtils.unixDateToString((int) dateData.getMin().getDaysSinceEpoch()));
        }
    } else {
        throw new TableException("Unsupported CatalogColumnStatisticsDataBase: " + columnStatisticsData.getClass().getCanonicalName());
    }
    return ColumnStats.Builder.builder().setNdv(ndv).setNullCount(nullCount).setAvgLen(avgLen).setMaxLen(maxLen).setMax(max).setMin(min).build();
}
Also used : TableException(org.apache.flink.table.api.TableException) CatalogColumnStatisticsDataDate(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate) CatalogColumnStatisticsDataLong(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong) CatalogColumnStatisticsDataDouble(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble) CatalogColumnStatisticsDataLong(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong) CatalogColumnStatisticsDataBoolean(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBoolean) CatalogColumnStatisticsDataString(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString) CatalogColumnStatisticsDataBinary(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBinary) CatalogColumnStatisticsDataDouble(org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble)

Aggregations

CatalogColumnStatisticsDataDate (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDate)7 CatalogColumnStatisticsDataDouble (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataDouble)6 CatalogColumnStatisticsDataLong (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong)6 CatalogColumnStatisticsDataString (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataString)6 CatalogColumnStatisticsDataBoolean (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBoolean)5 HashMap (java.util.HashMap)4 CatalogColumnStatistics (org.apache.flink.table.catalog.stats.CatalogColumnStatistics)4 CatalogColumnStatisticsDataBase (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBase)4 CatalogColumnStatisticsDataBinary (org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataBinary)4 Date (org.apache.flink.table.catalog.stats.Date)4 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 LinkedHashMap (java.util.LinkedHashMap)1 TableException (org.apache.flink.table.api.TableException)1 TableSchema (org.apache.flink.table.api.TableSchema)1 CatalogTable (org.apache.flink.table.catalog.CatalogTable)1 CatalogTableImpl (org.apache.flink.table.catalog.CatalogTableImpl)1 HiveShim (org.apache.flink.table.catalog.hive.client.HiveShim)1 CatalogTableStatistics (org.apache.flink.table.catalog.stats.CatalogTableStatistics)1