Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/729#discussion_r98108433
--- Diff:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/AnalyzeTableHandler.java
---
@@ -0,0 +1,256 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.sql.handlers;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.tools.RelConversionException;
+import org.apache.calcite.tools.ValidationException;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.common.logical.FormatPluginConfig;
+import org.apache.drill.exec.dotdrill.DotDrillType;
+import org.apache.drill.exec.physical.PhysicalPlan;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.planner.logical.DrillAnalyzeRel;
+import org.apache.drill.exec.planner.logical.DrillRel;
+import org.apache.drill.exec.planner.logical.DrillScreenRel;
+import org.apache.drill.exec.planner.logical.DrillStoreRel;
+import org.apache.drill.exec.planner.logical.DrillWriterRel;
+import org.apache.drill.exec.planner.logical.DrillTable;
+import org.apache.drill.exec.planner.physical.Prel;
+import org.apache.drill.exec.planner.sql.DirectPlan;
+import org.apache.drill.exec.planner.sql.SchemaUtilites;
+import org.apache.drill.exec.planner.sql.parser.SqlAnalyzeTable;
+import org.apache.drill.exec.store.AbstractSchema;
+import org.apache.drill.exec.store.dfs.DrillFileSystem;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.FormatSelection;
+import org.apache.drill.exec.store.dfs.NamedFormatPluginConfig;
+import org.apache.drill.exec.store.parquet.ParquetFormatConfig;
+import org.apache.drill.exec.util.Pointer;
+import org.apache.drill.exec.work.foreman.ForemanSetupException;
+import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.FileStatus;
+
+public class AnalyzeTableHandler extends DefaultSqlHandler {
+ private static final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(AnalyzeTableHandler.class);
+
+ public AnalyzeTableHandler(SqlHandlerConfig config, Pointer<String>
textPlan) {
+ super(config, textPlan);
+ }
+
+ @Override
+ public PhysicalPlan getPlan(SqlNode sqlNode)
+ throws ValidationException, RelConversionException, IOException,
ForemanSetupException {
+ final SqlAnalyzeTable sqlAnalyzeTable = unwrap(sqlNode,
SqlAnalyzeTable.class);
+
+ verifyNoUnsupportedFunctions(sqlAnalyzeTable);
+
+ SqlIdentifier tableIdentifier = sqlAnalyzeTable.getTableIdentifier();
+ SqlSelect scanSql = new SqlSelect(
+ SqlParserPos.ZERO, /* position */
+ SqlNodeList.EMPTY, /* keyword list */
+ getColumnList(sqlAnalyzeTable), /* select list */
+ tableIdentifier, /* from */
+ null, /* where */
+ null, /* group by */
+ null, /* having */
+ null, /* windowDecls */
+ null, /* orderBy */
+ null, /* offset */
+ null /* fetch */
+ );
+
+ final ConvertedRelNode convertedRelNode =
validateAndConvert(rewrite(scanSql));
+ final RelNode relScan = convertedRelNode.getConvertedNode();
+ final String tableName = sqlAnalyzeTable.getName();
+ final AbstractSchema drillSchema = SchemaUtilites.resolveToDrillSchema(
+ config.getConverter().getDefaultSchema(),
sqlAnalyzeTable.getSchemaPath());
+ Table table = SqlHandlerUtil.getTableFromSchema(drillSchema,
tableName);
+
+ if (table == null) {
+ throw UserException.validationError()
+ .message("No table with given name [%s] exists in schema [%s]",
tableName,
+ drillSchema.getFullSchemaName())
+ .build(logger);
+ }
+
+ if(! (table instanceof DrillTable)) {
+ return notSupported(tableName);
+ }
+
+ if (table instanceof DrillTable) {
+ DrillTable drillTable = (DrillTable) table;
+ final Object selection = drillTable.getSelection();
+ if (!(selection instanceof FormatSelection)) {
+ return notSupported(tableName);
+ }
+ // Do not support non-parquet tables
+ FormatSelection formatSelection = (FormatSelection) selection;
+ FormatPluginConfig formatConfig = formatSelection.getFormat();
+ if (!((formatConfig instanceof ParquetFormatConfig)
--- End diff --
It would be better to add an API to GroupScan interface for checking if the
underlying GroupScan supports statistics collection. For now, only
ParquetGroupScan will return true for that.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---