morrySnow commented on code in PR #28372: URL: https://github.com/apache/doris/pull/28372#discussion_r1429556804
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/FoundRows.java: ########## @@ -0,0 +1,110 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.rules.analysis; + +import org.apache.doris.catalog.Env; +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator; +import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; +import org.apache.doris.nereids.trees.expressions.functions.agg.Count; +import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.RelationId; +import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; +import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; +import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink; +import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * FoundRows support. + */ +public class FoundRows extends OneRewriteRuleFactory { + @Override + public Rule build() { + return logicalResultSink(logicalProject(logicalAggregate(logicalSubQueryAlias()))) + .thenApply(ctx -> { + String user = ctx.cascadesContext.getConnectContext().getQualifiedUser(); + if (user == null || !Env.getCurrentEnv().getAuth().isEnableFoundRows(user) + || ctx.cascadesContext.getConnectContext().getFoundRowsPlan() == null) { + return null; + } + LogicalResultSink<LogicalProject<LogicalAggregate<LogicalSubQueryAlias<Plan>>>> rs = ctx.root; + LogicalProject<LogicalAggregate<LogicalSubQueryAlias<Plan>>> project = rs.child(); + if (project.getProjects().size() != 1) { Review Comment: we need add more comment to explain limitations ########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Analyzer.java: ########## @@ -125,6 +127,8 @@ private static List<RewriteJob> buildAnalyzeJobs(Optional<CustomTableResolver> c topDown(new EliminateGroupByConstant()), topDown(new NormalizeAggregate()), bottomUp(new JoinCommute()), + topDown(new CalcFoundRows()), + topDown(new FoundRows()), Review Comment: we call setFoundRowsPlan in CalcFoundRows rule. and getFoundRowsPlan in FoundRows, so we need apply FoundRows in the head of CalcFoundRows ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/FoundRows.java: ########## @@ -0,0 +1,110 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.rules.analysis; + +import org.apache.doris.catalog.Env; +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator; +import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; +import org.apache.doris.nereids.trees.expressions.functions.agg.Count; +import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.RelationId; +import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; +import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.trees.plans.logical.LogicalProject; +import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink; +import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * FoundRows support. + */ +public class FoundRows extends OneRewriteRuleFactory { + @Override + public Rule build() { + return logicalResultSink(logicalProject(logicalAggregate(logicalSubQueryAlias()))) Review Comment: why this pattern? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
