use std::collections::HashMap;
use std::fmt::{self, Display};
use std::hash::{Hash, Hasher};
use std::sync::Arc;
use datafusion_common::config::FormatOptions;
use datafusion_common::{DFSchemaRef, OwnedTableReference};
use crate::LogicalPlan;
#[derive(Clone)]
pub struct CopyTo {
pub input: Arc<LogicalPlan>,
pub output_url: String,
pub partition_by: Vec<String>,
pub format_options: FormatOptions,
pub options: HashMap<String, String>,
}
impl PartialEq for CopyTo {
fn eq(&self, other: &Self) -> bool {
self.input == other.input && self.output_url == other.output_url
}
}
impl Eq for CopyTo {}
impl Hash for CopyTo {
fn hash<H: Hasher>(&self, state: &mut H) {
self.input.hash(state);
self.output_url.hash(state);
}
}
#[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())
}
}