hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject [31/50] [abbrv] hive git commit: HIVE-10190: CBO: AST mode checks for TABLESAMPLE with AST.toString().contains("TOK_TABLESPLITSAMPLE")
Date Wed, 20 May 2015 16:01:50 GMT
HIVE-10190: CBO: AST mode checks for TABLESAMPLE with AST.toString().contains("TOK_TABLESPLITSAMPLE")


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/037559fd
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/037559fd
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/037559fd

Branch: refs/heads/parquet
Commit: 037559fd74c1a2d3ab6eee094ebce7934f3b9f39
Parents: b28d394
Author: Sergio Pena <sergio.pena@cloudera.com>
Authored: Mon May 18 10:06:38 2015 -0500
Committer: Sergio Pena <sergio.pena@cloudera.com>
Committed: Mon May 18 10:06:38 2015 -0500

----------------------------------------------------------------------
 .../ql/optimizer/calcite/HiveCalciteUtil.java   | 14 +++----
 .../apache/hadoop/hive/ql/parse/ParseUtils.java | 42 ++++++++++++++++++--
 2 files changed, 45 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/037559fd/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java
index 372c93d..f4e7c45 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java
@@ -58,6 +58,8 @@ import org.apache.hadoop.hive.ql.metadata.VirtualColumn;
 import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject;
 import org.apache.hadoop.hive.ql.optimizer.calcite.translator.ExprNodeConverter;
 import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.ParseUtils;
 import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
 
 import com.google.common.base.Function;
@@ -95,15 +97,11 @@ public class HiveCalciteUtil {
   }
 
   public static boolean validateASTForUnsupportedTokens(ASTNode ast) {
-    String astTree = ast.toStringTree();
-    // if any of following tokens are present in AST, bail out
-    String[] tokens = { "TOK_CHARSETLITERAL", "TOK_TABLESPLITSAMPLE" };
-    for (String token : tokens) {
-      if (astTree.contains(token)) {
-        return false;
-      }
+    if (ParseUtils.containsTokenOfType(ast, HiveParser.TOK_CHARSETLITERAL, HiveParser.TOK_TABLESPLITSAMPLE))
{
+      return false;
+    } else {
+      return true;
     }
-    return true;
   }
 
   public static List<RexNode> getProjsFromBelowAsInputRef(final RelNode rel) {

http://git-wip-us.apache.org/repos/asf/hive/blob/037559fd/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java
index 373429c..18f0180 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java
@@ -18,15 +18,15 @@
 
 package org.apache.hadoop.hive.ql.parse;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import org.apache.hadoop.hive.common.JavaUtils;
 import org.apache.hadoop.hive.common.type.HiveDecimal;
 import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.exec.PTFUtils;
 import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.lib.Node;
 import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
 import org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo;
 import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
@@ -229,5 +229,41 @@ public final class ParseUtils {
     return className;
   }
 
+  public static boolean containsTokenOfType(ASTNode root, Integer ... tokens) {
+      final Set<Integer> tokensToMatch = new HashSet<Integer>();
+      for (Integer tokenTypeToMatch : tokens) {
+          tokensToMatch.add(tokenTypeToMatch);
+        }
+
+        return ParseUtils.containsTokenOfType(root, new PTFUtils.Predicate<ASTNode>()
{
+          @Override
+          public boolean apply(ASTNode node) {
+              return tokensToMatch.contains(node.getType());
+            }
+        });
+    }
+
+    public static boolean containsTokenOfType(ASTNode root, PTFUtils.Predicate<ASTNode>
predicate) {
+      Queue<ASTNode> queue = new ArrayDeque<ASTNode>();
+
+      // BFS
+      queue.add(root);
+      while (!queue.isEmpty())  {
+        ASTNode current = queue.remove();
+        // If the predicate matches, then return true.
+        // Otherwise visit the next set of nodes that haven't been seen.
+        if (predicate.apply(current)) {
+          return true;
+        } else {
+          // Guard because ASTNode.getChildren.iterator returns null if no children available
(bug).
+          if (current.getChildCount() > 0) {
+            for (Node child : current.getChildren()) {
+              queue.add((ASTNode) child);
+            }
+          }
+        }
+      }
 
+      return false;
+    }
 }


Mime
View raw message