Skip to content

Commit

Permalink
Fix for replaceWhere
Browse files Browse the repository at this point in the history
Fix for Rust example in 'Overwriting part of the table data using a predicate' part of the delta-rs webpage
  • Loading branch information
LauH1987 authored and rtyler committed Mar 19, 2024
1 parent 7379d09 commit f32779d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docs/src/rust/operations.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// --8<-- [start:replace_where]
// Assuming there is already a table in this location with some records where `id = '1'` which we want to overwrite
use arrow_schema::{DataType, Field, Schema as ArrowSchema};
use arrow_array::RecordBatch;
import deltalake::protocol::SaveMode;
use arrow_schema::{DataType, Field, Schema as ArrowSchema};
use deltalake::datafusion::logical_expr::{col, lit};
use deltalake::protocol::SaveMode;
use deltalake::DeltaOps;

let schema = ArrowSchema::new(vec![
Field::new("id", DataType::Utf8, true),
Field::new("value", DataType::Int32, true),
]);

let data = RecordBatch::try_new(
&schema,
schema.into(),
vec![
Arc::new(arrow::array::StringArray::from(vec!["1", "1"])),
Arc::new(arrow::array::Int32Array::from(vec![11, 12])),
Expand All @@ -21,11 +25,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap();

let table = deltalake::open_table("/tmp/my_table").await.unwrap();
let table = DeltaOps(table)
let _table = DeltaOps(table)
.write(vec![data])
.with_save_mode(SaveMode::Overwrite)
.with_replace_where(col("id").eq(lit("1")))
.await;
.await
.unwrap();
// --8<-- [end:replace_where]

Ok(())
Expand Down

0 comments on commit f32779d

Please sign in to comment.