This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-08
Channels
- # adventofcode (240)
- # beginners (87)
- # boot (4)
- # cider (27)
- # cljs-dev (20)
- # cljsrn (24)
- # clojure (365)
- # clojure-argentina (1)
- # clojure-brasil (4)
- # clojure-dev (12)
- # clojure-greece (65)
- # clojure-india (1)
- # clojure-italy (15)
- # clojure-japan (1)
- # clojure-losangeles (1)
- # clojure-madison (4)
- # clojure-poland (3)
- # clojure-russia (5)
- # clojure-spec (3)
- # clojure-uk (105)
- # clojurescript (27)
- # core-async (1)
- # core-logic (3)
- # cursive (61)
- # datomic (68)
- # devcards (4)
- # docs (27)
- # duct (67)
- # emacs (15)
- # events (1)
- # fulcro (8)
- # graphql (50)
- # lein-figwheel (1)
- # lumo (15)
- # numerical-computing (1)
- # off-topic (77)
- # om (3)
- # onyx (5)
- # parinfer (3)
- # planck (2)
- # portkey (5)
- # re-frame (4)
- # reagent (16)
- # ring (14)
- # rum (3)
- # shadow-cljs (17)
- # vim (1)
So reading further i learned that [[?title ?box-office]]
is input and is a vector of vectors. It is being destructured
And the ?box-office
value has no effect on the query and is simply being outputted with the title
This indeed looks very weird. I don't see a way to experiment without recreating the entire dataset locally but this example looks half-finished. For instance, all the outputs are also inputs?
What’s missing is the larger context. It’s been a while since I did that tutorial, but as I recall, this is illustrating how to combine db + external data to answer questions like “Show the title and box-office receipts for each movie directed by a specific director.”
No one data source has all the information you need: the db is missing the box-office info, and the list of movies is missing the director info.
This query combines the two in a way that lets you get the specific answer you want.
@U06CM8C3V I see that. But is ?director
meant to be input, or output? Without running the query, it's unclear to me that ?director gets used at all except as a filter to verify that titles in the input list have a director at all.
Director is an input
You can tell because it’s listed on the :in
line
In datomic you would call it like this:
(d/q '[:find ?title ?box-office
:in $ ?director [[?title ?box-office]]
:where
[?p :person/name ?director]
[?m :movie/director ?p]
[?m :movie/title ?title]]
db "Stanley Kubrick" box-office-receipts)
I think I now see the confusion. I was aware that ?director was listed as an input; what was unclear was whether that was intentional. The phrase "to find box office earnings for a particular director" made me think it was intended to return something like ?director and the sum of box office earnings. I see it's just meant to subset the input list (which already has most of the info needed) based on information that the database has (the director).
Datomic fam, I have a query for you all 😃 I have a rating system, I want to let users rate things but only show the effects of their rating 24 hrs later, meaning someone upvotes something, someone downvotes something, but the effcts aren't apparent to the score until 24 hrs later. Can i structure a datomic query to get all the results that are at least 24 hours old?
@sova you can query the database 24 hours in the past by using (datomic.api/as-of db some-date)
and pass that database to the query
@stijn excellent.
thank you
some things are so simple 😄
I wonder if anyone has ever had to join datomic data stored on postgres with postgres data, for a very simple join.
I.e. a postgres table has a unique column with an id, you want to join ON a datomic entity with the same id as a lookup ref, and add some datomic attribute values to the resulting rows.
in other words, use SQL to lookup an attribute’s currrent value using only the entity lookup ref.
It may require hardcoding the attribute id when creating the schema for better performance though.
I ask this cause some teams are interested in exploring datomic for its audit and read scalability, but they do merge some of their CRUD app data with Postgres tables to fill in missing columns. And these Postgres tables are often owned by other teams.
@kenbier are you wanting to do this in a datomic query? in theory you could, just call a function inside your datomic query to lookup postgres
the use case would be query a postgres table, but join in some missing columns from datomic data also stored in postgres
to do what you want would require issuing a datomic lookup from within the postgresql server itself
you could probably write a stored procedure which called out to datomic, but your data fetch is going to leave the posgres query process no matter what you do
why burden the postgresql server with that cpu load and additional complexity just so SELECT works?
they are going to want to join in missing fields like a an entities title based on an id, for example. to generate reports and look into insights for customers
siloing data from the rest of our large organization really hurts the value prop of adopting a new database engine, even if the data lives on postgres in reality.
though i am curious how to do the postgres query from datomic, the aforementioned is a more pressing issue for adoption.
you can have a process read the datomic tx queue and write the data you want into postgres
what if the postgres server fails over? how would i pickup where i left off in the txn queue?
(playing catch-up from datomic's tx-log) before switching to the live-streaming tx-queue
datomic queries are run on the querying machine, not the transactor, so they can call anything they want
you just need a clojure function that returns something shaped appropriately for query destructuring