Skip to content

mergeForEach wrongly calls innerCallback when rhsItem can't be compared with lhsItem #21

@Sumolari

Description

@Sumolari

Related internal issue » https://geoblink.atlassian.net/browse/CORE-7255

If rhsCollection has items which do not have a value for primary key and lhsCollection have primary key for all items, then the comparison between the element without primary key and any element of the other collection will return SORTING_ORDER.EQUAL because the else branch of this chunk will be executed:

      if (lhsValue < rhsValue) {
        return SORTING_ORDER.LHS_BEFORE_RHS
      } else if (lhsValue > rhsValue) {
        return SORTING_ORDER.LHS_AFTER_RHS
      } else {
        return SORTING_ORDER.EQUAL
      }

However, this comparison is false. It's not entirely clear if this example is breaking some precondition on the API but it can be fixed in the algorithm by adding a new value return value, null whenever values can't be compared.

      if (lhsValue < rhsValue) {
        return SORTING_ORDER.LHS_BEFORE_RHS
      } else if (lhsValue > rhsValue) {
        return SORTING_ORDER.LHS_AFTER_RHS
      } else if (lhsValue === rhsValue) {
        return SORTING_ORDER.EQUAL
      } else {
        return SORTING_ORDER.UNCOMPARABLE
      }

If a pair is not comparable then we should not caller innerCallback for it. At the end we'll end up calling leftCallback and rightCallback on each member of the pair, according to their actual position.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions