Skip to content
Permalink
Browse files

provide parent to generic aggregate functions

  • Loading branch information
3nids authored and nyalldawson committed Oct 16, 2020
1 parent c21141b commit 28a85833955438220c5e0c4816c907f0eee429c2
Showing with 6 additions and 0 deletions.
  1. +4 −0 src/core/expression/qgsexpressionfunction.cpp
  2. +2 −0 tests/src/core/testqgsexpression.cpp
@@ -674,6 +674,7 @@ static QVariant fcnAggregate( const QVariantList &values, const QgsExpressionCon
{
return context->cachedValue( cacheKey );
}

QgsExpressionContext subContext( *context );
QgsExpressionContextScope *subScope = new QgsExpressionContextScope();
subScope->setVariable( QStringLiteral( "parent" ), context->feature() );
@@ -921,6 +922,9 @@ static QVariant fcnAggregateGeneric( QgsAggregateCalculator::Aggregate aggregate
bool ok = false;

QgsExpressionContext subContext( *context );
QgsExpressionContextScope *subScope = new QgsExpressionContextScope();
subScope->setVariable( QStringLiteral( "parent" ), context->feature() );
subContext.appendScope( subScope );
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok );

if ( !ok )
@@ -2194,6 +2194,8 @@ class TestQgsExpression: public QObject
QTest::newRow( "group by and filter named" ) << "sum(expression:=\"col1\", group_by:=\"col3\", filter:=\"col1\">=3)" << false << QVariant( 7 );
QTest::newRow( "group by expression" ) << "sum(\"col1\", \"col1\" % 2)" << false << QVariant( 14 );
QTest::newRow( "group by with null value" ) << "sum(\"col1\", \"col4\")" << false << QVariant( 8 );

QTest::newRow( "filter by @parent attribute in generic aggregate" ) << "maximum(\"col1\", filter:=\"col1\"<attribute(@parent,'col1'))" << false << QVariant( 3 );
}

void maptip_display_data()

0 comments on commit 28a8583

Please sign in to comment.
You can’t perform that action at this time.