graphrecords_query/operations/conversion/
discard_index.rs1use crate::{
2 Bare, BareValueDomain, Explain, IndexDomain, Indexed, Operand, QueryResult,
3 element::{Pipeline, Preserving},
4 execution::EvaluationCache,
5 operations::{Apply, ElementKernel, ElementPipeline, Operation, OperationContext, Prepare},
6 optimizer::{OperationInputs, OptimizerHints, PlanIdentity, PlanInputs},
7 registry::operation_manifest,
8 traits::DiscardIndex,
9};
10use graphrecords_core::GraphRecord;
11
12#[derive(Clone, Explain, Operation, OperationInputs, OptimizerHints, PlanIdentity, PlanInputs)]
13#[operation(scope = Element)]
14#[explain(label = "DiscardIndex")]
15#[plan(optimizer_hints(commutes_with_filter, allows_limit_pushdown, empty = if_any))]
16pub struct DiscardIndexOperation;
17
18impl Prepare for DiscardIndexOperation {
19 type Prepared<'a> = ();
20
21 fn prepare<'a>(
22 &'a self,
23 _graphrecord: &'a GraphRecord,
24 _cache: &'a EvaluationCache<'a>,
25 ) -> QueryResult<Self::Prepared<'a>> {
26 Ok(())
27 }
28}
29
30impl<I: IndexDomain, V: BareValueDomain> ElementKernel<Indexed<I, V>> for DiscardIndexOperation {
31 type Emission = Preserving;
32 type OutShape = Bare<V>;
33
34 fn pipeline<'a>(
35 _graphrecord: &'a GraphRecord,
36 _prepared: Self::Prepared<'a>,
37 ) -> QueryResult<ElementPipeline<'a, Indexed<I, V>, Self>> {
38 Ok(Pipeline::unkeyed(|value| value))
39 }
40}
41
42impl<O: Apply<DiscardIndexOperation>> DiscardIndex for O {
43 type ReturnOperand = O::Output;
44
45 fn discard_index(&self) -> Self::ReturnOperand {
46 Self::ReturnOperand::new(OperationContext::new(self.clone(), DiscardIndexOperation))
47 }
48}
49
50operation_manifest! {
51 DiscardIndexOperation {
52 method: DiscardIndex::discard_index;
53 scope: element;
54
55 kernel {
56 parameters: <I: IndexDomain, V: BareValueDomain>;
57 input: Indexed<I, V>;
58 output: Bare<V>;
59 emission: Preserving;
60 }
61 }
62}