Skip to main content

graphrecords_query/operands/
edges.rs

1use super::{DefiniteElementOperand, ElementOperand, ElementsOperand};
2use crate::{
3    EvaluateContext, EvaluateOperand, Explain, QueryResult, Unordered,
4    execution::EvaluationCache,
5    optimizer::{
6        Count, CountKind, Estimate, Estimated, MatchInputs, OptimizePlan, OptimizerHints, PlanNode,
7        Stats,
8    },
9};
10use graphrecords_core::{GraphRecord, graphrecord::EdgeIndex};
11
12pub type EdgesOperand<O> = ElementsOperand<EdgeIndex, O>;
13pub type EdgeOperand = ElementOperand<EdgeIndex>;
14pub type DefiniteEdgeOperand = DefiniteElementOperand<EdgeIndex>;
15
16#[derive(PlanNode, MatchInputs, OptimizePlan, OptimizerHints, Explain)]
17#[plan(operand = EdgesOperand<Unordered>)]
18pub struct AllEdges;
19
20impl Estimated for AllEdges {
21    fn estimate(&self, stats: &Stats) -> Estimate {
22        let edges = stats.get::<Count>(&CountKind::Edges);
23
24        Estimate::values(edges, edges)
25    }
26}
27
28impl EvaluateContext for AllEdges {
29    type Operand = EdgesOperand<Unordered>;
30
31    fn evaluate<'a>(
32        &'a self,
33        graphrecord: &'a GraphRecord,
34        _cache: &'a EvaluationCache<'a>,
35    ) -> QueryResult<<Self::Operand as EvaluateOperand>::ReturnValue<'a>> {
36        Ok(Box::new(
37            graphrecord.edge_indices().map(|index| (index, Ok(()))),
38        ))
39    }
40}