Datomic 数据记录:使用聚合时出现 ArrayIndexOutOfBounds 异常

Datomic datalog: ArrayIndexOutOfBounds Exception when using aggregates

鉴于 db 是一个数据库值,以下查询将引发异常:

(d/q 
  '[:find ?concert (count-distinct ?demand) 
    :in $ ?campaignId
    :with ?concert
    :where 
    [?c :campaign/id ?campaignId]
    [?concert :crowd-concert/campaign ?c]
    [?demand :demand/concert ?concert]
    ]
  db "546b7e0f2348f10200abf5ea")

(信息模型是一个campaign有几场演唱会,需求是,我们要获取演唱会的字段和每场演唱会的需求数量)

堆栈跟踪在这里:

java.lang.Exception: processing rule: (q__25764 ?concert ?demand ?concert), message: processing clause: [?demand :demand/concert ?concert], message: java.lang.ArrayIndexOutOfBoundsException: 2
    at datomic.datalog$eval_rule$fn__6161.invoke(datalog.clj:1441)
    at datomic.datalog$eval_rule.invoke(datalog.clj:1421)
    at datomic.datalog$eval_query.invoke(datalog.clj:1464)
    at datomic.datalog$qsqr.invoke(datalog.clj:1553)
    at datomic.datalog$qsqr.invoke(datalog.clj:1510)
    at datomic.query$q.invoke(query.clj:674)
    at datomic.api$q.doInvoke(api.clj:35)
    at clojure.lang.RestFn.invoke(RestFn.java:439)
    at bs.routes.campaigns$eval25762.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.Compiler.eval(Compiler.java:6782)
    at clojure.lang.Compiler.eval(Compiler.java:6745)
    at clojure.core$eval.invoke(core.clj:3081)
    at clojure.main$repl$read_eval_print__7099$fn__7102.invoke(main.clj:240)
    at clojure.main$repl$read_eval_print__7099.invoke(main.clj:240)
    at clojure.main$repl$fn__7108.invoke(main.clj:258)
    at clojure.main$repl.doInvoke(main.clj:258)
    at clojure.lang.RestFn.invoke(RestFn.java:1523)
    at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__1025.invoke(interruptible_eval.clj:53)
    at clojure.lang.AFn.applyToHelper(AFn.java:152)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:630)
    at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1868)
    at clojure.lang.RestFn.invoke(RestFn.java:425)
    at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:51)
    at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__1067$fn__1070.invoke(interruptible_eval.clj:183)
    at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__1060.invoke(interruptible_eval.clj:152)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.Exception: processing clause: [?demand :demand/concert ?concert], message: java.lang.ArrayIndexOutOfBoundsException: 2
    at datomic.datalog$eval_clause$fn__6135.invoke(datalog.clj:1387)
    at datomic.datalog$eval_clause.invoke(datalog.clj:1350)
    at datomic.datalog$eval_rule$fn__6161.invoke(datalog.clj:1436)
    ... 29 more
Caused by: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 2
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at clojure.core$deref_future.invoke(core.clj:2186)
    at clojure.core$deref.invoke(core.clj:2207)
    at clojure.core$mapv$fn__6727.invoke(core.clj:6616)
    at clojure.lang.PersistentVector.reduce(PersistentVector.java:333)
    at clojure.core$reduce.invoke(core.clj:6518)
    at clojure.core$mapv.invoke(core.clj:6616)
    at datomic.datalog$fn__5678.invoke(datalog.clj:588)
    at datomic.datalog$fn__5536$G__5508__5551.invoke(datalog.clj:51)
    at datomic.datalog$join_project_coll.invoke(datalog.clj:116)
    at datomic.datalog$fn__5607.invoke(datalog.clj:219)
    at datomic.datalog$fn__5515$G__5510__5530.invoke(datalog.clj:51)
    at datomic.datalog$eval_clause$fn__6135.invoke(datalog.clj:1356)
    ... 31 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
    at clojure.lang.RT.aset(RT.java:2326)
    at datomic.datalog$fn__5678$project__5749.invoke(datalog.clj:480)
    at datomic.datalog$fn__5678$join__5767.invoke(datalog.clj:578)
    at datomic.datalog$fn__5678$fn__5772$fn__5773.invoke(datalog.clj:588)
    at clojure.lang.AFn.applyToHelper(AFn.java:152)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.core$apply.invoke(core.clj:630)
    at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1868)
    at clojure.lang.RestFn.invoke(RestFn.java:425)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.RestFn.applyTo(RestFn.java:132)
    at clojure.core$apply.invoke(core.clj:634)
    at clojure.core$bound_fn_STAR_$fn__4439.doInvoke(core.clj:1890)
    at clojure.lang.RestFn.invoke(RestFn.java:397)
    at clojure.lang.AFn.call(AFn.java:18)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    ... 3 more

我是不是做错了什么?

删除 :with 子句解决了问题。

我对 Datalog 的了解还不足以知道确切原因,但我认为这是因为 ?concert:find:with 子句中存在一些冗余。