mavo icon indicating copy to clipboard operation
mavo copied to clipboard

"Condense" function doesn't remove comas when there's no where condition {feature request}

Open GalinhaLX opened this issue 2 years ago • 1 comments

Hi

while testing queries on nested collections: (codepen based on cats demo)

it seems that condense function must have a where condition to properly work

Wouldn't it be nice to make it work also without it?

Sometimes, we just need to remove empty values, without a 'complicated' where to let right values appear

GalinhaLX avatar May 04 '22 03:05 GalinhaLX

I examined the issue @GalinhaLX faced and found that it's caused by the way Mavo treats absent values. Consider the following data:

{
  "cat": [
    {
      "name": "Vector",
      "age": 12
    },
    {
      "name": "Jean"
    }
  ]
}

In the Mavo Inspector, we can see that the (absent) age property of the second cat is treated by Mavo as text (an empty string):

Screen Shot 2022-05-04 at 10 04 41

And since "" != null and condense(list(12, null)) != condense(list(12, "")), we get 12, as a result of condense(age).

If I'm not mistaken, the where operator drops empty strings that's why condense(age where age) returns the expected result.

Since condense() is based on first(), to fix condense() we need to fix first() first. It looks like we need to decide whether "" and null are equal.

DmitrySharabin avatar May 04 '22 07:05 DmitrySharabin