fluree / db

Fluree database library
https://fluree.github.io/db/
Other
337 stars 22 forks source link

Queries with recursive predicates do not parse #339

Open mpoffald opened 1 year ago

mpoffald commented 1 year ago

Our expand fn is throwing an exception when we attempt to parse queries with recursive predicates.

Exception is being thrown at this step: https://github.com/fluree/db/blob/main/src/fluree/db/query/fql/parse.cljc#L144

Stack trace:

  contains? not supported on type: clojure.lang.Keyword

                   RT.java:  853  clojure.lang.RT/contains
                  core.clj: 1506  clojure.core/contains?
                  core.clj: 1498  clojure.core/contains?
               expand.cljc:  319  fluree.json_ld.impl.expand$node/invokeStatic
               expand.cljc:  305  fluree.json_ld.impl.expand$node/invoke
               expand.cljc:  311  fluree.json_ld.impl.expand$node/invokeStatic
               expand.cljc:  305  fluree.json_ld.impl.expand$node/invoke
              json_ld.cljc:   96  fluree.json_ld$expand/invokeStatic
              json_ld.cljc:   88  fluree.json_ld$expand/invoke
                parse.cljc:  145  fluree.db.query.fql.parse$recursion_predicate/invokeStatic
                parse.cljc:  134  fluree.db.query.fql.parse$recursion_predicate/invoke
                parse.cljc:  210  fluree.db.query.fql.parse$parse_recursion_predicate/invokeStatic
                parse.cljc:  208  fluree.db.query.fql.parse$parse_recursion_predicate/invoke
                parse.cljc:  235  fluree.db.query.fql.parse$parse_predicate_pattern/invokeStatic
                parse.cljc:  230  fluree.db.query.fql.parse$parse_predicate_pattern/invoke
                parse.cljc:  293  fluree.db.query.fql.parse$parse_triple/invokeStatic
                parse.cljc:  290  fluree.db.query.fql.parse$parse_triple/invoke
                parse.cljc:  307  fluree.db.query.fql.parse$eval30336$fn__30337/invoke
              MultiFn.java:  244  clojure.lang.MultiFn/invoke
                parse.cljc:  284  fluree.db.query.fql.parse$parse_where_clause$fn__30328/invoke
                  core.clj: 6979  clojure.core/mapv/fn
           ArrayChunk.java:   58  clojure.lang.ArrayChunk/reduce
             protocols.clj:  136  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6886  clojure.core/reduce
                  core.clj: 6970  clojure.core/mapv
                  core.clj: 6970  clojure.core/mapv
                parse.cljc:  283  fluree.db.query.fql.parse$parse_where_clause/invokeStatic
                parse.cljc:  279  fluree.db.query.fql.parse$parse_where_clause/invoke
                parse.cljc:  327  fluree.db.query.fql.parse$parse_where/invokeStatic
                parse.cljc:  324  fluree.db.query.fql.parse$parse_where/invoke
                parse.cljc:  394  fluree.db.query.fql.parse$parse_analytical_query/invokeStatic
                parse.cljc:  389  fluree.db.query.fql.parse$parse_analytical_query/invoke
subject_crawl_reparse_test.clj:   97  fluree.db.query.subject-crawl-reparse-test/fn
subject_crawl_reparse_test.clj:    9  fluree.db.query.subject-crawl-reparse-test/fn
                  test.clj:  242  cider.nrepl.middleware.test/test-var/fn
                  test.clj:  242  cider.nrepl.middleware.test/test-var
                  test.clj:  234  cider.nrepl.middleware.test/test-var
                  test.clj:  257  cider.nrepl.middleware.test/test-vars/fn/fn
                  test.clj:  687  clojure.test/default-fixture
                  test.clj:  683  clojure.test/default-fixture
                  test.clj:  257  cider.nrepl.middleware.test/test-vars/fn
                  test.clj:  687  clojure.test/default-fixture
                  test.clj:  683  clojure.test/default-fixture
                  test.clj:  254  cider.nrepl.middleware.test/test-vars
                  test.clj:  248  cider.nrepl.middleware.test/test-vars
                  test.clj:  270  cider.nrepl.middleware.test/test-ns
                  test.clj:  261  cider.nrepl.middleware.test/test-ns
                  test.clj:  281  cider.nrepl.middleware.test/test-var-query
                  test.clj:  274  cider.nrepl.middleware.test/test-var-query
                  test.clj:  319  cider.nrepl.middleware.test/handle-test-var-query-op/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1990  clojure.core/with-bindings*
                  core.clj: 1990  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
                  test.clj:  311  cider.nrepl.middleware.test/handle-test-var-query-op/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  833  java.lang.Thread/run
bplatz commented 1 year ago

Here is a property path description from SPARQL which ultimately we want to support all of - so we should use similar syntax (JSON-ified): https://en.wikibooks.org/wiki/SPARQL/Property_paths

dpetran commented 1 year ago

Possibly related: db #322

mpoffald commented 1 year ago

This still does need some spec work to see what syntax we can use that won't break anything, but that will be part of the implementation work.

mpoffald commented 1 year ago

Some work was done on this, but the approach needs to be rethought and this isn't high-priority enough to keep working on right now.

The fix for the parsing error itself is straightforward, just need to use expand-iri where we were using expand, and accommodate strings vs keywords appropriately: https://github.com/fluree/db/commit/d943ba225c4209daf25aa59d4ec049242df27229

But the bigger lift is getting the recursive queries to actually execute, and we have chosen to come back to that later.