This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-30
Channels
- # announcements (41)
- # aws (2)
- # aws-lambda (1)
- # babashka (51)
- # babashka-sci-dev (15)
- # beginners (56)
- # calva (15)
- # cider (8)
- # clojars (6)
- # clojure (107)
- # clojure-dev (6)
- # clojure-europe (33)
- # clojure-france (3)
- # clojure-nl (4)
- # clojure-sg (2)
- # clojure-uk (8)
- # clojurescript (16)
- # cursive (11)
- # data-oriented-programming (1)
- # datomic (4)
- # events (11)
- # fulcro (15)
- # graphql (6)
- # helix (17)
- # holy-lambda (1)
- # improve-getting-started (14)
- # integrant (39)
- # jobs (14)
- # lsp (36)
- # malli (3)
- # nrepl (8)
- # off-topic (26)
- # other-languages (1)
- # polylith (21)
- # portal (7)
- # practicalli (17)
- # re-frame (7)
- # react (4)
- # reitit (1)
- # remote-jobs (6)
- # sci (1)
- # shadow-cljs (45)
- # spacemacs (12)
- # tools-deps (5)
- # xtdb (26)
I want to run parameterized queries like the one below.
(xt/q (xt/db node) '{:find [(pull e [:bios.provider/id :xt/id])]
:where [[e :hud/entity :hud.calendar/team]
(or-join
[e ?name ?abbr]
(and
[fid :hud/provider "gizmo"]
[e :gizmo.provider/id fid]
[(text-search :gizmo/abbreviation ?abbr) [[fid]]]
[fid :xt/id]
[(any? ?name)])
(and
[e :hud/provider "hud"]
[(text-search :hud/name ?name) [[e]]]
[e :xt/id])
(and
[fid :hud/provider "gizmo"]
[e :gizmo.provider/id fid]
[(text-search :gizmo/name ?name) [[fid]]]
[fid :xt/id]
[(any? ?abbr)]))]
:in [[?name ?abbr]]}
[name abbr])
But sometimes the `abbr` var is nil and causes lucene to throw ParseException errors. Changing nil values to empty string does not work. One solution is to check if `abbr` is nil then use a different query
(xt/q (xt/db node) '{:find [(pull e [:bios.provider/id :xt/id])]
:where [[e :hud/entity :hud.calendar/team]
(or-join
[e ?name]
(and
[e :hud/provider "hud"]
[(text-search :hud/name ?name) [[e]]]
[e :xt/id])
(and
[fid :hud/provider "gizmo"]
[e :gizmo.provider/id fid]
[(text-search :gizmo/name ?name) [[fid]]]
[fid :xt/id]))]
:in [[?name ?abbr]]}
[name])
Is there a way to disable an or
leg with nil parametersHi, I think you could try adding a predicate in the relevant leg(s) to guard against that, i.e. [(some? abbr)]
> Changing nil values to empty string does not work
I'd be curious to see what you attempted for this, as I would expect it to be another valid approach. Was it converting nil
-> ""
before passing into :in
and running the actual query?
EDIT: Ah I see, text-search
accepts ""
fine but Lucene itself will throw a parsing error. Hmm. Maybe that's a sensible default and should be left alone, I'm not sure :thinking_face:
ah, I suppose there's no way (currently) for the query planner to know to prioritise the some?
clause ahead of the text-search
something else I think you could try as a fairly hacky workaround (while I think of something better) - instead of replacing nil
with ""
, replace it with "averyveryveryverylongstringthatdefinitelywontreturnanyresults"
This works. I'll go with the hacky solution for now. Better than writing a separate query for every combination of nil parameter values
with the hacky workaround you'll still be hitting the lucene search, you could avoid that with the dynamic query approach
I would've thought that and
would short circuit as it does in clojure, but it makes sense that the planner reorders things
I wonder if some variant of and
that works as a planner fence would be possible, like (and-short-circuit clause1 ... clauseN)
(with a better name perhaps)
:thinking_face: or even a guard in a predicate form like [(text-search :name ?name) [[e]] :when ?name]
sorry for the delayed response (blame the Slack DNS outage last night!)...
A key idea of Datalog (and XT's Datalog included), is that it is declarative, which isn't really compatible with traditional notions of conditionals & control flow. I agree though that and
is counter-intuitive when you're used to clojure.core/and
datomic doesn't have a planner that rearranges forms, so datalog doesn't preclude that imo
is there documentation what are valid types for values? also what values can be compared with >
(and similar)
XT will happily store and index anything which can be serialised via https://github.com/ptaoussanis/nippy (including many funky Java object types), however you are right to ask about byte-comparable types. The list as it stands today is only defined in the codec.clj namespace, e.g. https://github.com/xtdb/xtdb/blob/a7907f35d55ce8935da0b93c7f6752e0a615010c/core/src/xtdb/codec.clj#L82-L100
We haven't documented this much mainly because the exact supported schema is still subject to roadmap changes. Also note that there are edge cases when using the range predicates (`>` etc.) where value type boundaries are not necessarily intuitive, e.g. comparing across numbers https://github.com/xtdb/xtdb/issues/1298
You can also handle your own userspace byte encodings and store byte-arrays, since https://github.com/xtdb/xtdb/pull/1168
yeah, I was mainly concerned about the comparability... because I had tried ju.Date, jt.LocalDate and Time and those seemed to work, those seem to be supported specifically
if the comparison can't be done by just pulling from the index, will it revert to deserializing all and calling compare on them, or fail?
The byte-wise comparison will still be done, since bytes are always available, but it will be ~meaningless. You can always replace > with clojure.core/> though to get the more familiar semantics (and comparison failures!) with the cost of deserialising each value and comparing every possible entry in the index one by one
Clear datatype docs have been on the ol' todo list for quite some time. There will be a bit of hardening around datatypes with xtdb v2 so it's likely we won't publish strict formal docs until that point. Apologies for sending you to the source for now.