Skip to content
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
28 changes: 18 additions & 10 deletions crates/lance-csr/src/path_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ struct Ready {
node_keys: Int64Array,
shortest: Option<(Neighbors, Neighbors)>,
/// CSR route only: per step and hop, its filter and what that filter has checked.
hops: Vec<Vec<(HopFilter, EdgeFilterState)>>,
hops: Vec<Vec<(HopFilter, Arc<EdgeFilterState>)>>,
/// CSR route only: the inventory has no edges, so relationship values are built here.
edge_type: arrow_schema::DataType,
edge_fields: arrow_schema::Fields,
Expand Down Expand Up @@ -708,15 +708,23 @@ impl Ready {
let edge_fields = property_fields(spec.edges.iter().map(|s| s.schema.fields()))?;
let node_type = inventory.nodes.data_type().clone();
let edge_type = entity_type(edge_fields.clone(), "relationship", Some(&node_type));
let hops = hop_filters
.iter()
.map(|filters| {
filters
.iter()
.map(|f| (f.clone(), EdgeFilterState::default()))
.collect()
})
.collect();
// Hops of one step over the same table share a state: the two halves of an
// undirected step then count their checks together and read one mask.
let hops = match &spec.csr {
Some(csr) => csr
.steps
.iter()
.zip(hop_filters)
.map(|(step, filters)| {
let mut states: HashMap<usize, Arc<EdgeFilterState>> = HashMap::new();
step.iter()
.zip(filters)
.map(|(hop, f)| (f.clone(), states.entry(hop.kind).or_default().clone()))
.collect()
})
.collect(),
None => Vec::new(),
};
let mask =
|p: &Option<Arc<dyn PhysicalExpr>>, batch: &RecordBatch| -> Result<BooleanArray> {
match p {
Expand Down
3 changes: 2 additions & 1 deletion docs/internals/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ A frame reads its node's neighbors and their edge rows from the CSR the first ti
step reads the outgoing and incoming CSR separately, so each edge keeps its stored direction. The step's relationship
equalities are compiled against each relationship table and checked by `EdgeFilterState`, the same rule
`CsrExpandExec` uses: fetch the filter columns of just the edges reached and, on a Lance table, switch to one read of
the whole column once the edges checked pass 1/256 of the relationship's edges. An edge's identity is its CSR row,
the whole column once the edges checked pass 1/256 of the relationship's edges. Both halves of an undirected step
share one state, so they count their checks together and read the column once. An edge's identity is its CSR row,
numbered per input batch so a trail can refuse to reuse one. Relationship records (properties, identity, start and
end nodes) are built only for the edges of the paths in an output batch. This follows Kùzu's design, which evaluates
relationship predicates inside recursive joins over CSR adjacency lists, so the work follows the frontier instead of
Expand Down
Loading