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