qpdb / mentat

A persistent, relational store inspired by Datomic and DataScript.
https://mentat.rs/
Apache License 2.0
52 stars 2 forks source link

Inequality predicates seem to match nonsensical types #179

Open gburd opened 4 years ago

gburd commented 4 years ago

It seems like the types returned by the inequality predicates (>, >=, <, <=) aren't limited to what is vaguely sensible.

To reproduce, you can copy/paste the following into the mentat CLI:

.t[{:db/ident :t/name :db/valueType :db.type/string :db/cardinality :db.cardinality/one}
   {:db/ident :t/weight :db/valueType :db.type/double :db/cardinality :db.cardinality/one}
   {:db/ident :t/key :db/valueType :db.type/keyword :db/cardinality :db.cardinality/one}
   {:db/ident :t/count :db/valueType :db.type/long :db/cardinality :db.cardinality/one}
   {:db/ident :t/id :db/valueType :db.type/uuid :db/cardinality :db.cardinality/one}
   {:db/ident :t/date :db/valueType :db.type/instant :db/cardinality :db.cardinality/one}
   {:db/ident :t/ref :db/valueType :db.type/ref :db/cardinality :db.cardinality/one}]
.t[{:t/name "foo" :t/weight 0.3 :t/key :foo/bar :t/count 12 :t/id #uuid "ff62d552-6569-4d1b-b667-04703041dfc4" :t/date #inst "2018-01-01T11:00:00.000Z" }]
.t[{:t/name "bar" :t/weight 0.5 :t/key :foo/bar :t/count 99 :t/id #uuid "ff62d552-1234-1234-b667-047030414321" :t/date #inst "2017-01-01T11:00:00.000Z" }]
.t[[:db/add 65543 :t/ref 65544]]
.q[:find [?v ...] :where [65543 _ ?v] [(> ?v 0)]]

Which will output (a bunch of TxReports, followed by):

"foo"
0.3
:foo/bar
12
ff62d552-6569-4d1b-b667-04703041dfc4
2018-01-01 11:00:00 UTC
65544

Note that [(> ?v 0)] matches strings, keywords, and uuids, in addition to the types that seem intentional that it matches (e.g. doubles, longs, instants, and refs -- I'm assuming these are intentional, since a similarly broad < will return those, but not the strings/keywords/uuids).

In fact, it always seems to include the nonsense types, no matter how large I make the second argument to > (I've tried 1.79e308 and 9223372036854775807, at least).

This seems to exhibit itself when comparing if a variable is larger than a constant. For constant values of $k, [(> ?v $k)] and [(>= ?v $k)] both cause the issue, as do [(< $k ?v)] and [(<= $k ?v)]. But not when comparing if a constant is larger than a variable, e.g. [(< ?v $k)], [(<= ?v $k)], [(> $k ?v)] and [(>= $k ?v)] all seem to behave correctly.