Not possible to pass more then one vector variable to or-join

The example schema:

(def schema
[
        {
          :db/ident :type
          :db/valueType :db.type/string
          :db/cardinality :db.cardinality/one
        }
        {
          :db/ident :typeCode
          :db/valueType :db.type/long
          :db/cardinality :db.cardinality/one
        }
        {
          :db/ident :typeId
          :db/valueType :db.type/long
          :db/cardinality :db.cardinality/one
        }
])


(d/transact conn schema)

Example data:

(def data [
  {
    :type "User"
    :typeCode 1
    :typeId 1
  }
  {
    :type "User"
    :typeCode 2
    :typeId 2
  }
])
(d/transact conn data)

The next query fails:

(d/q "[ 
:find ?e 
:in $ ?type [?typeIds ...] [?typeCodes ...] 
:where 
  [?e :type ?type]
  (or-join [?e ?typeCodes ?typeIds]
    [?e :typeCode ?typeCodes]
    [?e :typeId ?typeIds]
  )
]"
(d/db conn), "User" [1, 2], [1, 2])

then the next error happens:

Execution error (ArrayIndexOutOfBoundsException) at datomic.datalog/fn$project (datalog.clj:503).
Index 2 out of bounds for length 2

if to pass non vector variables:

(d/q "[ 
:find ?e 
:in $ ?type ?typeIds ?typeCodes
:where 
  [?e :type ?type]
  (or-join [?e ?typeIds ?typeCodes]
    [?e :typeCode ?typeCodes]
    [?e :typeId ?typeIds] 
  )
]"
(d/db conn), "User" 1, 1)

then all works.

P.S.

  1. Do not try to understand the any meaning in the schema and queries, it is just the quickest example to show the problem
  2. All failed queries are executed successfully when DB is empty
  3. Looks like the order of vector variables from :in section matters for the order of variables for rule-vars of or-join

if to execute

(d/q "[ 
:find ?e 
:in $ ?type [?typeCodes ...] [?typeIds ...] 
:where 
  [?e :type ?type]
  (or-join [?e ?typeCodes ?typeIds]
    [?e :typeCode ?typeCodes]
    [?e :typeId ?typeIds] 
    [(get-else $ ?e :typeId ?typeIds) ?someIds]
    [(get-else $ ?e :typeCode ?typeCodes) ?someCodes]
  )
]"
(d/db conn), "User" [1, 2], [1, 2])

when ?typeIds is the last listed in :in section and rule-vars then the next error happens:

:db.error/insufficient-binding [?typeIds] not bound in expression clause: [(get-else $ ?e :typeId ?typeIds) ?someIds]

datomic-on-prem:1.0.6202

2 Likes

@marshall @stu @jaret Guys, can it somehow related to

and

?

2 Likes

Hi @nikolayandr,

Regarding the general case of supplying two vectors to an or-join. I’ve reproduced the behavior and we are investigating for a resolution. We will update this thread and your case once we have more information. Thank you for the report!

Or-joins require that all inputs be bound. The get-else in this scenario is not binding one side of the or-join. Thus one side is unbound. I wanted to clarify that because even after we address the multiple vectors this approach would not work.

Thanks,
Jaret

1 Like

Thank you, @jaret . I believe Not possible to pass attributes as argument for fulltext used inside or-join also relates to this issue. Could you please let know whether it is the same issue, so that we could plan our future work, thanks.

1 Like

Hi @jaret / @nikolayandr just wondering if this question/bug was ever resolved? I think I’ve hit it. Easy work around for my use case, but curious non-the-less.

Thanks
Felix

1 Like

Hi @xlfe Thanks for checking in. We are targeting this fix for our next release, but we are currently working through items for that release. I cannot promise that any particular fix/feature will make the release, but the current plan is to work to incorporate this fix.

2 Likes

Thanks - sounds like its in the works which is great.

1 Like

Any update on this? I’m seeing the same problem in datomic-cloud

2 Likes

I see datomic-1-0-6610 still contains this issue, not sure but looks like Does not-join support working with collection variables? might be related to this issue

1 Like

Hi @jaret. Could you please tell me whether is there any updates on this issue?

1 Like

@jaret please tell us about any plans to release the fix for this issue

1 Like

@jaret is there any chance to get a fix for this issue?

1 Like

Any updates on this issue?

2 Likes