Convert between predicate options and collator expressions - #12329
Conversation
There was a problem hiding this comment.
Apparently this code was ported from GL JS code that will also need to be updated.
There was a problem hiding this comment.
Maybe slightly better would be:
length != 3 || (isArray(arrayMember(filter, 1)) || isArray(arrayMember(filter, 2)))There was a problem hiding this comment.
The reasoning being that the default should be "this is an expression", and we should scope the fallback to legacy filters as tightly as possible?
There was a problem hiding this comment.
The reasoning being that the default should be "this is an expression", and we should scope the fallback to legacy filters as tightly as possible?
Yeah, pretty much: sending as many inputs as possible through the expression parsing pipeline, since that will be more and more likely what users will be trying to write, and so expression-related validation messages are more likely to be useful
There was a problem hiding this comment.
Does this means 'Québec' =[] 'Quebec' will use a collator (and thus the current locale) vs. 'Québec' = 'Quebec' doing non-locale-aware comparison?
There was a problem hiding this comment.
As long as an option is specified in brackets, it’ll use a collator. To match Core Data behavior, I suppose we could default the locale to en-posix when c or d is specified unless l is also specified.
A literal =[] is invalid syntax; there has to be an option. NSPredicate will raise an exception immediately on initialization.
There was a problem hiding this comment.
I think the current behavior sounds right. 👍
There was a problem hiding this comment.
🤔 Now that I see this, I wonder if it makes sense to treat the core feature ("support styles using the collator expression") as a separate changelog entry from the platform-specific wrapper...
There was a problem hiding this comment.
That’s a good point; we normally mention the JSON equivalent when that’s also new.
There was a problem hiding this comment.
Updated the changelog entry.
There was a problem hiding this comment.
To make sure I'm understanding: if you wanted to explicitly do locale-sensitive comparison with something other than the current locale, you'd have to manually craft your expression, because NSPredicate only supports a binary "locale-sensitive"?
There was a problem hiding this comment.
That’s correct. The syntax would look something like this:
NSPredicate(format: "MGL_FUNCTION('==', 'QUEBEC', 'Québec', MGL_FUNCTION('collator', %@))", ["case-sensitive": false, "locale": "fr-CA"])There’s a couple things we could adjust at the SDK level, like allowing locale to be set to an NSLocale instead of a raw locale identifier. But my understanding is that we normally want developers to keep using the default collator for better performance, so maybe it doesn’t help much to simplify the locale-specific collator syntax.
There was a problem hiding this comment.
I made some last-minute changes so that this predicate would work:
- The collator options object is no longer wrapped in a
literalexpression when converting from NSExpression to JSON. - The
MGL_FUNCTION()syntax is used instead of the==[…]syntax when alocaleis specified.
421db04 to
e992355
Compare
When detecting an expression used as a filter, relax the check for expressions to allow comparison expressions to contain a fourth member for the collator.
e992355 to
aaac2a5
Compare
The
[c]and[d]options are now supported within comparison predicates for case and diacritic insensitivity, respectively. Along the way, the mbgl code that detects expressions in filters had to be updated to allow a collator as the third argument to a comparison expression.Fixes #12269. Working towards #11786.
/cc @ChrisLoer @fabian-guerra @anandthakker