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 <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
(cherry picked from commit 3b820d7774)
This commit is contained in:
stiga-huang
2020-07-07 11:01:52 +08:00
parent 4796d13f71
commit e41fc61a28

View File

@@ -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;
@@ -48,6 +49,8 @@ import org.apache.impala.catalog.Table;
import org.apache.impala.common.Pair;
import org.apache.impala.thrift.TSortingOrder;
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;
@@ -63,6 +66,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.,
@@ -139,7 +144,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.