fix(transformer): reject a second = on a has-one list field

What does this MR do and why?

combine_expressions merges every clause that shares a field and operator. For has-one list fields such as id, iteration and the analytics user and flowType, that turned x = a and x = b into x in (a, b): the author's AND became an OR, with no error. The same happened to x = a and x in (b, c), since in collapses onto = before the merge.

The merge now refuses when = on such a field would produce more than one value, and points the author at in. Wildcards on a has-one field hit the same check. combine_values used to keep the left side when either value was a wildcard, so a second = slipped through whenever the wildcard came first. That rule is skipped on these fields.

query main this MR
id = 1 and id = 2 iids: ["1", "2"] error
id = 1 and id in (2, 3) iids: ["1", "2", "3"] error
id = 2 and id in (2, 3) iids: ["2", "3"] error
iteration = 1 and iteration = 2 iterationId: [1, 2] error
user = 1 and user = 2 (analytics) userId: [1, 2] error
milestone = ANY and milestone = NONE milestoneWildcardId: ANY error
milestone in ("a", "b") and milestone = upcoming milestoneTitle: ["a", "b"] error
milestone = upcoming and milestone in ("a", "b") milestoneWildcardId: UPCOMING error
assignee = ANY and assignee = NONE assigneeWildcardId: ANY unchanged, has-many wildcard wins
label = "foo" and label = "bar" labelName: ["foo", "bar"] unchanged, has-many
flowType != "a" and flowType != "b" workflowDefinitionNot: ["a", "b"] unchanged, negation
id in (1, 2) and id in (2, 3) DuplicateOperatorForField unchanged, rejected by the analyzer

The error reads "id can only match one value. To match any of several values, use a single id in (...)". The hint is deliberate: for id = 2 and id in (2, 3) the author meant {2}, and "put all the values in one in" would have steered them to the union.

The check lives in the merge step, not the analyzer, because the analyzer cannot tell milestone = %"a" and milestone = "a", which !537 (merged) deliberately folds into one filter, from id = 1 and id = 2. Two !537 (merged) tests pinned the union, test_repeated_numeric_inclusions_union and test_repeated_numeric_values_union. Both are inverted, as agreed on #210 (closed).

How to set up and validate locally

  1. cargo test

  2. On main, id = 1 and id = 2 on the MergeRequest source compiles to iids: ["1", "2"]. On this branch it errors with:

    Error: id can only match one value. To match any of several values, use a single id in (...).

  3. label = "foo" and label = "bar" still compiles to labelName: ["foo", "bar"], and flowType != "a" and flowType != "b" still merges into workflowDefinitionNot.

  4. milestone = upcoming and milestone in ("a", "b") errors in both clause orders. On main the first order compiled to milestoneWildcardId: UPCOMING.

Edited by Aditya Parida

Merge request reports

Loading
Loading