drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [drill] vvysotskyi commented on a change in pull request #2005: DRILL-7477: Allow passing table function parameters into ANALYZE statement
Date Mon, 02 Mar 2020 08:34:13 GMT
vvysotskyi commented on a change in pull request #2005: DRILL-7477: Allow passing table function
parameters into ANALYZE statement
URL: https://github.com/apache/drill/pull/2005#discussion_r386248016
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DrillTableInfo.java
 ##########
 @@ -0,0 +1,171 @@
+/*
+ * 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.sql.handlers;
+
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.TranslatableTable;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlFunction;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.validate.SqlUserDefinedTableMacro;
+import org.apache.calcite.util.Util;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.planner.logical.DrillTable;
+import org.apache.drill.exec.planner.logical.DrillTranslatableTable;
+import org.apache.drill.exec.planner.sql.SchemaUtilites;
+import org.apache.drill.exec.store.AbstractSchema;
+import org.apache.drill.shaded.guava.com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * Holder class for {@link DrillTable}, {@code tableName} and table {@code schemaPath} obtained
from
+ * {@code SqlNode tableRef}.
+ */
+public class DrillTableInfo {
+  private static final Logger logger = LoggerFactory.getLogger(DrillTableInfo.class);
+
+  private final DrillTable drillTable;
+  private final String tableName;
+  private final List<String> schemaPath;
+
+  private DrillTableInfo(DrillTable drillTable, List<String> schemaPath, String tableName)
{
+    this.drillTable = drillTable;
+    this.tableName = tableName;
+    this.schemaPath = schemaPath;
+  }
+
+  public DrillTable drillTable() {
+    return drillTable;
+  }
+
+  public String tableName() {
+    return tableName;
+  }
+
+  public List<String> schemaPath() {
+    return schemaPath;
+  }
+
+  /**
+   * Returns {@link DrillTableInfo} instance which holds {@link DrillTable}, {@code drillTable},
+   * {@code schemaPath} corresponding to specified {@code tableRef}.
+   *
+   * @param tableRef table ref
+   * @param config   handler config
+   * @return {@link DrillTableInfo} instance
+   */
+  public static DrillTableInfo getTableInfoHolder(SqlNode tableRef, SqlHandlerConfig config)
{
+    switch (tableRef.getKind()) {
+      case COLLECTION_TABLE: {
+        SqlCall call = (SqlCall) config.getConverter().validate(tableRef);
+        assert call.getOperandList().size() == 1;
+        SqlOperator operator = ((SqlCall) call.operand(0)).getOperator();
+        assert operator instanceof SqlUserDefinedTableMacro;
+        SqlUserDefinedTableMacro tableMacro = (SqlUserDefinedTableMacro) operator;
+        SqlIdentifier tableIdentifier = tableMacro.getSqlIdentifier();
+
+        AbstractSchema drillSchema = SchemaUtilites.resolveToDrillSchema(
+            config.getConverter().getDefaultSchema(), SchemaUtilites.getSchemaPath(tableIdentifier));
+
+        TranslatableTable translatableTable = tableMacro.getTable(config.getConverter().getTypeFactory(),
prepareTableMacroOperands(call.operand(0)));
+        DrillTable table = ((DrillTranslatableTable) translatableTable).getDrillTable();
+        return new DrillTableInfo(table, drillSchema.getSchemaPath(), Util.last(tableIdentifier.names));
+      }
+      case IDENTIFIER: {
+        SqlIdentifier tableIdentifier = (SqlIdentifier) tableRef;
+        AbstractSchema drillSchema = SchemaUtilites.resolveToDrillSchema(
+            config.getConverter().getDefaultSchema(), SchemaUtilites.getSchemaPath(tableIdentifier));
+        String tableName = Util.last(tableIdentifier.names);
+        DrillTable table = getDrillTable(drillSchema, tableName);
+        return new DrillTableInfo(table, drillSchema.getSchemaPath(), tableName);
+      }
+      default:
+        throw new UnsupportedOperationException("Unsupported table ref kind: " + tableRef.getKind());
+    }
+  }
+
+  /**
+   * Returns list with operands for table function, obtained from specified call in the order,
 
 Review comment:
   Thanks, fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message