Skip to main content

datafusion_physical_expr/expressions/
no_op.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! NoOp placeholder for physical operations
19
20use std::hash::Hash;
21use std::sync::Arc;
22
23use crate::PhysicalExpr;
24use arrow::{
25    datatypes::{DataType, Schema},
26    record_batch::RecordBatch,
27};
28use datafusion_common::{Result, internal_err};
29use datafusion_expr::ColumnarValue;
30
31/// A place holder expression, can not be evaluated.
32///
33/// Used in some cases where an `Arc<dyn PhysicalExpr>` is needed, such as `children()`
34#[derive(Debug, PartialEq, Eq, Default, Hash)]
35pub struct NoOp {}
36
37impl NoOp {
38    /// Create a NoOp expression
39    pub fn new() -> Self {
40        Self {}
41    }
42}
43
44impl std::fmt::Display for NoOp {
45    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
46        write!(f, "NoOp")
47    }
48}
49
50impl PhysicalExpr for NoOp {
51    fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
52        Ok(DataType::Null)
53    }
54
55    fn nullable(&self, _input_schema: &Schema) -> Result<bool> {
56        Ok(true)
57    }
58
59    fn evaluate(&self, _batch: &RecordBatch) -> Result<ColumnarValue> {
60        internal_err!("NoOp::evaluate() should not be called")
61    }
62
63    fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> {
64        vec![]
65    }
66
67    fn with_new_children(
68        self: Arc<Self>,
69        _children: Vec<Arc<dyn PhysicalExpr>>,
70    ) -> Result<Arc<dyn PhysicalExpr>> {
71        Ok(self)
72    }
73
74    fn fmt_sql(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75        std::fmt::Display::fmt(self, f)
76    }
77}