Creating a Delta Lake Table
This section explains how to create a Delta Lake table.
You can easily write a DataFrame to a Delta table.
let table = CreateBuilder::new()
.with_location(path)
.with_table_name("/tmp/some-table")
.with_save_mode(SaveMode::Overwrite)
.with_columns(
StructType::try_new(vec![
StructField::new(
"num".to_string(),
DataType::Primitive(PrimitiveType::Integer),
true,
),
StructField::new(
"letter".to_string(),
DataType::Primitive(PrimitiveType::String),
true,
),
])?
.fields()
.cloned(),
)
.await?;
use arrow_schema::{Field, Schema, DataType as ArrowDataType};
let data = RecordBatch::try_new(
Arc::new(Schema::new(vec![
Field::new("num", ArrowDataType::Int32, true),
Field::new("letter", ArrowDataType::Utf8, true),
])),
vec![
Arc::new(arrow::array::Int32Array::from(vec![1, 2, 3])),
Arc::new(arrow::array::StringArray::from(vec!["a", "b", "c"])),
],
)?;
table
.write(vec![data])
.with_save_mode(SaveMode::Overwrite)
.await?;
Here are the contents of the Delta table in storage: