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

fix: load command for local tables #1205

Merged
merged 1 commit into from
Mar 4, 2023
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
31 changes: 28 additions & 3 deletions rust/src/operations/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use crate::storage::DeltaObjectStore;
use crate::{DeltaResult, DeltaTable, DeltaTableError};
use crate::{builder::ensure_table_uri, DeltaResult, DeltaTable};

use datafusion::datasource::TableProvider;
use datafusion::execution::context::{SessionContext, TaskContext};
Expand Down Expand Up @@ -77,8 +77,7 @@ impl std::future::IntoFuture for LoadBuilder {

Box::pin(async move {
let object_store = this.object_store.unwrap();
let url = url::Url::parse(&object_store.root_uri())
.map_err(|_| DeltaTableError::InvalidTableLocation(object_store.root_uri()))?;
let url = ensure_table_uri(object_store.root_uri())?;
let store = object_store.storage_backend().clone();
let mut table = DeltaTable::new(object_store, Default::default());
table.load().await?;
Expand All @@ -100,8 +99,34 @@ impl std::future::IntoFuture for LoadBuilder {
mod tests {
use crate::operations::{collect_sendable_stream, DeltaOps};
use crate::writer::test_utils::{get_record_batch, TestResult};
use crate::DeltaTableBuilder;
use datafusion::assert_batches_sorted_eq;

#[tokio::test]
async fn test_load_local() -> TestResult {
let table = DeltaTableBuilder::from_uri("./tests/data/delta-0.8.0")
.load()
.await
.unwrap();

let (_table, stream) = DeltaOps(table).load().await?;
let data = collect_sendable_stream(stream).await?;

let expected = vec![
"+-------+",
"| value |",
"+-------+",
"| 0 |",
"| 1 |",
"| 2 |",
"| 4 |",
"+-------+",
];

assert_batches_sorted_eq!(&expected, &data);
Ok(())
}

#[tokio::test]
async fn test_write_load() -> TestResult {
let batch = get_record_batch(None, false);
Expand Down