Fork me on GitHub
#xtdb
<
2021-12-16
>
furkan3ayraktar15:12:28

Is it possible to pass projection-spec for pull as a query argument? The following minimal example fails with an error Query didn't match expected structure:

(def pull-pattern
  [:xt/id
   :name
   :created-at])

(xt/q (xt/db node)
 '{:find  [(pull ?e pattern)]
   :in    [?name pattern]
   :where [[?e :name ?name]]}
 "example name" pull-pattern)
This one works normally:
(xt/q (xt/db node)
 '{:find  [(pull ?e [:xt/id :name :created-at])]
   :in    [?name]
   :where [[?e :name ?name]]}
 "example name")

refset15:12:12

Not currently, unfortunately, so you will have to construct the query dynamically:

(xt/q (xt/db node)
 {:find  [(list 'pull '?e pull-pattern)]
  :in    '[?name]
  :where '[[?e :name ?name]]}
 "example name")

refset15:12:27

you could also use the pull API as a separate step, or even create a custom function that does the work inside a subquery (e.g. something a little simpler than this https://gist.github.com/refset/a61a89cfb6bd505ed306a18a9132c62f ...but hopefully it gives some idea)

furkan3ayraktar15:12:54

Is there a huge difference (in terms of performance) between pulling within the query and using pull-many after getting all the results? E.g.:

(->> (xt/q db '{:find [?e]
                :in   [?name]
                :where [[?e :name ?name]]}
           "example name")
     (map first)
     (xt/pull-many db pull-pattern))

refset15:12:35

potentially not :thinking_face: but I recommend checking for your config anyway. However, if you use open-db instead of db it will help keep the gap smaller (if there is one)

furkan3ayraktar15:12:38

Thanks! My config is S3 for the document-store, mysql for the tx-log and rocksdb for the index-store at the moment, nothing fancy other than those 😄. I just started playing with XTDB today, we are evaluating it to see if it makes sense to migrate into.

👌 1
refset16:12:30

cool, good to know - happy to help 🙂

🙌 1
Steven Deobald20:12:41

@U2BDZ9JG3 Especially since you're a new XT user (who's likely to have plenty of relevant questions), I'll make a small request in here to add your question to https://discuss.xtdb.com/c/users/5 and point us to it. It may seem kind of silly and repetitive, but we're trying to gauge the usefulness of Discourse as an asynchronous, long-form, additive forum that retains searchable state. 🙂

Steven Deobald23:12:47

Including your config was a nice touch, especially since many early XT users get confused about pluggable storage. The example might really help them. 🙂

richiardiandrea16:12:03

Hi folks, question - is there a way to undelete an entity? We have a use case where we want for an entity to disappear from the queries (`xt/delete`) but preserve history so that we can return to it in case

refset18:12:14

Hey, there's no undelete operation, you simply have to scan for the version you want to bring back to life from (e.g.) entity-history and put it back in at the appropriate time range (you will want to specify start and end valid-times)

refset18:12:43

Maybe that is roughly what you mean already by your follow-up message but I wasn't sure 🙂 There is certainly some debate worth considering about whether/when to rely on delete for filtering out old data vs using a user-space :state or :deleted? field and doing the work as part of the joins. It depends on what your full range of queries are (since searching over time isn't supported within XT's Datalog today)

👍 1
richiardiandrea18:12:14

Ok sounds good, the only thing I am not seeing is why I also need the end time - cause my undelete would restore the entity from now to forever - unless I am missing something else

refset19:12:16

uh, yeah on second thoughts I think you're right 😅

richiardiandrea20:12:15

cool thank you Jeremy!

richiardiandrea20:12:43

Just one last question (I know I can and will try but) when I xt/delete and then xt/put with the same xt/id, do I add to the previous entity history?

refset21:12:44

yep, entities are correlated by ID, so the entity-history will show everything that uses the same ID

❤️ 1
richiardiandrea16:12:18

The alternative would be to use our :state field to handle that "in code"

Steven Deobald20:12:10

@U0C8489U6 Same request you've probably seen elsewhere in this Slack channel: if you have a minute, if you could add your question to https://discuss.xtdb.com/c/users/5 and point us to it, it may help future users. It may seem kind of silly and repetitive, but we're trying to gauge the usefulness of Discourse as an asynchronous, long-form, additive forum that retains searchable state. 🙂

richiardiandrea20:12:20

Oh yeah no I haven't noticed that, it's a good idea, I will do that

♥️ 1
❤️ 1
💙 1
💚 1
🙏 1
Steven Deobald23:12:57

Searchable corpus of knowledge, here we come. Thanks @U0C8489U6!

👍 1