Skip to content

Commit

Permalink
[fix](planner) statement run successful but log error msg in audit log (
Browse files Browse the repository at this point in the history
apache#24628)

legacy planner will set error msg when throw AnalysisException.
However, in some place, we catch these exception and muted them.
So, we should reset back error msg and error code.
  • Loading branch information
morrySnow authored Sep 20, 2023
1 parent 5a0ccd7 commit b02398b
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ public Expr getResultValue(boolean inView) throws AnalysisException {
targetExpr.setType(type);
}
} catch (AnalysisException ae) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
targetExpr = this;
} catch (NumberFormatException nfe) {
targetExpr = new NullLiteral();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.InvalidFormatException;
import org.apache.doris.nereids.util.DateUtils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TDateLiteral;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
Expand Down Expand Up @@ -680,6 +681,9 @@ protected void toThrift(TExprNode msg) {
try {
checkValueValid();
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
// If date value is invalid, set this to null
msg.node_type = TExprNodeType.NULL_LITERAL;
msg.setIsNullable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.common.io.Writable;
import org.apache.doris.persist.gson.GsonPostProcessable;
import org.apache.doris.persist.gson.GsonUtils;
import org.apache.doris.qe.ConnectContext;

import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
Expand Down Expand Up @@ -71,6 +72,9 @@ public FunctionCallExpr getExpr(Type type) {
try {
expr.analyzeImplForDefaultValue(type);
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
LOG.warn("analyzeImplForDefaultValue fail: {}", e);
}
return expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ public Expr evalExpr(Expr constExpr) {
try {
((DateLiteral) dateLiteral).checkValueValid();
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
return NullLiteral.create(dateLiteral.getType());
}
return dateLiteral;
} else {
return invoker.invoke(constExpr.getChildrenWithoutCast());
}
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
LOG.debug("failed to invoke", e);
return constExpr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.ConnectContext;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
Expand Down Expand Up @@ -124,6 +125,9 @@ public ArrayList<Expr> getGroupingExprs() {
try {
genGroupingExprs();
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
LOG.error("gen grouping expr error:", e);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.NotImplementedException;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TIntLiteral;
Expand Down Expand Up @@ -321,6 +322,9 @@ protected Expr uncheckedCastTo(Type targetType) throws AnalysisException {
res.setType(targetType);
return res;
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
//invalid date format. leave it to BE to cast it as NULL
}
} else if (targetType.isStringType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.rewrite.ExprRewriter;
import org.apache.doris.thrift.TQueryOptions;

Expand Down Expand Up @@ -449,6 +450,9 @@ protected void substituteOrdinalsAliases(List<Expr> exprs, String errorPrefix,
substituteExpr = expr.clone();
substituteExpr.analyze(analyzer);
} catch (AnalysisException ex) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
// then consider alias name
substituteExpr = expr.trySubstitute(aliasSMap, analyzer, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,9 @@ private void analyzeAggregation(Analyzer analyzer) throws AnalysisException {
excludeAliasSMap.removeByLhsExpr(expr);
} catch (AnalysisException ex) {
// according to case3, column name do not exist, keep alias name inside alias map
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
}
}
havingClauseAfterAnalyzed = havingClause.substitute(excludeAliasSMap, analyzer, false);
Expand Down Expand Up @@ -1838,6 +1841,9 @@ public void rewriteExprs(ExprRewriter rewriter) throws AnalysisException {
}
} catch (AnalysisException ex) {
//ignore any exception
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
}
rewriter.rewriteList(oriGroupingExprs, analyzer);
// after rewrite, need reset the analyze status for later re-analyze
Expand All @@ -1859,6 +1865,9 @@ public void rewriteExprs(ExprRewriter rewriter) throws AnalysisException {
}
} catch (AnalysisException ex) {
//ignore any exception
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
}
orderByElem.setExpr(rewriter.rewrite(orderByElem.getExpr(), analyzer));
// after rewrite, need reset the analyze status for later re-analyze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,9 @@ public void createTableAsSelect(CreateTableAsSelectStmt stmt) throws DdlExceptio
try {
FeNameFormat.checkColumnName(name);
} catch (AnalysisException exception) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
name = "_col" + (colNameIndex++);
}
TypeDef typeDef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ private void getSysVarDescExpr(Expr expr, Map<String, Expr> sysVarMap) {
VariableMgr.fillValue(ConnectContext.get().getSessionVariable(), (VariableExpr) expr);
literalExpr = ((VariableExpr) expr).getLiteralExpr();
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
LOG.warn("failed to get session variable value: " + ((VariableExpr) expr).getName());
}
}
Expand All @@ -279,6 +282,9 @@ private void getInfoFnExpr(Expr expr, Map<String, Expr> infoFnMap) {
literalExpr = LiteralExpr.create(str, type);
infoFnMap.put(expr.getId().toString(), literalExpr);
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
LOG.warn("failed to get const expr value from InformationFunction: {}", e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.ConnectContext;

/**
* Rewrite binary predicate.
Expand Down Expand Up @@ -101,6 +102,9 @@ private Expr rewriteBigintSlotRefCompareDecimalLiteral(Expr expr0, Type expr0Col
// case 3
return new BinaryPredicate(op, expr0.castTo(expr0ColumnType), newExpr);
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
// case 1
IntLiteral colTypeMinValue = IntLiteral.createMinValue(expr0ColumnType);
IntLiteral colTypeMaxValue = IntLiteral.createMaxValue(expr0ColumnType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.analysis.NullLiteral;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.ConnectContext;

/**
* this rule try to convert date expression, if date is invalid, it will be
Expand Down Expand Up @@ -65,6 +66,9 @@ public Expr apply(Expr expr, Analyzer analyzer, ExprRewriter.ClauseType clauseTy
dateLiteral.fromDateStr(dateStr);
expr.setChild(1, dateLiteral);
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
if (clauseType == ExprRewriter.ClauseType.OTHER_CLAUSE) {
return new NullLiteral();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.doris.analysis.Subquery;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.rewrite.ExprRewriter.ClauseType;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -98,6 +99,9 @@ public Expr apply(Expr expr, Analyzer analyzer, ClauseType clauseType) throws An
try {
childExpr = (LiteralExpr) childExpr.castTo(Type.DECIMALV2);
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
continue;
}
}
Expand All @@ -116,6 +120,9 @@ public Expr apply(Expr expr, Analyzer analyzer, ClauseType clauseType) throws An
newInList.add(newExpr);
}
} catch (AnalysisException ignored) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
// pass
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.MaterializedIndexMeta;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.ConnectContext;

import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -86,6 +87,9 @@ public static boolean sumArgumentEqual(Expr expr, Expr mvArgument) {
String rhs = mvArgument.toSqlWithoutTbl();
return lhs.equalsIgnoreCase(rhs);
} catch (AnalysisException e) {
if (ConnectContext.get() != null) {
ConnectContext.get().getState().reset();
}
return false;
}
}
Expand Down

0 comments on commit b02398b

Please sign in to comment.