Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Datafusion file sink #2155

Merged
merged 11 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions vortex-datafusion/src/persistent/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use datafusion_common::stats::Precision;
use datafusion_common::{
not_impl_err, ColumnStatistics, DataFusionError, Result as DFResult, ScalarValue, Statistics,
};
use datafusion_expr::dml::InsertOp;
use datafusion_expr::Expr;
use datafusion_physical_expr::{LexRequirement, PhysicalExpr};
use datafusion_physical_plan::insert::DataSinkExec;
use datafusion_physical_plan::metrics::ExecutionPlanMetricsSet;
use datafusion_physical_plan::ExecutionPlan;
use futures::{stream, StreamExt as _, TryStreamExt as _};
Expand All @@ -29,6 +31,7 @@ use vortex_scalar::Scalar;

use super::cache::FileLayoutCache;
use super::execution::VortexExec;
use super::sink::VortexSink;
use crate::can_be_pushed_down;

/// Vortex implementation of a DataFusion [`FileFormat`].
Expand Down Expand Up @@ -237,12 +240,24 @@ impl FileFormat for VortexFormat {

async fn create_writer_physical_plan(
&self,
_input: Arc<dyn ExecutionPlan>,
input: Arc<dyn ExecutionPlan>,
_state: &SessionState,
_conf: FileSinkConfig,
_order_requirements: Option<LexRequirement>,
conf: FileSinkConfig,
order_requirements: Option<LexRequirement>,
) -> DFResult<Arc<dyn ExecutionPlan>> {
not_impl_err!("Writer not implemented for this format")
if conf.insert_op != InsertOp::Append {
return not_impl_err!("Overwrites are not implemented yet for Parquet");
}

let sink = Arc::new(VortexSink::new(conf));
let sink_schema = input.schema();

Ok(Arc::new(DataSinkExec::new(
input,
sink,
sink_schema,
order_requirements,
)) as _)
}

fn supports_filters_pushdown(
Expand Down
1 change: 1 addition & 0 deletions vortex-datafusion/src/persistent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ mod config;
mod execution;
mod format;
mod opener;
mod sink;

pub use format::{VortexFormat, VortexFormatOptions};
60 changes: 60 additions & 0 deletions vortex-datafusion/src/persistent/sink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::any::Any;
use std::sync::Arc;

use async_trait::async_trait;
use datafusion::datasource::physical_plan::FileSinkConfig;
use datafusion_execution::{SendableRecordBatchStream, TaskContext};
use datafusion_physical_plan::insert::DataSink;
use datafusion_physical_plan::metrics::MetricsSet;
use datafusion_physical_plan::{DisplayAs, DisplayFormatType};

pub struct VortexSink {
config: FileSinkConfig,
}

impl VortexSink {
pub fn new(config: FileSinkConfig) -> Self {
Self { config }
}
}

impl std::fmt::Debug for VortexSink {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VortexSink").finish()
}
}

impl DisplayAs for VortexSink {
fn fmt_as(&self, t: DisplayFormatType, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match t {
DisplayFormatType::Default | DisplayFormatType::Verbose => {
write!(f, "VortexSink")
}
}
}
}

#[async_trait]
impl DataSink for VortexSink {
fn as_any(&self) -> &dyn Any {
self
}

fn metrics(&self) -> Option<MetricsSet> {
None
}

async fn write_all(
&self,
mut data: SendableRecordBatchStream,
context: &Arc<TaskContext>,
) -> datafusion_common::error::Result<u64> {
let object_store = context
.runtime_env()
.object_store(&self.config.object_store_url)?;

let base_output_path = &self.config.table_paths[0];

todo!()
AdamGS marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading