Skip to content

Unexpected results with multiple optionals at the same level #21

@kirahowe

Description

@kirahowe

It seems like having multiple optionals in a matcha query returns unexpected results. E.g. in this example (from an internal app), the query returns different results depending on which optional comes first:

> (matcha/construct-1 {:notation ?notation
                       :name ?name
                       :company-number ?company_number
                       :company-uri ?company_uri
                       :expiry-date ?expiry_date}
                      [[uri skos:notation ?notation]
                       [uri reg:holder ?holder]
                       [?holder foaf:name ?name]
                       (matcha/optional [[?holder org:identifier ?company_number]
                                         [?holder owl:sameAs ?company_uri]])
                       (matcha/optional [[uri reg:expiryDate ?expiry_date]])]
                      matcha-db)

> {:notation "CBDU195810",
   :name "1ST WASTE MANAGEMENT CONSULTANTS LTD",
   :company-number "03736942",
   :company-uri #object[java.net.URI 0x2cbb354 "http://business.data.gov.uk/id/company/03736942"],
   :expiry-date _0}

vs

> (matcha/construct-1 {:notation ?notation
                       :name ?name
                       :company-number ?company_number
                       :company-uri ?company_uri
                       :expiry-date ?expiry_date}
                      [[uri skos:notation ?notation]
                       [uri reg:holder ?holder]
                       [?holder foaf:name ?name]
                       (matcha/optional [[uri reg:expiryDate ?expiry_date]])
                       (matcha/optional [[?holder org:identifier ?company_number]
                                         [?holder owl:sameAs ?company_uri]])]
                      matcha-db)

> {:notation "CBDU195810",
   :name "1ST WASTE MANAGEMENT CONSULTANTS LTD",
   :company-number _0,
   :company-uri _1,
   :expiry-date #object[java.time.LocalDate 0x2802054f "2020-09-20"]}

Not sure what the problem is, but this result was surprising.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions