Fork me on GitHub
#xtdb
<
2020-05-17
>
mmer11:05:28

Hi I am wondering how I can find out what is wrong with a document being added to the db, which shows a committed transaction but I can'y retrieve its entity?

refset11:05:09

Hi, do you know what the document looks like? Does it have a value for :crux.db/id ?

refset11:05:07

You should at least be able to retrieve the document from the tx-log

refset11:05:03

If you forgot to add an ID then your confusion that may be the result of a small regression introduced in the last release, that's now fixed on master https://github.com/juxt/crux/commit/3d186a7773f4ecbe2e402b6c6bf9e77e6646cb82 discussed in the last few days in this channel history

mmer12:05:23

Thanks for the quick answer - could you give me an example of how get documents from the tx-log?

Eric Ihli13:05:07

You can find the transaction that is showing committed but that you can't retrieve with open-tx-log, like this for example (take 3 (iterator-seq (crux/open-tx-log adb/conn 40 true)))

Eric Ihli13:05:35

Scroll up to the chat on Thursday, May 14th, for discussion on how to fix the document if the problem is that it doesn't have a crux.db/id key.

mmer14:05:43

Thanks Eric, I know the id, but it does not get returned when I do the entity check.

mmer14:05:24

and tx-committed? return true

refset14:05:58

Are you using await-tx before checking? Or is this in the repl?

mmer14:05:43

Another question I have is about queries. In Sparql you can do an "s p o" However `(crux/q (crux/db db) '{:find [s p o] :where [[s p o]]})` Doe not seem to work with crux? Any ideas? Linked to this is the fact that I want to query with an argument being passed in the 'o' position.

refset14:05:01

Crux' indexes don't currently support variables in the attribute positions of triple clauses. The main justification being that in the vast majority of use-cases all attributes will be known ahead of time, but the benefits are significant in simplifying the query algorithm and minimising disk space. Therefore for certain inference-heavy domain use-cases Crux is probably not appropriate as things stand today. A workaround for doing ad-hoc exploration of data with the current functionality is to look at attribute-stats and generate queries based on that (though they may be slow!) We may well (optionally) support variable attributes in a future release but we have no immediate plans.

refset14:05:26

I hope that makes sense, but I would be keen to hear about your use-case anyway 🙂

Eric Ihli14:05:42

^ This is something I also tried once I started playing around with code, after having gone through the tutorials. I scanned the docs to confirm it wasn't supposed to work and never saw anything. Just another anecdotal data point for what newcomers experience.

👀 4
mmer14:05:24

Being able to get the attribute names associated with the data allows for creating table heading in UI and reports etc, without having to know them in advance.

mmer14:05:01

Linked with this I would like to know how to optionally return a value if it exists but nothing if it does not

mmer14:05:50

Or set a default when it does not exist

Eric Ihli16:05:02

Can getting the attribute names without knowing them in advance be done some other way? If you know the type of thing that you you want to report on, then you must know one of it's attributes. Since there are no "tables" you can't really use database introspection to dynamically get the names of columns of a table. It's not like you have a "user" table and a "cars" table, each with different columns. Each object that you model is defined by its attributes. So if you want to report on something, you must know at least the attribute that identifies what "type" it is. You could give each entity a "type" attribute. Then you don't need to know the other attributes ahead of time. You could write some shared reporting code that given a type would get all entities that have :data/type :user or :data/type :car and then generate column headers for your UI based on the set of attributes of each collection

Eric Ihli16:05:54

And {:find [s p o] :where [[s p o]]} would just return everything, yeah? Every entity must have a crux.db/id key, so that's almost the same thing as {:find [s] :where [[s :crux.db/id o]] :full-results? true} and then just getting the entity/attribute/value triplets from each result.

dvingo17:05:14

Vars in attribute position not being supported is mentioned here, but it isn't very prominent https://opencrux.com/docs#queries_datascript_differences

🙏 4
mmer19:05:29

Thanks you all

4