From b02398ba85cc46336db542d0def809c74ba1d1d6 Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:32:47 +0800 Subject: [PATCH] [fix](planner) statement run successful but log error msg in audit log (#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. --- .../main/java/org/apache/doris/analysis/CastExpr.java | 3 +++ .../main/java/org/apache/doris/analysis/DateLiteral.java | 4 ++++ .../org/apache/doris/analysis/DefaultValueExprDef.java | 4 ++++ .../org/apache/doris/analysis/ExpressionFunctions.java | 6 ++++++ .../java/org/apache/doris/analysis/GroupByClause.java | 4 ++++ .../main/java/org/apache/doris/analysis/IntLiteral.java | 4 ++++ .../main/java/org/apache/doris/analysis/QueryStmt.java | 4 ++++ .../main/java/org/apache/doris/analysis/SelectStmt.java | 9 +++++++++ .../org/apache/doris/datasource/InternalCatalog.java | 3 +++ .../java/org/apache/doris/rewrite/FoldConstantsRule.java | 6 ++++++ .../doris/rewrite/RewriteBinaryPredicatesRule.java | 4 ++++ .../org/apache/doris/rewrite/RewriteDateLiteralRule.java | 4 ++++ .../org/apache/doris/rewrite/RewriteInPredicateRule.java | 7 +++++++ .../apache/doris/rewrite/mvrewrite/MVExprEquivalent.java | 4 ++++ 14 files changed, 66 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java index 607a7e766e5fb9..461647123aa12d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java @@ -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(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java index f48aec0c0fe699..0a68664d7c1231 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java @@ -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; @@ -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); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExprDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExprDef.java index dcaa944e0d754e..30ab756bb51a56 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExprDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExprDef.java @@ -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; @@ -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; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java index 70f913e803edbb..008f9131964808 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java @@ -120,6 +120,9 @@ 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; @@ -127,6 +130,9 @@ public Expr evalExpr(Expr constExpr) { return invoker.invoke(constExpr.getChildrenWithoutCast()); } } catch (AnalysisException e) { + if (ConnectContext.get() != null) { + ConnectContext.get().getState().reset(); + } LOG.debug("failed to invoke", e); return constExpr; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java index 7e66ae85fa37bb..f6305e611da442 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java @@ -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; @@ -124,6 +125,9 @@ public ArrayList getGroupingExprs() { try { genGroupingExprs(); } catch (AnalysisException e) { + if (ConnectContext.get() != null) { + ConnectContext.get().getState().reset(); + } LOG.error("gen grouping expr error:", e); return null; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java index 6e7c5d6f21a3b3..5f1c90abd6dc3e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java @@ -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; @@ -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()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java index c705fc5ea93f8b..3850f594c90907 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/QueryStmt.java @@ -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; @@ -449,6 +450,9 @@ protected void substituteOrdinalsAliases(List 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); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index a159695246f560..10e54da3d221a5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -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); @@ -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 @@ -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 diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 9a17070c154780..5d94848dd42a8d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -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; diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java index 70b38a377a13c1..3bd22cdbf24e9f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java @@ -253,6 +253,9 @@ private void getSysVarDescExpr(Expr expr, Map 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()); } } @@ -279,6 +282,9 @@ private void getInfoFnExpr(Expr expr, Map 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()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java index 264b956700a4b6..b144520f830098 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRule.java @@ -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. @@ -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); diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteDateLiteralRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteDateLiteralRule.java index cda54130defbe5..a11999a07770e6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteDateLiteralRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteDateLiteralRule.java @@ -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 @@ -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 { diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java index acf26abffb5d02..c04ff432961574 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java @@ -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; @@ -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; } } @@ -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 } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/MVExprEquivalent.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/MVExprEquivalent.java index 49d299acf3dd58..b4bc6b4827ce43 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/MVExprEquivalent.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/MVExprEquivalent.java @@ -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; @@ -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; } }