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

Feature/sparql format #621

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Feature/sparql format #621

wants to merge 11 commits into from

Conversation

Laschoking
Copy link
Collaborator

@Laschoking Laschoking commented Feb 12, 2025

With this changes a new keyword sparql is introduced that expects two keywords:
endpoint is expected to be a valid IRI and query a String.
f.e. @import test :- sparql{endpoint=<https://query.wikidata.org/>, "SELECT ?item ..."}.

Furthermore, resources can be written as IRIs now.
Most importantly the Resource-type is changed, allowing now a Resource::Iri for HTTPRequests (either online-files or sparql queries) and Resource::Path for local resources.

Known lacks:

Questions for review:

  • how precise should the validation of parameters be? In sparql::is_value_valid() the SparqlParameter::Endpoint and SparqlParameter::Query are validated intensely, which seems like a lot of effort.
  • The parsing of a resource (now can be either IRI or string) was moved to format::ResouceSpec::parse_string while before, the two file providers HttpResourceProvider and FileResourceProvider were handling this.
    -> is this change agreeable?
  • in format_builder::new_with_tag the created resource: Option<ResourceSpec> can be replaced by a Option<ResourceSpec> returned from any Builder. This allows the SparqlBuilder to return its own ResourceSpec that uses endpoint and query.
    -> is this agreeable or should it be handled elsewhere?
  • in resource_providers::open_resource() the existing vector containing both ResourceProviders is used. -> can this be simplified somehow?

Copy link
Member

@mmarx mmarx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how precise should the validation of parameters be? In sparql::is_value_valid() the SparqlParameter::Endpoint and SparqlParameter::Query are validated intensely, which seems like a lot of effort.

Even if this takes a bit of effort, we're doing this once, when loading the program, so the performance overhead is negligible, especially if we have queries with lots of results. Sending off a query to the endpoint, only to then find out that it fails because there's a syntax error, however, is certainly going to take much longer.

The parsing of a resource (now can be either IRI or string) was moved to format::ResouceSpec::parse_string while before, the two file providers HttpResourceProvider and FileResourceProvider were handling this.

As mentioned, this should go into a TryFrom<Resource> for ResourceSpec.

in format_builder::new_with_tag the created resource: Option can be replaced by a Option returned from any Builder. This allows the SparqlBuilder to return its own ResourceSpec that uses endpoint and query.

As mentioned, this should rather be another method on the trait, with a default implementation that does not replace the ResourceSpec.

in resource_providers::open_resource() the existing vector containing both ResourceProviders is used. -> can this be simplified somehow?

This should stay as it is. The fact that there's only two entries is an implementation detail that we can't rely on (and might not be true in, e.g., some test cases).

@mmarx mmarx added enhancement New feature or request io rdf RDF support labels Feb 12, 2025
@mmarx mmarx added this to the Release 0.8.0 milestone Feb 12, 2025
@Laschoking Laschoking force-pushed the feature/sparql-format branch from 8eb375d to f6560ed Compare February 13, 2025 15:32
…urning a Resource

The commit misses the actual reading of parameters (get_parameters, header_parameters, body_parameters, fragment) from an import statement.
However, the ResourceBuilder provides all needed functionalities to include them.
Copy link
Member

@mmarx mmarx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going in the right direction. I have a lot of comments, but most of them are stylistic issues (particularly in user-facing code such as error messages).

You can ignore the clippy issues for now and rebase once #626 is merged, they're already fixed there. The doc failure is already fixed, next run should work again.

@@ -407,9 +441,77 @@ impl ImportExportBuilder {
}
}?;

let resource_builder = inner
.override_resource_builder(direction)
.or(resource_builder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make this unwrap_or(resource_builder); and get rid of an if let with an else that is way too far along, below?

Comment on lines +65 to +71
.to_iri()
.ok_or(ValidationErrorKind::ImportExportInvalidIri)
.and_then(|iri| {
Iri::parse(iri)
.map(|_| ())
.map_err(|_| ValidationErrorKind::ImportExportInvalidIri)
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't need to throw the same error twice, clearly, to_iri() should actually return a validated IRI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request io rdf RDF support
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants