Fork me on GitHub
#datomic
<
2017-03-01
>
val_waeselynck08:03:50

releasing Datomock 0.2.0, with support for the Log API: https://github.com/vvvvalvalval/datomock

dm315:03:12

I’m trying to reuse the rules and failing to produce the most basic working example:

(def rules '[[(doc-is [?x] ?e) [?e :db/doc ?x]]])
(d/q '[:find ?e :in $ % ?x :where [(doc-is ?x ?e)]] db rules “test-doc”)
The query compiler throws Unable to resolve symbol: doc-is in this context - what am I doing wrong?

dm315:03:37

ok, you’re not supposed to put the rule invocation inside square brackets - problem solved!

misha16:03:06

@dm3 paste full solution here, please

dm316:03:37

(d/q '[:find ?e :in $ % ?x :where (doc-is ?x ?e)] db rules “test-doc

stijn20:03:13

I have a question connecting datomic console to a production database

stijn20:03:12

We are running on cassandra and I was trying to forward port 9042 to a local port and have console connect to datomic:

stijn20:03:56

it seems this connection works, but as soon as you select a database Artemis will throw a ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]

donaldball20:03:58

Is there a simple way to restrict a variable in a datalog query to all entities that are (or are not) referenced by any other entities, via any attribute?

stijn20:03:00

How could I possibly solve this? Which connection is failing? From the transactor to the localhost? Or the other way around?

stijn20:03:21

I assume it's from localhost to the transactor, but how does cassandra store the transactor's address?

stijn20:03:13

is it an IP? a hostname?

favila20:03:02

@stijn The peer connects to cassandra storage

favila20:03:25

Cassandra storage has written into it two transactor addresses, as provided by your transactor.properties file

favila20:03:35

The peer then pulls those and uses them to connect to the transactor

favila20:03:50

So you need to make sure those hosts are correctly resolveable from wherever you are

stijn20:03:55

the 'host' and 'alt-host' field?

favila20:03:59

(whereever your peer is)

stijn20:03:10

cool, that should be doable with /etc/hosts 🙂

marshall20:03:41

@val_waeselynck sorry i missed your message yesterday. Do you have a small repro?

val_waeselynck07:03:54

marshall: not seeing a leak at all, I just want to know if I can count on that to be the case for future versions - I don't want to be relying on an implementation detail

val_waeselynck07:03:05

My use case is the implementation of Datomock forked connections, in which forked connections keep a reference to the Log of the original connection.

marshall13:03:09

Hrm. I’m actually not sure. It may depend on Clojure’s handling on GC actually

marshall20:03:48

are you seeing a potential leak?

favila20:03:48

@donaldball

(d/q '[:find ?e
       :where
       [?vt :db/ident :db.type/ref]
       [?a :db/valueType ?vt]
       [_ ?a ?e]])

marshall20:03:50

@donaldball you could put in a clause with the entity ID of your entity of interest in the v position

marshall20:03:01

ah. welp, @favila beat me to it 🙂

favila20:03:52

@donaldball or use (into #{} (map :v) (d/seek-datoms :vaet)) to get all referenced entities

favila20:03:15

Getting the opposite (not-reference entities) is harder

favila20:03:29

mostly because entities don't exist

marshall20:03:39

not-join with your 3 clauses above ?

marshall20:03:08

oh, sorry, all entities

marshall20:03:10

yeah that’s harder

favila20:03:26

You need to refine what you mean by "not referenced entities"

favila20:03:38

because theoretically that is any integer

favila20:03:10

Maybe you mean "any entity which has other assertions on it, but which is not referenced by other assertions"

favila20:03:27

I think this would do it, but I'm not sure it would run:

[:find ?e
       :where
       [?vt :db/ident :db.type/ref]
       [?a :db/valueType ?vt]
       (not [_ ?a ?e])
       [?e]

donaldball20:03:09

I suppose I mean “there do not exist any datoms in the current database which have attributes which are references to the datom in question"

favila20:03:37

attributes? you mean values?

donaldball20:03:43

Sorry, I haven’t quite gotten the datomic language fully integrated yet 😛

favila20:03:22

[?vt :db/ident :db.type/ref]
       [?a :db/valueType ?vt]
       (not [_ ?a ?e])
will work, if you are able to bind ?e earlier in the query

favila20:03:36

If you want all unreferenced entities, you may not be able to query in a sensible amount of time in a query (you will need a table scan, and the query engine will not allow that)

favila21:03:38

@donaldball OK I think this will do it efficiently:

(let [partition-key-by (fn [f]
                         (fn [xf]
                           (let [last (volatile! (Object.))]
                             (fn
                               ([] (xf))
                               ([r] (vreset! last nil) (xf r))
                               ([r x]
                                (let [k (f x)]
                                  (if (= k @last)
                                    r
                                    (do
                                      (vreset! last k)
                                      (xf r k)))))))))]
  (->> (sequence
         (comp
           (partition-key-by :e)
           (remove #(first (d/seek-datoms db :vaet %))))
         (d/datoms db :eavt))
;;; just so we don't explode
       (take 10)))

csm22:03:17

with the 0.9.5530 peer server/clojure client, I’m getting an error {:datomic.client-spi/request-id 782ba011-a723-4f9e-b25c-93338d389785, :cognitect.anomalies/category :cognitect.anomalies/incorrect, :cognitect.anomalies/message :db.error/tempid-not-an-entity tempid used only as value in transaction, :dbs [{:database-id datomic:, :t 137256, :next-t 137258, :history false}]}, but this same transaction succeeds for me using an in-memory database

csm22:03:41

I get failures with dev storage and dynamodb

matthavener22:03:29

csm: using strings as tempids?

matthavener22:03:17

I think upgrading to 5544 has the fix. Check out this thread https://groups.google.com/forum/#!topic/datomic/m6vSa6CjqjQ

csm22:03:52

aha, nice. Thanks!

sova-soars-the-sora23:03:25

Hi everyone, I'm doing something interesting that uses time-querying. Basically, I want to know the users username when they posted a thing

sova-soars-the-sora23:03:43

since they can change their username (but never their email) i want to find out what they had their username set to at the time of posting

sova-soars-the-sora23:03:50

to stay historically consistent

sova-soars-the-sora23:03:10

firstly, thoughts? should i even bother? i think it's a cool feature, and an interesting practical use of datomic's capabilities...

sova-soars-the-sora23:03:08

secondly, if i were to do this, how do I query for it ? get the creation date of the item, query for the user's username at that db instant, and synthesize them, i think it's a winning approach...