use std::{
fmt::{self, Display},
sync::Arc,
};
use datafusion_common::{
file_options::StatementOptions, DFSchemaRef, FileType, FileTypeWriterOptions,
OwnedTableReference,
};
use crate::LogicalPlan;
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct CopyTo {
pub input: Arc<LogicalPlan>,
pub output_url: String,
pub file_format: FileType,
pub single_file_output: bool,
pub copy_options: CopyOptions,
}
#[derive(Clone)]
pub enum CopyOptions {
SQLOptions(StatementOptions),
WriterOptions(Box<FileTypeWriterOptions>),
}
impl PartialEq for CopyOptions {
fn eq(&self, other: &CopyOptions) -> bool {
match self {
Self::SQLOptions(statement1) => match other {
Self::SQLOptions(statement2) => statement1.eq(statement2),
Self::WriterOptions(_) => false,
},
Self::WriterOptions(_) => false,
}
}
}
impl Eq for CopyOptions {}
impl std::hash::Hash for CopyOptions {
fn hash<H>(&self, hasher: &mut H)
where
H: std::hash::Hasher,
{
match self {
Self::SQLOptions(statement) => statement.hash(hasher),
Self::WriterOptions(_) => (),
}
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct DmlStatement {
pub table_name: OwnedTableReference,
pub table_schema: DFSchemaRef,
pub op: WriteOp,
pub input: Arc<LogicalPlan>,
}
impl DmlStatement {
pub fn name(&self) -> &str {
self.op.name()
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum WriteOp {
InsertOverwrite,
InsertInto,
Delete,
Update,
Ctas,
}
impl WriteOp {
pub fn name(&self) -> &str {
match self {
WriteOp::InsertOverwrite => "Insert Overwrite",
WriteOp::InsertInto => "Insert Into",
WriteOp::Delete => "Delete",
WriteOp::Update => "Update",
WriteOp::Ctas => "Ctas",
}
}
}
impl Display for WriteOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.name())
}
}