From 2097e9a485da01e61d606e081ffa8fbcbccdc86b Mon Sep 17 00:00:00 2001 From: asfernandes Date: Thu, 18 Feb 2010 16:55:38 +0000 Subject: [PATCH] Fixed some inconsistencies with aggregate functions with more than one parameter --- src/dsql/AggNodes.cpp | 4 +++- src/dsql/ExprNodes.cpp | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/dsql/AggNodes.cpp b/src/dsql/AggNodes.cpp index 151d3ee9eb..7a952df5e1 100644 --- a/src/dsql/AggNodes.cpp +++ b/src/dsql/AggNodes.cpp @@ -144,7 +144,9 @@ bool AggNode::dsqlAggregateFinder(AggregateFinder& visitor) aggregate = true; else { - // Check also for a nested aggregate that could belong to this context + // Check also for a nested aggregate that could belong to this context. Example: + // select (select count(count(outer.n)) from inner) from outer + AutoSetRestore autoDeepestLevel(&visitor.deepestLevel, localDeepestLevel); for (dsql_nod*** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) diff --git a/src/dsql/ExprNodes.cpp b/src/dsql/ExprNodes.cpp index 2e5d13206a..b41e978b23 100644 --- a/src/dsql/ExprNodes.cpp +++ b/src/dsql/ExprNodes.cpp @@ -434,7 +434,9 @@ bool OverNode::dsqlAggregateFinder(AggregateFinder& visitor) AggNode* aggNode = ExprNode::as(dsqlAggExpr); fb_assert(aggNode); - aggregate |= visitor.visit(&aggNode->dsqlArg); + Array& exprChildren = aggNode->dsqlChildNodes; + for (dsql_nod*** i = exprChildren.begin(); i != exprChildren.end(); ++i) + aggregate |= visitor.visit(*i); } else aggregate |= visitor.visit(&dsqlAggExpr); @@ -514,13 +516,16 @@ bool OverNode::dsqlFieldRemapper(FieldRemapper& visitor) AggNode* aggNode = ExprNode::as(copy); fb_assert(aggNode); - dsql_nod*& aggExpr = aggNode->dsqlArg; + Array& exprChildren = aggNode->dsqlChildNodes; - if (Aggregate2Finder::find(visitor.context->ctx_scope_level, FIELD_MATCH_TYPE_EQUAL, - true, aggExpr)) + for (dsql_nod*** i = exprChildren.begin(); i != exprChildren.end(); ++i) { - ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << - Arg::Gds(isc_dsql_agg_nested_err)); + if (Aggregate2Finder::find(visitor.context->ctx_scope_level, FIELD_MATCH_TYPE_EQUAL, + true, **i)) + { + ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << + Arg::Gds(isc_dsql_agg_nested_err)); + } } AggregateFinder aggFinder(dsqlScratch, false); @@ -531,12 +536,13 @@ bool OverNode::dsqlFieldRemapper(FieldRemapper& visitor) { if (!visitor.window) { - if (copy->nod_count) - { + { // scope AutoSetRestore autoPartitionNode2(&visitor.partitionNode, NULL); AutoSetRestore autoOrderNode2(&visitor.orderNode, NULL); - visitor.visit(&aggExpr); + Array& exprChildren = aggNode->dsqlChildNodes; + for (dsql_nod*** i = exprChildren.begin(); i != exprChildren.end(); ++i) + visitor.visit(*i); } if (dsqlPartition)