Skip to main content

graphrecords_query/operations/ordering/
unorder.rs

1use crate::{
2    Bare, BareValueDomain, EvaluateOperand, Explain, IndexDomain, Indexed, Multiple, Operand,
3    OrderState, QueryResult, Unordered, ValueDomain,
4    execution::EvaluationCache,
5    operands::OperandHandle,
6    operations::{
7        Apply, BareStream, KeyedStream, LaneKernel, Operation, OperationContext, Prepare,
8    },
9    optimizer::{Estimate, OperationInputs, OptimizerHints, PlanIdentity, PlanInputs, Stats},
10    registry::operation_manifest,
11    traits::Unorder,
12};
13use graphrecords_core::GraphRecord;
14
15#[derive(Clone, Explain, Operation, OperationInputs, OptimizerHints, PlanIdentity, PlanInputs)]
16#[operation(scope = Lane)]
17#[explain(label = "Unorder")]
18#[plan(optimizer_hints(empty = if_any))]
19pub struct UnorderOperation;
20
21impl Prepare for UnorderOperation {
22    type Prepared<'a> = ();
23
24    fn prepare<'a>(
25        &'a self,
26        _graphrecord: &'a GraphRecord,
27        _cache: &'a EvaluationCache<'a>,
28    ) -> QueryResult<Self::Prepared<'a>> {
29        Ok(())
30    }
31}
32
33impl<I: IndexDomain, V: ValueDomain, O: OrderState> LaneKernel<Indexed<I, V>, Multiple<O>>
34    for UnorderOperation
35{
36    type Output = OperandHandle<Indexed<I, V>, Multiple<Unordered>>;
37
38    fn execute<'a>(
39        _graphrecord: &'a GraphRecord,
40        values: KeyedStream<'a, I, V, Multiple<O>>,
41        _prepared: Self::Prepared<'a>,
42    ) -> QueryResult<<Self::Output as EvaluateOperand>::ReturnValue<'a>> {
43        Ok(values)
44    }
45
46    fn estimate(&self, input: Estimate, _stats: &Stats) -> Estimate {
47        input
48    }
49}
50
51impl<V: BareValueDomain, O: OrderState> LaneKernel<Bare<V>, Multiple<O>> for UnorderOperation {
52    type Output = OperandHandle<Bare<V>, Multiple<Unordered>>;
53
54    fn execute<'a>(
55        _graphrecord: &'a GraphRecord,
56        values: BareStream<'a, V, Multiple<O>>,
57        _prepared: Self::Prepared<'a>,
58    ) -> QueryResult<<Self::Output as EvaluateOperand>::ReturnValue<'a>> {
59        Ok(values)
60    }
61
62    fn estimate(&self, input: Estimate, _stats: &Stats) -> Estimate {
63        input
64    }
65}
66
67impl<O: Apply<UnorderOperation>> Unorder for O {
68    type ReturnOperand = O::Output;
69
70    fn unorder(&self) -> Self::ReturnOperand {
71        Self::ReturnOperand::new(OperationContext::new(self.clone(), UnorderOperation))
72    }
73}
74
75operation_manifest! {
76    UnorderOperation {
77        method: Unorder::unorder;
78        scope: lane;
79
80        kernel {
81            parameters: <I: IndexDomain, V: ValueDomain, O: OrderState>;
82            input: (Indexed<I, V>, Multiple<O>);
83            output: OperandHandle<Indexed<I, V>, Multiple<Unordered>>;
84        }
85        kernel {
86            parameters: <V: BareValueDomain, O: OrderState>;
87            input: (Bare<V>, Multiple<O>);
88            output: OperandHandle<Bare<V>, Multiple<Unordered>>;
89        }
90    }
91}