Skip to content

String aggregate-related functions treat NULL and empty strings interchangeably #35433

Description

@suricactus

Describe the bug
Pretty much the title. I've attached the data layer I am using for calculation, but this screenshot summarizes the issue.
image
The results are scary when "concatenate" with delimiter is used, for exampleconcatenate(str, NULL, NULL, ' | ') or count_missing(str).
Expectations
I was expecting that NULL values are going to be omitted as they do not represent countable values. This is already the case for aggregates for numeric types.
Reading the documentation, especially on the count_missing, it states only NULL values should be counted.
https://docs.qgis.org/testing/en/docs/user_manual/working_with_vector/expression.html#aggregates-functions

Function Description
count Returns the count of matching features
count_distinct Returns the count of distinct values
count_missing Returns the count of missing (null) values

How to Reproduce

  1. load the attached layer
    aggr.zip
  2. this is the expression I'm using to display the result. Any other aggregate function is also affected.
'\ncount(int) ' || count("int") || 
'\ncounr(str) ' || count("str") ||
'\nmissing(int) ' || count_missing("int") || 
'\nmissing(str) ' || count_missing("str")

QGIS and OS versions
All QGIS3 versions on all platforms, it is in the very core of how statistics for strings work.
Additional context
Applying the fix breaks a few existing unit test, but also might break user expressions dependent on this bug.

Once we agree this is an issue, I already have a fix on my branch here:
suricactus@27264be

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugEither a bug report, or a bug fix. Let's hope for the latter!ExpressionsRelated to the QGIS expression engine or specific expression functions

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions