This is an automated email from the ASF dual-hosted git repository.

dkuzmenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 26ed33a274d HIVE-22618: Fix checkstyle violations for ParseUtils 
(okumin, reviewed by Denys Kuzmenko)
26ed33a274d is described below

commit 26ed33a274df242228bda5313e72a14db0e7c9ae
Author: okumin <[email protected]>
AuthorDate: Tue Aug 29 20:09:31 2023 +0900

    HIVE-22618: Fix checkstyle violations for ParseUtils (okumin, reviewed by 
Denys Kuzmenko)
    
    Closes #4451
---
 .../apache/hadoop/hive/ql/parse/ParseUtils.java    | 467 +++++++++++----------
 .../hadoop/hive/ql/parse/TestParseUtils.java       |   8 +-
 2 files changed, 243 insertions(+), 232 deletions(-)

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 61b6f67c968..04483dc9ff3 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
@@ -224,8 +224,8 @@ public final class ParseUtils {
       int i = filterCondn.getType() == HiveParser.TOK_FUNCTION ? 1 : 0;
       for (; i < filterCondn.getChildCount(); i++) {
         int cIdx = checkJoinFilterRefersOneAlias(tabAliases, (ASTNode) 
filterCondn.getChild(i));
-        if ( cIdx != idx ) {
-          if ( idx != -1 && cIdx != -1 ) {
+        if (cIdx != idx) {
+          if (idx != -1 && cIdx != -1) {
             return -1;
           }
           idx = idx == -1 ? cIdx : idx;
@@ -238,23 +238,23 @@ public final class ParseUtils {
   public static DecimalTypeInfo getDecimalTypeTypeInfo(ASTNode node)
       throws SemanticException {
     if (node.getChildCount() > 2) {
-        throw new SemanticException("Bad params for type decimal");
-      }
+      throw new SemanticException("Bad params for type decimal");
+    }
 
-      int precision = HiveDecimal.USER_DEFAULT_PRECISION;
-      int scale = HiveDecimal.USER_DEFAULT_SCALE;
+    int precision = HiveDecimal.USER_DEFAULT_PRECISION;
+    int scale = HiveDecimal.USER_DEFAULT_SCALE;
 
-      if (node.getChildCount() >= 1) {
-        String precStr = node.getChild(0).getText();
-        precision = Integer.parseInt(precStr);
-      }
+    if (node.getChildCount() >= 1) {
+      String precStr = node.getChild(0).getText();
+      precision = Integer.parseInt(precStr);
+    }
 
-      if (node.getChildCount() == 2) {
-        String scaleStr = node.getChild(1).getText();
-        scale = Integer.parseInt(scaleStr);
-      }
+    if (node.getChildCount() == 2) {
+      String scaleStr = node.getChild(1).getText();
+      scale = Integer.parseInt(scaleStr);
+    }
 
-      return TypeInfoFactory.getDecimalTypeInfo(precision, scale);
+    return TypeInfoFactory.getDecimalTypeInfo(precision, scale);
   }
 
   public static String ensureClassExists(String className)
@@ -271,249 +271,260 @@ public final class ParseUtils {
   }
 
   public static boolean containsTokenOfType(ASTNode root, Integer ... tokens) {
-      final Set<Integer> tokensToMatch = new HashSet<Integer>();
-      for (Integer tokenTypeToMatch : tokens) {
-          tokensToMatch.add(tokenTypeToMatch);
-        }
+    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 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;
     }
 
-    private static void handleSetColRefs(ASTNode tree, Context ctx) {
-      CalcitePlanner.ASTSearcher astSearcher = new 
CalcitePlanner.ASTSearcher();
-      while (true) {
-        astSearcher.reset();
-        ASTNode setCols = astSearcher.depthFirstSearch(tree, 
HiveParser.TOK_SETCOLREF);
-        if (setCols == null) break;
-        processSetColsNode(setCols, astSearcher, ctx);
+    return false;
+  }
+
+  private static void handleSetColRefs(ASTNode tree, Context ctx) {
+    CalcitePlanner.ASTSearcher astSearcher = new CalcitePlanner.ASTSearcher();
+    while (true) {
+      astSearcher.reset();
+      ASTNode setCols = astSearcher.depthFirstSearch(tree, 
HiveParser.TOK_SETCOLREF);
+      if (setCols == null) {
+        break;
       }
+      processSetColsNode(setCols, astSearcher, ctx);
     }
+  }
 
-    /**
-     * Replaces a spurious TOK_SETCOLREF added by parser with column names 
referring to the query
-     * in e.g. a union. This is to maintain the expectations that some code, 
like order by position
-     * alias, might have about not having ALLCOLREF. If it cannot find the 
columns with confidence
-     * it will just replace SETCOLREF with ALLCOLREF. Most of the cases where 
that happens are
-     * easy to work around in the query (e.g. by adding column aliases in the 
union).
-     * @param setCols TOK_SETCOLREF ASTNode.
-     * @param searcher AST searcher to reuse.
-     */
-    private static void processSetColsNode(ASTNode setCols, ASTSearcher 
searcher, Context ctx) {
-      searcher.reset();
-      CommonTree rootNode = setCols;
-      while (rootNode != null && rootNode.getType() != HiveParser.TOK_INSERT) {
-        rootNode = rootNode.parent;
-      }
-      if (rootNode == null || rootNode.parent == null) {
-        // Couldn't find the parent insert; replace with ALLCOLREF.
-        LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the root INSERT");
-        setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-        return;
+  /**
+   * Replaces a spurious TOK_SETCOLREF added by parser with column names 
referring to the query
+   * in e.g. a union. This is to maintain the expectations that some code, 
like order by position
+   * alias, might have about not having ALLCOLREF. If it cannot find the 
columns with confidence
+   * it will just replace SETCOLREF with ALLCOLREF. Most of the cases where 
that happens are
+   * easy to work around in the query (e.g. by adding column aliases in the 
union).
+   * @param setCols TOK_SETCOLREF ASTNode.
+   * @param searcher AST searcher to reuse.
+   */
+  private static void processSetColsNode(ASTNode setCols, ASTSearcher 
searcher, Context ctx) {
+    searcher.reset();
+    CommonTree rootNode = setCols;
+    while (rootNode != null && rootNode.getType() != HiveParser.TOK_INSERT) {
+      rootNode = rootNode.parent;
+    }
+    if (rootNode == null || rootNode.parent == null) {
+      // Couldn't find the parent insert; replace with ALLCOLREF.
+      LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the root INSERT");
+      setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+      return;
+    }
+    rootNode = rootNode.parent; // TOK_QUERY above insert
+    Tree fromNode = null;
+    for (int j = 0; j < rootNode.getChildCount(); ++j) {
+      Tree child = rootNode.getChild(j);
+      if (child.getType() == HiveParser.TOK_FROM) {
+        fromNode = child;
+        break;
       }
-      rootNode = rootNode.parent; // TOK_QUERY above insert
-      Tree fromNode = null;
-      for (int j = 0; j < rootNode.getChildCount(); ++j) {
-        Tree child = rootNode.getChild(j);
-        if (child.getType() == HiveParser.TOK_FROM) {
-          fromNode = child;
-          break;
+    }
+    if (!(fromNode instanceof ASTNode)) {
+      // Couldn't find the from that contains subquery; replace with ALLCOLREF.
+      LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the FROM");
+      setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+      return;
+    }
+    // We are making what we are trying to do more explicit if there's a union 
alias; so
+    // that if we do something we didn't expect to do, it'd be more likely to 
fail.
+    String alias = null;
+    if (fromNode.getChildCount() > 0) {
+      Tree fromWhat = fromNode.getChild(0);
+      if (fromWhat.getType() == HiveParser.TOK_SUBQUERY && 
fromWhat.getChildCount() > 1) {
+        Tree child = fromWhat.getChild(fromWhat.getChildCount() - 1);
+        if (child.getType() == HiveParser.Identifier) {
+          alias = child.getText();
         }
       }
-      if (!(fromNode instanceof ASTNode)) {
-        // Couldn't find the from that contains subquery; replace with 
ALLCOLREF.
-        LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the FROM");
+    }
+    // Note: we assume that this isn't an already malformed query;
+    //       we don't check for that here - it will fail later anyway.
+    // First, we find the SELECT closest to the top.
+    ASTNode select = searcher.simpleBreadthFirstSearchAny((ASTNode)fromNode,
+        HiveParser.TOK_SELECT, HiveParser.TOK_SELECTDI);
+    if (select == null) {
+      // Couldn't find the from that contains subquery; replace with ALLCOLREF.
+      LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the SELECT");
+      setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+      return;
+    }
+
+    // Then, find the leftmost logical sibling select, because that's what 
Hive uses for aliases.
+    while (true) {
+      CommonTree queryOfSelect = select.parent;
+      while (queryOfSelect != null && queryOfSelect.getType() != 
HiveParser.TOK_QUERY) {
+        queryOfSelect = queryOfSelect.parent;
+      }
+      // We should have some QUERY; and also its parent because by supposition 
we are in subq.
+      if (queryOfSelect == null || queryOfSelect.parent == null) {
+        LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the QUERY");
         setCols.token.setType(HiveParser.TOK_ALLCOLREF);
         return;
       }
-      // We are making what we are trying to do more explicit if there's a 
union alias; so
-      // that if we do something we didn't expect to do, it'd be more likely 
to fail.
-      String alias = null;
-      if (fromNode.getChildCount() > 0) {
-        Tree fromWhat = fromNode.getChild(0);
-        if (fromWhat.getType() == HiveParser.TOK_SUBQUERY && 
fromWhat.getChildCount() > 1) {
-          Tree child = fromWhat.getChild(fromWhat.getChildCount() - 1);
-          if (child.getType() == HiveParser.Identifier) {
-            alias = child.getText();
-          }
-        }
+      if (queryOfSelect.childIndex == 0) {
+        break; // We are the left-most child.
       }
-      // Note: we assume that this isn't an already malformed query;
-      //       we don't check for that here - it will fail later anyway.
-      // First, we find the SELECT closest to the top.
-      ASTNode select = searcher.simpleBreadthFirstSearchAny((ASTNode)fromNode,
+      Tree moreToTheLeft = queryOfSelect.parent.getChild(0);
+      Preconditions.checkState(moreToTheLeft != queryOfSelect);
+      ASTNode newSelect = 
searcher.simpleBreadthFirstSearchAny((ASTNode)moreToTheLeft,
           HiveParser.TOK_SELECT, HiveParser.TOK_SELECTDI);
-      if (select == null) {
-        // Couldn't find the from that contains subquery; replace with 
ALLCOLREF.
-        LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't find 
the SELECT");
-        setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-        return;
-      }
+      Preconditions.checkState(newSelect != select);
+      select = newSelect;
+      // Repeat the procedure for the new select.
+    }
 
-      // Then, find the leftmost logical sibling select, because that's what 
Hive uses for aliases.
-      while (true) {
-        CommonTree queryOfSelect = select.parent;
-        while (queryOfSelect != null && queryOfSelect.getType() != 
HiveParser.TOK_QUERY) {
-          queryOfSelect = queryOfSelect.parent;
-        }
-        // We should have some QUERY; and also its parent because by 
supposition we are in subq.
-        if (queryOfSelect == null || queryOfSelect.parent == null) {
-          LOG.debug("Replacing SETCOLREF with ALLCOLREF because we couldn't 
find the QUERY");
+    // Find the proper columns.
+    List<ASTNode> newChildren = new ArrayList<>(select.getChildCount());
+    Set<String> aliases = new HashSet<>();
+    for (int i = 0; i < select.getChildCount(); ++i) {
+      Tree selExpr = select.getChild(i);
+      if (selExpr.getType() == HiveParser.QUERY_HINT) {
+        continue;
+      }
+      assert selExpr.getType() == HiveParser.TOK_SELEXPR;
+      assert selExpr.getChildCount() > 0;
+      // we can have functions which generate multiple aliases (e.g. 
explode(map(x, y)) as (key, val))
+      boolean isFunctionWithMultipleParameters =
+          selExpr.getChild(0).getType() == HiveParser.TOK_FUNCTION && 
selExpr.getChildCount() > 2;
+      // if so let's skip the function token buth then examine all its 
parameters - otherwise check only the last item
+      int start = isFunctionWithMultipleParameters ? 1 : 
selExpr.getChildCount() - 1;
+      for (int j = start; j < selExpr.getChildCount(); ++j) {
+        Tree child = selExpr.getChild(j);
+        switch (child.getType()) {
+        case HiveParser.TOK_SETCOLREF:
+          // We have a nested setcolref. Process that and start from scratch 
TODO: use stack?
+          processSetColsNode((ASTNode) child, searcher, ctx);
+          processSetColsNode(setCols, searcher, ctx);
+          return;
+        case HiveParser.TOK_ALLCOLREF:
+          // We should find an alias of this insert and do (alias).*. This 
however won't fix e.g.
+          // positional order by alias case, cause we'd still have a star on 
the top level. Bail.
+          LOG.debug("Replacing SETCOLREF with ALLCOLREF because of nested 
ALLCOLREF");
           setCols.token.setType(HiveParser.TOK_ALLCOLREF);
           return;
-        }
-        if (queryOfSelect.childIndex == 0) break; // We are the left-most 
child.
-        Tree moreToTheLeft = queryOfSelect.parent.getChild(0);
-        Preconditions.checkState(moreToTheLeft != queryOfSelect);
-        ASTNode newSelect = 
searcher.simpleBreadthFirstSearchAny((ASTNode)moreToTheLeft,
-          HiveParser.TOK_SELECT, HiveParser.TOK_SELECTDI);
-        Preconditions.checkState(newSelect != select);
-        select = newSelect;
-        // Repeat the procedure for the new select.
-      }
-
-      // Find the proper columns.
-      List<ASTNode> newChildren = new ArrayList<>(select.getChildCount());
-      HashSet<String> aliases = new HashSet<>();
-      for (int i = 0; i < select.getChildCount(); ++i) {
-        Tree selExpr = select.getChild(i);
-        if (selExpr.getType() == HiveParser.QUERY_HINT) continue;
-        assert selExpr.getType() == HiveParser.TOK_SELEXPR;
-        assert selExpr.getChildCount() > 0;
-        // we can have functions which generate multiple aliases (e.g. 
explode(map(x, y)) as (key, val))
-        boolean isFunctionWithMultipleParameters =
-            selExpr.getChild(0).getType() == HiveParser.TOK_FUNCTION && 
selExpr.getChildCount() > 2;
-        // if so let's skip the function token buth then examine all its 
parameters - otherwise check only the last item
-        int start = isFunctionWithMultipleParameters ? 1 : 
selExpr.getChildCount() - 1;
-        for (int j = start; j < selExpr.getChildCount(); ++j) {
-          Tree child = selExpr.getChild(j);
-          switch (child.getType()) {
-            case HiveParser.TOK_SETCOLREF:
-              // We have a nested setcolref. Process that and start from 
scratch TODO: use stack?
-              processSetColsNode((ASTNode) child, searcher, ctx);
-              processSetColsNode(setCols, searcher, ctx);
-              return;
-            case HiveParser.TOK_ALLCOLREF:
-              // We should find an alias of this insert and do (alias).*. This 
however won't fix e.g.
-              // positional order by alias case, cause we'd still have a star 
on the top level. Bail.
-              LOG.debug("Replacing SETCOLREF with ALLCOLREF because of nested 
ALLCOLREF");
-              setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-              return;
-            case HiveParser.TOK_TABLE_OR_COL:
-              Tree idChild = child.getChild(0);
-              assert idChild.getType() == HiveParser.Identifier : idChild;
-              if (!createChildColumnRef(idChild, alias, newChildren, aliases, 
ctx)) {
-                setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-                return;
-              }
-              break;
-            case HiveParser.Identifier:
-              if (!createChildColumnRef(child, alias, newChildren, aliases, 
ctx)) {
-                setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-                return;
-              }
-              break;
-            case HiveParser.DOT: {
-              Tree colChild = child.getChild(child.getChildCount() - 1);
-              assert colChild.getType() == HiveParser.Identifier : colChild;
-              if (!createChildColumnRef(colChild, alias, newChildren, aliases, 
ctx)) {
-                setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-                return;
-              }
-              break;
-            }
-            default:
-              // Not really sure how to refer to this (or if we can).
-              // TODO: We could find a different from branch for the union, 
that might have an alias?
-              //       Or we could add an alias here to refer to, but that 
might break other branches.
-              LOG.debug("Replacing SETCOLREF with ALLCOLREF because of the 
nested node "
-                  + child.getType() + " " + child.getText());
-              setCols.token.setType(HiveParser.TOK_ALLCOLREF);
-              return;
+        case HiveParser.TOK_TABLE_OR_COL:
+          Tree idChild = child.getChild(0);
+          assert idChild.getType() == HiveParser.Identifier : idChild;
+          if (!createChildColumnRef(idChild, alias, newChildren, aliases, 
ctx)) {
+            setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+            return;
+          }
+          break;
+        case HiveParser.Identifier:
+          if (!createChildColumnRef(child, alias, newChildren, aliases, ctx)) {
+            setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+            return;
+          }
+          break;
+        case HiveParser.DOT:
+          Tree colChild = child.getChild(child.getChildCount() - 1);
+          assert colChild.getType() == HiveParser.Identifier : colChild;
+          if (!createChildColumnRef(colChild, alias, newChildren, aliases, 
ctx)) {
+            setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+            return;
           }
+          break;
+        default:
+          // Not really sure how to refer to this (or if we can).
+          // TODO: We could find a different from branch for the union, that 
might have an alias?
+          //       Or we could add an alias here to refer to, but that might 
break other branches.
+          LOG.debug("Replacing SETCOLREF with ALLCOLREF because of the nested 
node "
+              + child.getType() + " " + child.getText());
+          setCols.token.setType(HiveParser.TOK_ALLCOLREF);
+          return;
         }
       }
-      // Insert search in the beginning would have failed if these parents 
didn't exist.
-      ASTNode parent = (ASTNode)setCols.parent.parent;
-      int t = parent.getType();
-      assert t == HiveParser.TOK_SELECT || t == HiveParser.TOK_SELECTDI : t;
-      int ix = setCols.parent.childIndex;
-      parent.deleteChild(ix);
-      for (ASTNode node : newChildren) {
-        parent.insertChild(ix++, node);
-      }
     }
+    // Insert search in the beginning would have failed if these parents 
didn't exist.
+    ASTNode parent = (ASTNode)setCols.parent.parent;
+    int t = parent.getType();
+    assert t == HiveParser.TOK_SELECT || t == HiveParser.TOK_SELECTDI : t;
+    int ix = setCols.parent.childIndex;
+    parent.deleteChild(ix);
+    for (ASTNode node : newChildren) {
+      parent.insertChild(ix++, node);
+    }
+  }
+
+  private static boolean createChildColumnRef(Tree child, String alias,
+      List<ASTNode> newChildren, Set<String> aliases, Context ctx) {
+    String colAlias = child.getText();
+    if (SemanticAnalyzer.isRegex(colAlias, (HiveConf)ctx.getConf())) {
+      LOG.debug("Skip creating child column reference because of regexp used 
as alias: " + colAlias);
+      return false;
+    }
+    if (!aliases.add(colAlias)) {
+      // TODO: if a side of the union has 2 columns with the same name, none 
on the higher
+      //       level can refer to them. We could change the alias in the 
original node.
+      LOG.debug("Replacing SETCOLREF with ALLCOLREF because of duplicate alias 
" + colAlias);
+      return false;
+    }
+    ASTBuilder selExpr = ASTBuilder.construct(HiveParser.TOK_SELEXPR, 
"TOK_SELEXPR");
+    ASTBuilder toc = ASTBuilder.construct(HiveParser.TOK_TABLE_OR_COL, 
"TOK_TABLE_OR_COL");
+    ASTBuilder id = ASTBuilder.construct(HiveParser.Identifier, colAlias);
+    if (alias == null) {
+      selExpr = selExpr.add(toc.add(id));
+    } else {
+      ASTBuilder dot = ASTBuilder.construct(HiveParser.DOT, ".");
+      ASTBuilder aliasNode = ASTBuilder.construct(HiveParser.Identifier, 
alias);
+      selExpr = selExpr.add(dot.add(toc.add(aliasNode)).add(id));
+    }
+    newChildren.add(selExpr.node());
+    return true;
+  }
 
-    private static boolean createChildColumnRef(Tree child, String alias,
-        List<ASTNode> newChildren, HashSet<String> aliases, Context ctx) {
-      String colAlias = child.getText();
-      if (SemanticAnalyzer.isRegex(colAlias, (HiveConf)ctx.getConf())) {
-        LOG.debug("Skip creating child column reference because of regexp used 
as alias: " + colAlias);
-        return false;
+  public static String getKeywords(Set<String> excludes) {
+    StringBuilder sb = new StringBuilder();
+    for (Field f : HiveLexer.class.getDeclaredFields()) {
+      if (!Modifier.isStatic(f.getModifiers())) {
+        continue;
       }
-      if (!aliases.add(colAlias)) {
-        // TODO: if a side of the union has 2 columns with the same name, none 
on the higher
-        //       level can refer to them. We could change the alias in the 
original node.
-        LOG.debug("Replacing SETCOLREF with ALLCOLREF because of duplicate 
alias " + colAlias);
-        return false;
+      String name = f.getName();
+      if (!name.startsWith("KW_")) {
+        continue;
       }
-      ASTBuilder selExpr = ASTBuilder.construct(HiveParser.TOK_SELEXPR, 
"TOK_SELEXPR");
-      ASTBuilder toc = ASTBuilder.construct(HiveParser.TOK_TABLE_OR_COL, 
"TOK_TABLE_OR_COL");
-      ASTBuilder id = ASTBuilder.construct(HiveParser.Identifier, colAlias);
-      if (alias == null) {
-        selExpr = selExpr.add(toc.add(id));
-      } else {
-        ASTBuilder dot = ASTBuilder.construct(HiveParser.DOT, ".");
-        ASTBuilder aliasNode = ASTBuilder.construct(HiveParser.Identifier, 
alias);
-        selExpr = selExpr.add(dot.add(toc.add(aliasNode)).add(id));
+      name = name.substring(3);
+      if (excludes != null && excludes.contains(name)) {
+        continue;
       }
-      newChildren.add(selExpr.node());
-      return true;
-    }
-
-    public static String getKeywords(Set<String> excludes) {
-      StringBuilder sb = new StringBuilder();
-      for (Field f : HiveLexer.class.getDeclaredFields()) {
-        if (!Modifier.isStatic(f.getModifiers())) continue;
-        String name = f.getName();
-        if (!name.startsWith("KW_")) continue;
-        name = name.substring(3);
-        if (excludes != null && excludes.contains(name)) continue;
-        if (sb.length() > 0) {
-          sb.append(",");
-        }
-        sb.append(name);
+      if (sb.length() > 0) {
+        sb.append(",");
       }
-      return sb.toString();
+      sb.append(name);
     }
+    return sb.toString();
+  }
 
   public static CBOPlan parseQuery(HiveConf conf, String viewQuery)
       throws SemanticException, ParseException {
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java 
b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java
index fb433c09045..696311df25d 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java
@@ -120,26 +120,26 @@ public class TestParseUtils {
   @Test
   public void testTxnTypeWithEnabledReadOnlyFeature() throws Exception {
     enableReadOnlyTxnFeature(true);
-    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query,new 
Context(conf))), txnType);
+    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query, new 
Context(conf))), txnType);
   }
 
   @Test
   public void testTxnTypeWithDisabledReadOnlyFeature() throws Exception {
     enableReadOnlyTxnFeature(false);
-    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query,new 
Context(conf))),
+    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query, new 
Context(conf))),
         txnType == TxnType.READ_ONLY ? TxnType.DEFAULT : txnType);
   }
 
   @Test
   public void testTxnTypeWithLocklessReadsEnabled() throws Exception {
     enableLocklessReadsFeature(true);
-    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query,new 
Context(conf))), txnType);
+    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query, new 
Context(conf))), txnType);
   }
 
   @Test
   public void testTxnTypeWithLocklessReadsDisabled() throws Exception {
     enableLocklessReadsFeature(false);
-    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query,new 
Context(conf))), TxnType.DEFAULT);
+    Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query, new 
Context(conf))), TxnType.DEFAULT);
   }
   
   private void enableReadOnlyTxnFeature(boolean featureFlag) {

Reply via email to