amansinha100 commented on a change in pull request #729: Drill 1328: Support table statistics for Parquet URL: https://github.com/apache/drill/pull/729#discussion_r250691493
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillStatsTable.java ########## @@ -0,0 +1,428 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.planner.common; + +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelVisitor; +import org.apache.calcite.rel.core.TableScan; +import org.apache.drill.common.exceptions.DrillRuntimeException; +import org.apache.drill.common.expression.SchemaPath; +import org.apache.drill.common.logical.FormatPluginConfig; +import org.apache.drill.common.types.TypeProtos; +import org.apache.drill.exec.ops.QueryContext; +import org.apache.drill.exec.physical.PhysicalPlan; +import org.apache.drill.exec.planner.logical.DrillTable; +import org.apache.drill.exec.planner.sql.DirectPlan; +import org.apache.drill.exec.record.MajorTypeSerDe; +import org.apache.drill.exec.store.StoragePlugin; +import org.apache.drill.exec.store.dfs.FileSystemPlugin; +import org.apache.drill.exec.store.dfs.FormatPlugin; +import org.apache.drill.exec.store.dfs.FormatSelection; +import org.apache.drill.exec.store.parquet.ParquetFormatConfig; +import org.apache.drill.exec.util.ImpersonationUtil; +import org.apache.drill.shaded.guava.com.google.common.collect.Maps; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; + +/** + * Wraps the stats table info including schema and tableName. Also materializes stats from storage + * and keeps them in memory. + */ +public class DrillStatsTable { + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillStatsTable.class); + // All the statistics versions till date + public enum STATS_VERSION {V0, V1}; + // The current version + public static final STATS_VERSION CURRENT_VERSION = STATS_VERSION.V1; + private final FileSystem fs; + private final Path tablePath; + private final String schemaName; + private final String tableName; + private final Map<String, Long> ndv = Maps.newHashMap(); + private double rowCount = -1; + private boolean materialized = false; + private TableStatistics statistics = null; + + public DrillStatsTable(String schemaName, String tableName, Path tablePath, FileSystem fs) { + this.schemaName = schemaName; + this.tableName = tableName; + this.tablePath = tablePath; + this.fs = ImpersonationUtil.createFileSystem(ImpersonationUtil.getProcessUserName(), fs.getConf()); + } + + public String getSchemaName() { + return schemaName; + } + + public String getTableName() { + return tableName; + } + + /* + * Returns whether statistics have materialized or not i.e. were the table statistics successfully read + * from the persistent store? + */ + public boolean isMaterialized() { return materialized; } + /** + * Get number of distinct values of given column. If stats are not present for the given column, + * a null is returned. + * + * Note: returned data may not be accurate. Accuracy depends on whether the table data has changed after the + * stats are computed. + * + * @param col + * @return Review comment: return Double ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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