Skip to content

Commit

Permalink
use FilePath::try_from_local
Browse files Browse the repository at this point in the history
  • Loading branch information
jbellis committed Feb 28, 2023
1 parent 5556089 commit 5f5f5c6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/sparrow-main/src/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use error_stack::{IntoReport, ResultExt};
use sparrow_api::kaskada::v1alpha::{file_path, FilePath, PrepareDataRequest, SlicePlan};
use error_stack::{IntoReport, IntoReportCompat, ResultExt};
use sparrow_api::kaskada::v1alpha::{FilePath, PrepareDataRequest, SlicePlan};

use sparrow_runtime::s3::S3Helper;

Expand Down Expand Up @@ -48,6 +48,8 @@ pub enum Error {
Preparing,
#[display(fmt = "canonicalize paths")]
Canonicalize,
#[display(fmt = "unrecognized input format")]
UnrecognizedInputFormat,
}

impl error_stack::Context for Error {}
Expand Down Expand Up @@ -113,13 +115,9 @@ impl PrepareCommand {
.change_context(Error::Canonicalize)
.attach_printable_lazy(|| LabeledPath::new("input path", self.input.clone()))?;

// given the input path, we need to create a file path corresponding to its extension.
// non-CSV files are assumed to be Parquet.
let input_string = input.as_os_str().to_string_lossy().to_string();
let file_path = match std::path::Path::new(&input_string).extension() {
Some(ext) if ext == "csv" => file_path::Path::CsvPath(input_string),
_ => file_path::Path::ParquetPath(input_string),
};
let file_path = FilePath::try_from_local(input.as_path())
.into_report()
.change_context(Error::UnrecognizedInputFormat)?;

let sp = SlicePlan {
table_name: config.name.clone(),
Expand Down

0 comments on commit 5f5f5c6

Please sign in to comment.