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