edn-query-language / eql

EQL is a declarative way to make hierarchical (and possibly nested) selections of information about data requirements. This repository contains the base specs and definitions for EQL parsing, AST, etc.
http://edn-query-language.org
MIT License
381 stars 18 forks source link

Expected behavior when merging queries with parameters #12

Closed kennyjwilli closed 4 years ago

kennyjwilli commented 4 years ago

What is the expected behavior when calling merge-queries with a property that has parameters? I would expect a similar behavior to Clojure's merge, however that is not what I'm seeing.

This works as expected.

(eql/merge-queries [(list :a {:x 1})] [(list :a {:x 1})])
=> [(:a {:x 1})]

I would have expected :a to have the {:x 1} param map added to it. nil is a very strange return.

(eql/merge-queries [:a] [(list :a {:x 1})])
=> nil
(eql/merge-queries [(list :a {:x 1})] [(list :a {:x 2 :y 3})])
=> nil
awkay commented 4 years ago

As far as I'm concerned those two queries are not legally mergeable: they have diff parameters, which indicate a desire for different result. Combining them makes no sense. A query also returns a map, so having them in the same EQL expression is also non-sensical. You must split such an EQL expression ( one that contains duplicate query keys with differing parameters), not merge it.

Returning nil is perhaps non-perfect, but it is a way to indicate an error condition that can be composed.