use arrow::array::RecordBatch;
use arrow::datatypes::{DataType, Schema};
use datafusion::common::{internal_err, Result};
use datafusion::physical_expr::PhysicalExpr;
use datafusion::physical_plan::ColumnarValue;
use std::fmt::Formatter;
use std::{hash::Hash, sync::Arc};
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
pub struct UnboundColumn {
name: String,
datatype: DataType,
}
impl UnboundColumn {
pub fn new(name: &str, datatype: DataType) -> Self {
Self {
name: name.to_owned(),
datatype,
}
}
pub fn name(&self) -> &str {
&self.name
}
}
impl std::fmt::Display for UnboundColumn {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}, datatype: {}", self.name, self.datatype)
}
}
impl PhysicalExpr for UnboundColumn {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn fmt_sql(&self, _: &mut Formatter<'_>) -> std::fmt::Result {
unimplemented!()
}
fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
Ok(self.datatype.clone())
}
fn nullable(&self, _input_schema: &Schema) -> Result<bool> {
Ok(true)
}
fn evaluate(&self, _batch: &RecordBatch) -> Result<ColumnarValue> {
internal_err!("UnboundColumn::evaluate() should not be called")
}
fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> {
vec![]
}
fn with_new_children(
self: Arc<Self>,
_children: Vec<Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn PhysicalExpr>> {
Ok(self)
}
}