You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2020/07/08 05:34:09 UTC

[impala] 02/02: IMPALA-9921: Change error messages in checking needsQuotes to TRACE level logs

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

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

commit 3b820d777442dbec244a924604f47952479c2fff
Author: stiga-huang <hu...@gmail.com>
AuthorDate: Tue Jul 7 11:01:52 2020 +0800

    IMPALA-9921: Change error messages in checking needsQuotes to TRACE level logs
    
    Impala planner uses the HiveLexer to check whether an ident needs to be
    quoted in toSql results. However, HiveLexer will print error messages to
    stderr which is redirected to impalad.ERROR, so they appear as ERROR
    level logs. Actually, they just mean HiveLexer can't parse the ident so
    they are not Hive keywords so don't need to be quoted. These error
    messages don't mean anything wrong so shouldn't be ERROR level logs.
    
    This patch overrides the HiveLexer used in ToSqlUtils to log the error
    messages to TRACE level logs.
    
    Tests
     * Manually verify the error messages don't appear in impalad.ERROR and
       are printed to TRACE level logs.
    
    Change-Id: I0e1b5d2963285dc9125d8e0b8ed25c4db6821e0b
    Reviewed-on: http://gerrit.cloudera.org:8080/16146
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 .../main/java/org/apache/impala/analysis/ToSqlUtils.java | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
index a0a3b4c..c983d3c 100644
--- a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
+++ b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.RecognitionException;
 import org.antlr.runtime.Token;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.ObjectUtils;
@@ -51,6 +52,8 @@ import org.apache.impala.common.Pair;
 import org.apache.impala.thrift.TSortingOrder;
 import org.apache.impala.util.AcidUtils;
 import org.apache.impala.util.KuduUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
@@ -66,6 +69,8 @@ import com.google.common.collect.Maps;
  * for creating identifier strings that are compatible with Hive or Impala.
  */
 public class ToSqlUtils {
+  private final static Logger LOG = LoggerFactory.getLogger(ToSqlUtils.class);
+
   // Table properties to hide when generating the toSql() statement
   // EXTERNAL, SORT BY [order], and comment are hidden because they are part of the
   // toSql result, e.g.,
@@ -142,7 +147,16 @@ public class ToSqlUtils {
     // So, do the check on an upper-case version of the identifier.
     // Hive uses ANTLRNoCaseStringStream to upper-case text, but that
     // class is a non-static inner class so we can't use it here.
-    HiveLexer hiveLexer = new HiveLexer(new ANTLRStringStream(ident.toUpperCase()));
+    // Overrides HiveLexer to print error messages to TRACE level logs (see IMPALA-9921).
+    HiveLexer hiveLexer = new HiveLexer(new ANTLRStringStream(ident.toUpperCase())) {
+      @Override
+      public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("Error in checking needsQuotes using HiveLexer {}: {}",
+              getErrorHeader(e), getErrorMessage(e, tokenNames));
+        }
+      }
+    };
     try {
       Token t = hiveLexer.nextToken();
       // Check that the lexer recognizes an identifier and then EOF.