Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-202

RealmException Invalid predicate using IN query

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

      <!--- Questions: If you have questions about how to use Realm, please ask on -->
      <!--- StackOverflow: http://stackoverflow.com/questions/ask?tags=realm -->
      <!--- We monitor the realm tag. -->

      <!--- Feature Request: Just fill in the first two sections below. -->

      <!--- Bugs: To help you as fast as possible with an issue please describe your issue -->
      <!--- and the steps you have taken to reproduce it in as much detail as possible. -->

      <Unable to render embedded object: File (--- Thanks for helping us help you) not found. -->

      Goals

      I am trying to achieve the following query:

      AttributeCode = 'attributes_2' AND 
      Item.ItemId IN { '5e5a7eeac1c88db03896194b', '5e5a7eeac1c88db038961947', '5e5a7eeac1c88db038961949' } AND 
      ValueNumber = 101.999
      

      My schema looks like:

      Unable to find source-code formatter for language: csharp. 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
      class Item {
        [PrimaryKey]
        public string ItemId { get; set; }
        public IList<Attribute> { get; }
      }
      
      class Attribute {
        [Backlink(nameof(Item.Attributes))]
        public Item Item { get; }
        [Indexed]
        public string AttributeCode { get; }
        public string? ValueString { get; }
        public bool? ValueBoolean { get; }
        public double? ValueNumber { get; }
      }
      

      Unfortunately I cannot use a concrete implementation of the data models coming from our api, they are defined by customers, I just know each item has 0-many attributes. I have found it 15-20 times faster in my tests to query the Attribute realm directly and use the backlink to filter on item id rather than query the Item realm directly then use a subquery statement. I was testing using an OR'd statement previously for the item id e.g.

      AttributeCode = 'attributes_2' AND 
      ( Item.ItemId = '5e5a7eeac1c88db03896194b' OR Item.ItemId = '5e5a7eeac1c88db038961947' OR Item.ItemId = '5e5a7eeac1c88db038961949' ) AND 
      ValueNumber = 101.999
      

      does the realm .net sdk (or realm under the hood) not support the IN statement on a backlinked property?

      <!--- What are you trying to achieve? -->

      Expected Results

      For the filter to execute like the more verbose OR statement, the realm cheatsheet https://academy.realm.io/posts/nspredicate-cheatsheet/ suggests excessive use of OR is bad for performance and I may have up to 1k item ids.

      A side note, where can I go to find any useful realm query suggestions/recommendations with regards to performance? My data set is ~100k items and 1m attributes.

      <!--- What did you expect to happen? -->

      Actual Results

      I get the exception:

      Test	Duration	Traits	Error Message
      Realms.Exceptions.RealmException : AttributeCode = 'attributes_2' AND Item.ItemId IN { '5e5a7eeac1c88db03896194b', '5e5a7eeac1c88db038961947', '5e5a7eeac1c88db038961949' } AND ValueNumber = 101.999:1:50(50): Invalid predicate.
      

      <!--- What happened instead? -->
      <!--- e.g. the stack trace of a crash -->

      Steps to Reproduce

      <!--- What are steps we can follow to reproduce this issue? -->

      Code Sample

      <!--- Please provide a code sample or test case that highlights the issue. -->
      <!--- If relevant, include your model definitions. -->
      <!--- For larger code samples, links to external gists/repositories are preferred. -->
      <!--- Alternatively, you can share information confidentially via email at help@realm.io. -->
      <Unable to render embedded object: File (--- Full projects that we can compile and run ourselves are ideal) not found. -->

      Version of Realm and Tooling

      • Realm Object Server Version: ? (you can see this as well in Studio once connected to a Realm instance)
      • Flavor:
        • [ ] Realm Cloud
        • [x] Self-Hosted
      • Server OS & Version: ? (e.g. CentOS 6)
      • Client SDK Version: ?
      • Client OS & Version: ?

            Assignee:
            chris.bush@mongodb.com Chris Bush
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: