fluree / core

Fluree releases and public bug reports
0 stars 0 forks source link

Properties introduced as nested/referent objects aren't recognized as properties at query-time #24

Closed aaj3f closed 9 months ago

aaj3f commented 10 months ago

Description

Note: this is related to issue: subjects used as predicates don't have iris in query results

If you introduce a property as a nested object / referent of another node, then that property can't be used in queries without throwing a db/invalid-query: Invalid Predicate error

Steps to reproduce:

(1) Create ledger

{
    "ledger": "bug/property-iri",
    "txn": {
        "message": "success"
    }
}

(2) Add vocab data

{
    "@context": {
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "ex": "http://example.org/",
        "owl": "http://www.w3.org/202/07/owl#"
    },
    "@id": "bug/property-iri",
    "@graph": [
        {
            "@id": "ex:givenName",
            "@type": "rdf:Property",
            "owl:equivalentProperty": {
                "@id": "ex:firstName",
                "@type": "rdf:Property"
            }
        }
    ]
}

(3) Add entity data

{
    "@context": {
        "ex": "http://example.org/"
    },
    "@id": "bug/property-iri",
    "@graph": [
        {
            "@id": "ex:andrew",
            "ex:firstName": "Andrew",
            "ex:age": 35
        },
        {
            "@id": "ex:dan",
            "ex:givenName": "Dan"
        }
    ]
}

(4) This query works fine

{
    "from": "bug/property-iri",
    "select": {"?s": ["*"]},
    "where": [
        ["?s", "@id", "http://example.org/andrew"]

    ]
}

=> 

[
    {
        "@id": "http://example.org/andrew",
        "http://example.org/age": 35,
        "http://example.org/firstName": "Andrew"
    }
]

(5) This query throws the unexpected error

{
    "from": "bug/property-iri",
    "select": {"?s": ["*"]},
    "where": [
        ["?s", "http://example.org/firstName", "?o"]

    ]
}

=>

{
    "error": "db/invalid-query",
    "message": "Invalid predicate: http://example.org/firstName"
}
dpetran commented 10 months ago

I'm not getting the error you're getting here, but maybe some owl:equivalentProperty problems?

(let [conn @(fluree/connect {:method :memory})
      ledger @(fluree/create conn "bug/property-iri" 
                                                       {:defaultContext [test-utils/default-str-context
                                                           {"ex" "http://example.com/"
                                                             "owl" "http://www.w3.org/202/07/owl#"}]})
      db0 (fluree/db ledger)
      db1 @(fluree/stage db0 [{"@id" "bug/property-iri"
                               "@graph" [{"@id" "ex:givenName"
                                          "@type" "rdf:Property"
                                          "owl:equivalentProperty" {"@id" "ex:firstName"
                                                                    "@type" "rdf:Property"}}]}])
      db2 @(fluree/stage db1 [{"@id" "ex:andrew"
                               "ex:firstName" "Andrew"
                               "ex:age" 35}
                              {"@id" "ex:dan"
                               "ex:givenName" "Dan"}])]
;; this returns what we expect
  (is (= [{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}]
         @(fluree/query db2 {"select" {"?s" ["*"]}
                             "where" [["?s" "@id" "ex:andrew"]]})))
;; this doesn't return `ex:andrew`, even though `ex:givenName` and `ex:firstName` 
;; are owl:equivalentProperties
  (is (= [{"id" "ex:dan", "ex:givenName" "Dan"}]
         @(fluree/query db2 {"select" {"?s" ["*"]}
                             "where" [["?s" "ex:givenName" "?o"]]})))
;; vice versa shows the same owl:equivalentProperties problem
  (is (= [{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}]
         @(fluree/query db2 {"select" {"?s" ["*"]}
                             "where" [["?s" "ex:firstName" "?o"]]}))))
dpetran commented 10 months ago

Oh, wait, I see - we don't yet support from in queries, that's the source of the invalid-query error.

dpetran commented 10 months ago

Disregard - I was able to reproduce the issue in gateway.

cap10morgan commented 10 months ago

Oh, wait, I see - we don't yet support from in queries, that's the source of the invalid-query error.

We do now, FYI: https://github.com/fluree/db/blob/7834d151a750f7d148f36ce50739448ba11933d0/src/fluree/db/json_ld/api.cljc#L317-L323