hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-23951) Support parameterized queries in WHERE/HAVING clause
Date Mon, 03 Aug 2020 22:39:00 GMT

     [ https://issues.apache.org/jira/browse/HIVE-23951?focusedWorklogId=465931&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-465931
]

ASF GitHub Bot logged work on HIVE-23951:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Aug/20 22:38
            Start Date: 03/Aug/20 22:38
    Worklog Time Spent: 10m 
      Work Description: vineetgarg02 commented on a change in pull request #1315:
URL: https://github.com/apache/hive/pull/1315#discussion_r464698359



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/drop/ExecuteStatementAnalyzer.java
##########
@@ -0,0 +1,377 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.drop;
+
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType;
+import org.apache.hadoop.hive.ql.exec.ExplainTask;
+import org.apache.hadoop.hive.ql.exec.FetchTask;
+import org.apache.hadoop.hive.ql.exec.FilterOperator;
+import org.apache.hadoop.hive.ql.exec.Operator;
+import org.apache.hadoop.hive.ql.exec.OperatorUtils;
+import org.apache.hadoop.hive.ql.exec.SelectOperator;
+import org.apache.hadoop.hive.ql.exec.SerializationUtilities;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.exec.tez.TezTask;
+import org.apache.hadoop.hive.ql.exec.vector.VectorSelectOperator;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.parse.type.ExprNodeDescExprFactory;
+import org.apache.hadoop.hive.ql.plan.BaseWork;
+import org.apache.hadoop.hive.ql.plan.ExprDynamicParamDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Analyzer for Execute statement.
+ * This analyzer
+ *  retreives cached {@link BaseSemanticAnalyzer},
+ *  makes copy of all tasks by serializing/deserializing it,
+ *  bind dynamic parameters inside cached {@link BaseSemanticAnalyzer} using values provided
+ */
+@DDLType(types = HiveParser.TOK_EXECUTE)
+public class ExecuteStatementAnalyzer extends BaseSemanticAnalyzer {
+
+  public ExecuteStatementAnalyzer(QueryState queryState) throws SemanticException {
+    super(queryState);
+  }
+
+  /**
+   * This class encapsulate all {@link Task} required to be copied.
+   * This is required because {@link FetchTask} list of {@link Task} may hold reference to
same
+   * objects (e.g. list of result files) and are required to be serialized/de-serialized
together.
+   */
+  private class PlanCopy {
+    FetchTask fetchTask;
+    List<Task<?>> tasks;
+
+    PlanCopy(FetchTask fetchTask, List<Task<?>> tasks) {
+      this.fetchTask = fetchTask;
+      this.tasks = tasks;
+    }
+
+    FetchTask getFetchTask() {
+      return fetchTask;
+    }
+
+    List<Task<?>> getTasks()  {
+      return tasks;
+    }
+  }
+
+  private String getQueryName(ASTNode root) {
+    ASTNode queryNameAST = (ASTNode)(root.getChild(1));
+    return queryNameAST.getText();
+  }
+
+  /**
+   * Utility method to create copy of provided object using kyro serialization/de-serialization.
+   */
+  private <T> T makeCopy(final Object task, Class<T> objClass) {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    SerializationUtilities.serializePlan(task, baos);
+
+    return SerializationUtilities.deserializePlan(
+        new ByteArrayInputStream(baos.toByteArray()), objClass);
+  }
+
+  /**
+   * Given a {@link BaseSemanticAnalyzer} (cached) this method make copies of all tasks
+   * (including {@link FetchTask}) and update the existing {@link ExecuteStatementAnalyzer}
+   */
+  private void createTaskCopy(final BaseSemanticAnalyzer cachedPlan) {
+    PlanCopy planCopy = new PlanCopy(cachedPlan.getFetchTask(), cachedPlan.getAllRootTasks());
+    planCopy = makeCopy(planCopy, planCopy.getClass());
+    this.setFetchTask(planCopy.getFetchTask());
+    this.rootTasks = planCopy.getTasks();
+  }
+
+  private String getParamLiteralValue(Map<Integer, ASTNode> paramMap, int paramIndex)
{
+    assert(paramMap.containsKey(paramIndex));
+    ASTNode node = paramMap.get(paramIndex);
+
+    if (node.getType() == HiveParser.StringLiteral) {
+      // remove quotes
+      return BaseSemanticAnalyzer.unescapeSQLString(node.getText());
+
+    } else {
+      return node.getText();
+    }
+  }
+
+  /**
+   * This method creates a constant expression to replace the given dynamic expression.
+   * @param dynamicExpr Expression node representing Dynamic expression
+   * @param typeInfo Type info used to create constant expression from ASTNode
+   * @param parameterMap Integer to AST node map
+   */
+  private ExprNodeConstantDesc getConstant(ExprDynamicParamDesc dynamicExpr, TypeInfo typeInfo,

Review comment:
       You are right, I will update the code.




----------------------------------------------------------------
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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 465931)
    Time Spent: 1h  (was: 50m)

> Support parameterized queries in WHERE/HAVING clause
> ----------------------------------------------------
>
>                 Key: HIVE-23951
>                 URL: https://issues.apache.org/jira/browse/HIVE-23951
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Query Planning
>            Reporter: Vineet Garg
>            Assignee: Vineet Garg
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message