Skip to main content

graphrecords_query/operands/
nodes.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::NodeIndex};
11
12pub type NodesOperand<O> = ElementsOperand<NodeIndex, O>;
13pub type NodeOperand = ElementOperand<NodeIndex>;
14pub type DefiniteNodeOperand = DefiniteElementOperand<NodeIndex>;
15
16#[derive(PlanNode, MatchInputs, OptimizePlan, OptimizerHints, Explain)]
17#[plan(operand = NodesOperand<Unordered>)]
18pub struct AllNodes;
19
20impl Estimated for AllNodes {
21    fn estimate(&self, stats: &Stats) -> Estimate {
22        let nodes = stats.get::<Count>(&CountKind::Nodes);
23
24        Estimate::values(nodes, nodes)
25    }
26}
27
28impl EvaluateContext for AllNodes {
29    type Operand = NodesOperand<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.node_indices().map(|index| (index, Ok(()))),
38        ))
39    }
40}