Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement :from in queries #526

Closed
bplatz opened this issue Jul 6, 2023 · 2 comments
Closed

Implement :from in queries #526

bplatz opened this issue Jul 6, 2023 · 2 comments
Milestone

Comments

@bplatz
Copy link
Contributor

bplatz commented Jul 6, 2023

In SPARQL, FROM and FROM NAMED are ways to specify one or more data sets (graphs) the query will execute against.

Because FROM NAMED only works if you also support the SPARQL GRAPH statement, we can start by just implementing FROM, and initially only support a single data set.

To illustrate, this query specifies it should be run against the cookbook/test ledger:

{
  "from": "cookbook/test",
  "select": {"?s": ["*"]},
  "where": [
    ["?s", "ex:follows", "ex:cam"]
  ]
}

This change will allow a query to be executed against a conn (connection) and not have to be executed against a db (although we should still support that, in which case :from is implied as being the db). This is the exact situation HTTP-API has, and to get around that limitation it introduced a non-standard "ledger" key to specify the ledger. This change eliminates the need for the proprietary key in favor of the SPARQL standard.

While executing a query against a conn is a departure from always executing a query against a db, it makes even more sense when federating a query across multiple ledgers (which is not part of this initial ticket). e.g., if you wanted to execute the above query against two ledgers, both cookbook/test and foo/bar, the following syntax would be used:

{
  "from": ["cookbook/test", "foo/bar"],
  "select": {"?s": ["*"]},
  "where": [
    ["?s", "ex:follows", "ex:cam"]
  ]
}

With this pattern, executing this query against either the cookbook/test or the foo/bar db doesn't make much sense... but executing it against a conn does make sense.

This ticket aims to include the following features:

  1. Allow :from (from CLJ) and "from" (from JS) to specify only one ledger as the source, which can be a simple string or a one-element vector (e.g. :from "cookbook/test" or :from ["cookbook/test"]
  2. Allow the query to be executed against a conn, in which case if :from is specified it will load the latest db of the specified ledger and execute the query against the db. If :from is not specified, or is an unknown ledger, throw an exception.
  3. If a query with :from is executed against a db using the library, we ignore :from, and we will end up documenting that we ignore it in that circumstance.

This ticket excludes:

  1. Querying against multiple :from ledgers/graphs (for now)
  2. :from-named, which we'll introduce support for along with support for GRAPH
  3. Time travel query, :from will always load the latest db to execute against (for now)
@bplatz bplatz added this to the 3.0.0-beta1 milestone Jul 6, 2023
@aaj3f
Copy link
Contributor

aaj3f commented Jul 24, 2023

Added ticket fluree/core#19 as the initial subtask to deliver immediate need on this ticket. This ticket should be repurposed later to describe work for enabling a query against multiple ledgers using the :from and :from-named keys with an array of ledger names.

@aaj3f aaj3f modified the milestones: 3.0.0-beta1, 3.0.0-beta2 Jul 24, 2023
@bplatz
Copy link
Contributor Author

bplatz commented Sep 5, 2024

This is now implemented in: #606

@bplatz bplatz closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants