Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-2131

Operator IN behaviour

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      The recently released realm-core caused a test failure in the Dart SDK:

      The important part of the test is:

      Unable to find source-code formatter for language: dart. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
          final results = realmObject.list.query(r"nullableDecimalProp IN $0 || stringProp IN $0", [
            ['text1', null, 2.2, 3] // Searching by different type of values and null
          ]);
      

      where realmObject.list is a list of embedded objects with a nullableDecimalProp (with type Decimal128?) and a stringProp (with type String).

      This query now throws an error, since you cannot compare nullableDecimalProp with 'text1' because of the type mismatch.

      This a change in semantics, and I believe one we should avoid. Let me try to explain.

      From a mathematical point of view, if x in X and y in Y, then both x and y in X union Y. If x can never be in Y does not change that fact. For the example above, just because nullabeDecimalProp can never be a String does not imply that it cannot be a member of a set, that happens to also contain {{String}}s.

      As I can understand this issue arise from the fact that IN in realm, semantically behave like a gigantic OR clause, so {{x in

      {y, z}

      }} is equivalent to x == z OR x == y. But I would argue that even such an expression should not throw as long as one of the sides can be true.

      Expected results

      Test should pass

      Actual Results

      00:02 +27 ~1 -1: Query embedded objects list with list argument with different type of values [E]
        RealmException: Cannot convert 'text1' to a unknown. Error code: 3015.
        package:realm_dart/src/native/realm_core.dart 142:11   _RealmCore.throwLastError.<fn>
        ...
      

      Steps & Code to Reproduce

      run dart test -j1 test/embedded_test.dart (on fx. release/2.2.1 branch)

      Core version

      Core version: v14.7.0

            Assignee:
            jorgen.edelbo@mongodb.com Jørgen Edelbo
            Reporter:
            unitosyncbot Unito Sync Bot
            AD Sync Client
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: