Skip to content

Fix issues with the initial draft of the quad pattern node #12

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

Merged
merged 4 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ uuid = "1.14.0"
zip-extract = "0.3.0"

# Upstream Oxigraph dependencies
oxttl = "0.1.7"
oxrdfio = "0.1.7"
sparesults = "0.2.4"
oxttl = "0.1.8"
oxiri = "0.2.11"
oxrdf = "0.2.4"
oxrdfio = "0.1.8"
oxsdatatypes = "0.2.2"
sparesults = "0.2.5"
spargebra = "0.3.5"

# Internal dependencies
Expand Down
9 changes: 9 additions & 0 deletions lib/common/src/blank_node_mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// TODO
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum BlankNodeMatchingMode {
/// A blank node is interpreted as a variable.
#[default]
Variable,
/// A blank node is interpreted as a constant filter.
Filter,
}
2 changes: 2 additions & 0 deletions lib/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
extern crate core;

mod blank_node_mode;
pub mod error;
mod quad_storage;

pub use blank_node_mode::BlankNodeMatchingMode;
pub use quad_storage::QuadPatternEvaluator;
pub use quad_storage::QuadStorage;

Expand Down
23 changes: 10 additions & 13 deletions lib/common/src/quad_storage.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::error::StorageError;
use crate::DFResult;
use crate::{BlankNodeMatchingMode, DFResult};
use async_trait::async_trait;
use datafusion::datasource::TableProvider;
use datafusion::execution::SendableRecordBatchStream;
use datafusion::physical_planner::ExtensionPlanner;
use rdf_fusion_model::{
GraphNameRef, NamedNodeRef, NamedOrBlankNode, NamedOrBlankNodeRef, Quad, QuadRef, SubjectRef,
TermRef,
GraphName, GraphNameRef, NamedOrBlankNode, NamedOrBlankNodeRef, Quad, QuadRef, TriplePattern,
Variable,
};
use std::fmt::Debug;
use std::sync::Arc;
Expand Down Expand Up @@ -72,17 +72,14 @@ pub trait QuadStorage: Send + Sync {
pub trait QuadPatternEvaluator: Debug + Send + Sync {
/// Returns a stream of quads that match the given pattern.
///
/// The resulting stream must have a schema that is compatible with the default schema for
/// quads. Each emitted batch should have `batch_size` elements.
///
/// While currently we can only filter for constant patterns, in the future this method
/// should be able to evaluate arbitrary patterns (i.e., including variables).
fn quads_for_pattern(
/// The resulting stream must have a schema that projects to the variables provided in the
/// arguments. Each emitted batch should have `batch_size` elements.
fn evaluate_pattern(
&self,
graph: GraphNameRef<'_>,
subject: Option<SubjectRef<'_>>,
predicate: Option<NamedNodeRef<'_>>,
object: Option<TermRef<'_>>,
graph: GraphName,
graph_variable: Option<Variable>,
pattern: TriplePattern,
blank_node_mode: BlankNodeMatchingMode,
batch_size: usize,
) -> DFResult<SendableRecordBatchStream>;
}
4 changes: 2 additions & 2 deletions lib/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl RdfFusionInstance {
/// Checks whether `quad` is contained in the instance.
pub async fn contains(&self, quad: &QuadRef<'_>) -> DFResult<bool> {
let active_graph_info = graph_name_to_active_graph(Some(quad.graph_name));
let pattern_plan = RdfFusionLogicalPlanBuilder::new_from_quads(
let pattern_plan = RdfFusionLogicalPlanBuilder::new_from_matching_quads(
Arc::clone(&self.functions),
active_graph_info,
Some(quad.subject.into_owned()),
Expand Down Expand Up @@ -109,7 +109,7 @@ impl RdfFusionInstance {
object: Option<TermRef<'_>>,
) -> DFResult<SendableRecordBatchStream> {
let active_graph_info = graph_name_to_active_graph(graph_name);
let pattern_plan = RdfFusionLogicalPlanBuilder::new_from_quads(
let pattern_plan = RdfFusionLogicalPlanBuilder::new_from_matching_quads(
Arc::clone(&self.functions),
active_graph_info,
subject.map(SubjectRef::into_owned),
Expand Down
4 changes: 2 additions & 2 deletions lib/engine/src/sparql/rewriting/graph_pattern_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ impl GraphPatternRewriter {
object,
} => {
let state = self.state.borrow();
RdfFusionLogicalPlanBuilder::new_from_property_path(
Ok(RdfFusionLogicalPlanBuilder::new_from_property_path(
Arc::clone(&self.registry),
state.active_graph.clone(),
state.graph_name_var.clone(),
path.clone(),
subject.clone(),
object.clone(),
)
))
}
GraphPattern::Minus { left, right } => {
let left = self.rewrite_graph_pattern(left)?;
Expand Down
1 change: 0 additions & 1 deletion lib/logical/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ rdf-fusion-encoding.workspace = true
rdf-fusion-functions.workspace = true
datafusion.workspace = true
rdf-fusion-model.workspace = true
spargebra.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion lib/logical/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod logical_plan_builder;
pub mod minus;
pub mod paths;
pub mod patterns;
pub mod quads;
pub mod quad_pattern;

pub use active_graph::{ActiveGraph, EnumeratedActiveGraph};
use datafusion::common::{plan_err, DFSchema};
Expand Down
Loading
Loading