Skip to content
Merged
Changes from all commits
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: 16 additions & 7 deletions rust/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ impl Dataset {
}

// append + dataset doesn't already exists = warn + switch to create mode
if !flag_dataset_exists && matches!(params.mode, WriteMode::Append) {
if !flag_dataset_exists
&& (matches!(params.mode, WriteMode::Append)
|| matches!(params.mode, WriteMode::Overwrite))
{
eprintln!("Warning: No existing dataset at {uri}, it will be created");
params = WriteParams {
mode: WriteMode::Create,
Expand Down Expand Up @@ -713,10 +716,7 @@ mod tests {
use futures::stream::TryStreamExt;
use tempfile::tempdir;

#[tokio::test]
async fn create_dataset() {
let test_dir = tempdir().unwrap();

async fn create_file(path: &std::path::Path, mode: WriteMode) {
let schema = Arc::new(ArrowSchema::new(vec![
Field::new("i", DataType::Int32, false),
Field::new(
Expand Down Expand Up @@ -748,11 +748,11 @@ mod tests {
);
let expected_batches = batches.batches.clone();

let test_uri = test_dir.path().to_str().unwrap();

let test_uri = path.to_str().unwrap();
let mut write_params = WriteParams::default();
write_params.max_rows_per_file = 40;
write_params.max_rows_per_group = 10;
write_params.mode = mode;
let mut reader: Box<dyn RecordBatchReader> = Box::new(batches);
Dataset::write(&mut reader, test_uri, Some(write_params))
.await
Expand Down Expand Up @@ -793,6 +793,15 @@ mod tests {
)
}

#[tokio::test]
async fn test_create_dataset() {
// Appending / Overwriting a dataset that does not exist is treated as Create
for mode in [WriteMode::Create, WriteMode::Append, Overwrite] {
let test_dir = tempdir().unwrap();
create_file(test_dir.path(), mode).await
}
}

#[tokio::test]
async fn append_dataset() {
let test_dir = tempdir().unwrap();
Expand Down