Skip to main content

datafusion_physical_expr/expressions/
no_op.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! NoOp placeholder for physical operations
6
7use std::hash::Hash;
8use std::sync::Arc;
9
10use crate::PhysicalExpr;
11use arrow::{
12    datatypes::{DataType, Schema},
13    record_batch::RecordBatch,
14};
15use datafusion_common::{Result, internal_err};
16use datafusion_expr::ColumnarValue;
17
18/// A place holder expression, can not be evaluated.
19///
20/// Used in some cases where an `Arc<dyn PhysicalExpr>` is needed, such as `children()`
21#[derive(Debug, PartialEq, Eq, Default, Hash)]
22pub struct NoOp {}
23
24impl NoOp {
25    /// Create a NoOp expression
26    pub fn new() -> Self {
27        Self {}
28    }
29}
30
31impl std::fmt::Display for NoOp {
32    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
33        write!(f, "NoOp")
34    }
35}
36
37impl PhysicalExpr for NoOp {
38    fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
39        Ok(DataType::Null)
40    }
41
42    fn nullable(&self, _input_schema: &Schema) -> Result<bool> {
43        Ok(true)
44    }
45
46    fn evaluate(&self, _batch: &RecordBatch) -> Result<ColumnarValue> {
47        internal_err!("NoOp::evaluate() should not be called")
48    }
49
50    fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> {
51        vec![]
52    }
53
54    fn with_new_children(
55        self: Arc<Self>,
56        _children: Vec<Arc<dyn PhysicalExpr>>,
57    ) -> Result<Arc<dyn PhysicalExpr>> {
58        Ok(self)
59    }
60
61    fn fmt_sql(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        std::fmt::Display::fmt(self, f)
63    }
64}