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::any::Any;
21use std::hash::Hash;
22use std::sync::Arc;
23
24use crate::PhysicalExpr;
25use arrow::{
26    datatypes::{DataType, Schema},
27    record_batch::RecordBatch,
28};
29use datafusion_common::{internal_err, Result};
30use datafusion_expr::ColumnarValue;
31
32/// A place holder expression, can not be evaluated.
33///
34/// Used in some cases where an `Arc<dyn PhysicalExpr>` is needed, such as `children()`
35#[derive(Debug, PartialEq, Eq, Default, Hash)]
36pub struct NoOp {}
37
38impl NoOp {
39    /// Create a NoOp expression
40    pub fn new() -> Self {
41        Self {}
42    }
43}
44
45impl std::fmt::Display for NoOp {
46    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
47        write!(f, "NoOp")
48    }
49}
50
51impl PhysicalExpr for NoOp {
52    /// Return a reference to Any that can be used for downcasting
53    fn as_any(&self) -> &dyn Any {
54        self
55    }
56
57    fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
58        Ok(DataType::Null)
59    }
60
61    fn nullable(&self, _input_schema: &Schema) -> Result<bool> {
62        Ok(true)
63    }
64
65    fn evaluate(&self, _batch: &RecordBatch) -> Result<ColumnarValue> {
66        internal_err!("NoOp::evaluate() should not be called")
67    }
68
69    fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> {
70        vec![]
71    }
72
73    fn with_new_children(
74        self: Arc<Self>,
75        _children: Vec<Arc<dyn PhysicalExpr>>,
76    ) -> Result<Arc<dyn PhysicalExpr>> {
77        Ok(self)
78    }
79
80    fn fmt_sql(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81        std::fmt::Display::fmt(self, f)
82    }
83}