15 package com.cloudera.impala.catalog;
19 import org.apache.hadoop.hive.metastore.api.BinaryColumnStatsData;
20 import org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData;
21 import org.apache.hadoop.hive.metastore.api.ColumnStatisticsData;
22 import org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData;
23 import org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData;
24 import org.apache.hadoop.hive.metastore.api.LongColumnStatsData;
25 import org.apache.hadoop.hive.metastore.api.StringColumnStatsData;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
31 import com.cloudera.impala.thrift.TColumnStats;
32 import com.google.common.base.Objects;
33 import com.google.common.base.Preconditions;
34 import com.google.common.collect.Sets;
40 private final static Logger
LOG = LoggerFactory.getLogger(ColumnStats.class);
85 Preconditions.checkNotNull(expr);
86 Preconditions.checkState(expr.getType().isValid());
88 stats.setNumDistinctValues(expr.getNumDistinctValues());
89 SlotRef slotRef = expr.unwrapSlotRef(
false);
90 if (slotRef == null)
return stats;
91 ColumnStats slotStats = slotRef.getDesc().getStats();
92 if (slotStats == null)
return stats;
93 stats.numNulls_ = slotStats.getNumNulls();
94 stats.avgSerializedSize_ = slotStats.getAvgSerializedSize();
95 stats.avgSize_ = slotStats.getAvgSize();
96 stats.maxSize_ = slotStats.getMaxSize();
122 public void setMaxSize(
long maxSize) { this.maxSize_ = maxSize; }
125 this.numDistinctValues_ = numDistinctValues;
127 public void setNumNulls(
long numNulls) { this.numNulls_ = numNulls; }
145 public boolean update(
Type colType, ColumnStatisticsData statsData) {
148 boolean isCompatible =
false;
151 isCompatible = statsData.isSetBooleanStats();
153 BooleanColumnStatsData boolStats = statsData.getBooleanStats();
163 isCompatible = statsData.isSetLongStats();
165 LongColumnStatsData longStats = statsData.getLongStats();
172 isCompatible = statsData.isSetDoubleStats();
174 DoubleColumnStatsData doubleStats = statsData.getDoubleStats();
182 isCompatible = statsData.isSetStringStats();
184 StringColumnStatsData stringStats = statsData.getStringStats();
187 maxSize_ = stringStats.getMaxColLen();
188 avgSize_ = Double.valueOf(stringStats.getAvgColLen()).floatValue();
193 isCompatible = statsData.isSetStringStats();
195 BinaryColumnStatsData binaryStats = statsData.getBinaryStats();
197 maxSize_ = binaryStats.getMaxColLen();
198 avgSize_ = Double.valueOf(binaryStats.getAvgColLen()).floatValue();
203 isCompatible = statsData.isSetDecimalStats();
205 DecimalColumnStatsData decimalStats = statsData.getDecimalStats();
211 Preconditions.checkState(
false,
212 "Unexpected column type: " + colType.toString());
224 return SUPPORTED_COL_TYPES.contains(scalarType.getPrimitiveType());
229 avgSize_ = Double.valueOf(stats.getAvg_size()).floatValue();
240 TColumnStats colStats =
new TColumnStats();
250 return Objects.toStringHelper(this.getClass())
double avgSerializedSize_
ColumnStats(Type colType)
static final Set< PrimitiveType > SUPPORTED_COL_TYPES
static ColumnStats fromExpr(Expr expr)
void setNumDistinctValues(long numDistinctValues)
ColumnStats add(ColumnStats other)
static boolean isSupportedColType(Type colType)
void setNumNulls(long numNulls)
long getNumDistinctValues()
PrimitiveType getPrimitiveType()
void update(Type colType, TColumnStats stats)
void setAvgSerializedSize(float avgSize)
boolean hasAvgSerializedSize()
double getAvgSerializedSize()
void setMaxSize(long maxSize)
boolean isFixedLengthType()
void initColStats(Type colType)
boolean hasNumDistinctValues()
boolean update(Type colType, ColumnStatisticsData statsData)