40 mFilterExpression = parameters.
filter;
63 context = context ? context : &defaultContext;
65 std::unique_ptr<QgsExpression> expression;
76 if ( expression->hasParserError() || !expression->prepare( context ) )
82 lst.insert( fieldOrExpression );
84 lst = expression->referencedColumns();
86 request.
setFlags( ( expression && expression->needsGeometry() ) ?
94 if ( !mOrderBy.empty() )
97 if ( !mFilterExpression.isEmpty() )
102 QVariant::Type resultType = QVariant::Double;
115 return defaultValue( aggregate );
120 QVariant v = expression->evaluate( context );
121 resultType = v.type();
127 return calculate( aggregate, fit, resultType, attrNum, expression.get(), mDelimiter, context, ok );
132 QString normalized =
string.trimmed().toLower();
137 if ( normalized == QLatin1String(
"count" ) )
139 else if ( normalized == QLatin1String(
"count_distinct" ) )
141 else if ( normalized == QLatin1String(
"count_missing" ) )
143 else if ( normalized == QLatin1String(
"min" ) )
145 else if ( normalized == QLatin1String(
"max" ) )
147 else if ( normalized == QLatin1String(
"sum" ) )
149 else if ( normalized == QLatin1String(
"mean" ) )
151 else if ( normalized == QLatin1String(
"median" ) )
153 else if ( normalized == QLatin1String(
"stdev" ) )
155 else if ( normalized == QLatin1String(
"stdevsample" ) )
157 else if ( normalized == QLatin1String(
"range" ) )
159 else if ( normalized == QLatin1String(
"minority" ) )
161 else if ( normalized == QLatin1String(
"majority" ) )
163 else if ( normalized == QLatin1String(
"q1" ) )
165 else if ( normalized == QLatin1String(
"q3" ) )
167 else if ( normalized == QLatin1String(
"iqr" ) )
169 else if ( normalized == QLatin1String(
"min_length" ) )
171 else if ( normalized == QLatin1String(
"max_length" ) )
173 else if ( normalized == QLatin1String(
"concatenate" ) )
175 else if ( normalized == QLatin1String(
"concatenate_unique" ) )
177 else if ( normalized == QLatin1String(
"collect" ) )
179 else if ( normalized == QLatin1String(
"array_agg" ) )
194 QStringLiteral(
"count" ),
195 QCoreApplication::tr(
"Count" ),
196 QSet<QVariant::Type>()
197 << QVariant::DateTime
201 << QVariant::LongLong
202 << QVariant::ULongLong
207 QStringLiteral(
"count_distinct" ),
208 QCoreApplication::tr(
"Count Distinct" ),
209 QSet<QVariant::Type>()
210 << QVariant::DateTime
214 << QVariant::LongLong
215 << QVariant::ULongLong
220 QStringLiteral(
"count_missing" ),
221 QCoreApplication::tr(
"Count Missing" ),
222 QSet<QVariant::Type>()
223 << QVariant::DateTime
227 << QVariant::LongLong
232 QStringLiteral(
"min" ),
233 QCoreApplication::tr(
"Min" ),
234 QSet<QVariant::Type>()
235 << QVariant::DateTime
239 << QVariant::LongLong
240 << QVariant::ULongLong
246 QStringLiteral(
"max" ),
247 QCoreApplication::tr(
"Max" ),
248 QSet<QVariant::Type>()
249 << QVariant::DateTime
253 << QVariant::LongLong
254 << QVariant::ULongLong
260 QStringLiteral(
"sum" ),
261 QCoreApplication::tr(
"Sum" ),
262 QSet<QVariant::Type>()
265 << QVariant::LongLong
266 << QVariant::ULongLong
271 QStringLiteral(
"mean" ),
272 QCoreApplication::tr(
"Mean" ),
273 QSet<QVariant::Type>()
276 << QVariant::LongLong
277 << QVariant::ULongLong
282 QStringLiteral(
"median" ),
283 QCoreApplication::tr(
"Median" ),
284 QSet<QVariant::Type>()
291 QStringLiteral(
"stdev" ),
292 QCoreApplication::tr(
"Stdev" ),
293 QSet<QVariant::Type>()
296 << QVariant::LongLong
297 << QVariant::ULongLong
302 QStringLiteral(
"stdevsample" ),
303 QCoreApplication::tr(
"Stdev Sample" ),
304 QSet<QVariant::Type>()
307 << QVariant::LongLong
308 << QVariant::ULongLong
313 QStringLiteral(
"range" ),
314 QCoreApplication::tr(
"Range" ),
315 QSet<QVariant::Type>()
317 << QVariant::DateTime
320 << QVariant::LongLong
321 << QVariant::ULongLong
326 QStringLiteral(
"minority" ),
327 QCoreApplication::tr(
"Minority" ),
328 QSet<QVariant::Type>()
331 << QVariant::LongLong
332 << QVariant::ULongLong
338 QStringLiteral(
"majority" ),
339 QCoreApplication::tr(
"Majority" ),
340 QSet<QVariant::Type>()
343 << QVariant::LongLong
344 << QVariant::ULongLong
350 QStringLiteral(
"q1" ),
351 QCoreApplication::tr(
"Q1" ),
352 QSet<QVariant::Type>()
355 << QVariant::LongLong
356 << QVariant::ULongLong
361 QStringLiteral(
"q3" ),
362 QCoreApplication::tr(
"Q3" ),
363 QSet<QVariant::Type>()
366 << QVariant::LongLong
367 << QVariant::ULongLong
372 QStringLiteral(
"iqr" ),
373 QCoreApplication::tr(
"InterQuartileRange" ),
374 QSet<QVariant::Type>()
377 << QVariant::LongLong
378 << QVariant::ULongLong
383 QStringLiteral(
"min_length" ),
384 QCoreApplication::tr(
"Min Length" ),
385 QSet<QVariant::Type>()
390 QStringLiteral(
"max_length" ),
391 QCoreApplication::tr(
"Max Length" ),
392 QSet<QVariant::Type>()
397 QStringLiteral(
"concatenate" ),
398 QCoreApplication::tr(
"Concatenate" ),
399 QSet<QVariant::Type>()
404 QStringLiteral(
"collect" ),
405 QCoreApplication::tr(
"Collect" ),
406 QSet<QVariant::Type>()
410 QStringLiteral(
"array_agg" ),
411 QCoreApplication::tr(
"Array Aggregate" ),
412 QSet<QVariant::Type>()
428 return calculateArrayAggregate( fit, attr, expression, context );
431 switch ( resultType )
435 case QVariant::LongLong:
436 case QVariant::ULongLong:
437 case QVariant::Double:
446 return calculateNumericAggregate( fit, attr, expression, context, stat );
450 case QVariant::DateTime:
459 return calculateDateTimeAggregate( fit, attr, expression, context, stat );
462 case QVariant::UserType:
468 return calculateGeometryAggregate( fit, expression, context );
484 return concatenateStrings( fit, attr, expression, context,
delimiter );
491 return concatenateStrings( fit, attr, expression, context,
delimiter,
true );
501 return calculateStringAggregate( fit, attr, expression, context, stat );
669 Q_ASSERT( expression || attr >= 0 );
680 QVariant v = expression->
evaluate( context );
689 double val = s.statistic( stat );
690 return std::isnan( val ) ? QVariant() : val;
696 Q_ASSERT( expression || attr >= 0 );
707 QVariant v = expression->
evaluate( context );
716 return s.statistic( stat );
721 Q_ASSERT( expression );
724 QVector< QgsGeometry > geometries;
729 QVariant v = expression->
evaluate( context );
742 Q_ASSERT( expression || attr >= 0 );
753 QVariant v = expression->
evaluate( context );
754 result = v.toString();
761 if ( !unique || !results.contains( result ) )
784 return QVariantList();
811 Q_ASSERT( expression || attr >= 0 );
822 QVariant v = expression->
evaluate( context );
831 return s.statistic( stat );
837 Q_ASSERT( expression || attr >= 0 );
849 QVariant v = expression->
evaluate( context );