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

chore: bump to datafusion 39, arrow 52, pyo3 0.21 #2581

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ debug = true
debug = "line-tables-only"

[workspace.dependencies]
delta_kernel = { version = "0.1" }
delta_kernel = { git = "https://github.com/abhiaagarwal/delta-kernel-rs", branch = "arrow_52" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should now be updated to 0.1.1

# delta_kernel = { path = "../delta-kernel-rs/kernel" }

# arrow
arrow = { version = "51" }
arrow-arith = { version = "51" }
arrow-array = { version = "51", features = ["chrono-tz"] }
arrow-buffer = { version = "51" }
arrow-cast = { version = "51" }
arrow-ipc = { version = "51" }
arrow-json = { version = "51" }
arrow-ord = { version = "51" }
arrow-row = { version = "51" }
arrow-schema = { version = "51" }
arrow-select = { version = "51" }
object_store = { version = "0.9" }
parquet = { version = "51" }
arrow = { version = "52" }
arrow-arith = { version = "52" }
arrow-array = { version = "52", features = ["chrono-tz"] }
arrow-buffer = { version = "52" }
arrow-cast = { version = "52" }
arrow-ipc = { version = "52" }
arrow-json = { version = "52" }
arrow-ord = { version = "52" }
arrow-row = { version = "52" }
arrow-schema = { version = "52" }
arrow-select = { version = "52" }
object_store = { version = "0.10.1" }
parquet = { version = "52" }

# datafusion
datafusion = { version = "37.1" }
datafusion-expr = { version = "37.1" }
datafusion-common = { version = "37.1" }
datafusion-proto = { version = "37.1" }
datafusion-sql = { version = "37.1" }
datafusion-physical-expr = { version = "37.1" }
datafusion-functions = { version = "37.1" }
datafusion-functions-array = { version = "37.1" }
datafusion = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-expr = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-common = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-proto = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-sql = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-physical-expr = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-functions = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }
datafusion-functions-array = { git = "https://github.com/apache/datafusion", tag = "39.0.0-rc1" }

# serde
serde = { version = "1.0.194", features = ["derive"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/aws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ impl DynamoDbLockClient {
if dynamodb_override_endpoint exists/AWS_ENDPOINT_URL_DYNAMODB is specified by user
use dynamodb_override_endpoint to create dynamodb client
*/
let dynamodb_sdk_config = match dynamodb_override_endpoint {

match dynamodb_override_endpoint {
Some(dynamodb_endpoint_url) => sdk_config
.to_owned()
.to_builder()
.endpoint_url(dynamodb_endpoint_url)
.build(),
None => sdk_config.to_owned(),
};
dynamodb_sdk_config
}
}

/// Create the lock table where DynamoDb stores the commit information for all delta tables.
Expand Down
23 changes: 10 additions & 13 deletions crates/aws/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ use aws_config::provider_config::ProviderConfig;
use aws_config::{Region, SdkConfig};
use bytes::Bytes;
use deltalake_core::storage::object_store::{
aws::AmazonS3ConfigKey, parse_url_opts, GetOptions, GetResult, ListResult, MultipartId,
ObjectMeta, ObjectStore, PutOptions, PutResult, Result as ObjectStoreResult,
aws::AmazonS3ConfigKey, parse_url_opts, GetOptions, GetResult, ListResult, ObjectMeta,
ObjectStore, PutOptions, PutResult, Result as ObjectStoreResult,
};
use deltalake_core::storage::{
limit_store_handler, str_is_truthy, ObjectStoreFactory, ObjectStoreRef, StorageOptions,
};
use deltalake_core::{DeltaResult, ObjectStoreError, Path};
use futures::stream::BoxStream;
use futures::Future;
use object_store::{MultipartUpload, PutMultipartOpts, PutPayload};
use std::collections::HashMap;
use std::fmt::Debug;
use std::ops::Range;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use tokio::io::AsyncWrite;
use url::Url;

use crate::errors::DynamoDbConfigError;
Expand Down Expand Up @@ -334,14 +334,14 @@ impl std::fmt::Debug for S3StorageBackend {

#[async_trait::async_trait]
impl ObjectStore for S3StorageBackend {
async fn put(&self, location: &Path, bytes: Bytes) -> ObjectStoreResult<PutResult> {
async fn put(&self, location: &Path, bytes: PutPayload) -> ObjectStoreResult<PutResult> {
self.inner.put(location, bytes).await
}

async fn put_opts(
&self,
location: &Path,
bytes: Bytes,
bytes: PutPayload,
options: PutOptions,
) -> ObjectStoreResult<PutResult> {
self.inner.put_opts(location, bytes, options).await
Expand Down Expand Up @@ -402,19 +402,16 @@ impl ObjectStore for S3StorageBackend {
}
}

async fn put_multipart(
&self,
location: &Path,
) -> ObjectStoreResult<(MultipartId, Box<dyn AsyncWrite + Unpin + Send>)> {
async fn put_multipart(&self, location: &Path) -> ObjectStoreResult<Box<dyn MultipartUpload>> {
self.inner.put_multipart(location).await
}

async fn abort_multipart(
async fn put_multipart_opts(
&self,
location: &Path,
multipart_id: &MultipartId,
) -> ObjectStoreResult<()> {
self.inner.abort_multipart(location, multipart_id).await
options: PutMultipartOpts,
) -> ObjectStoreResult<Box<dyn MultipartUpload>> {
self.inner.put_multipart_opts(location, options).await
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/aws/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl S3Integration {
"dynamodb",
"create-table",
"--table-name",
&table_name,
table_name,
"--provisioned-throughput",
"ReadCapacityUnits=1,WriteCapacityUnits=1",
"--attribute-definitions",
Expand All @@ -112,7 +112,7 @@ impl S3Integration {
}

fn wait_for_table(table_name: &str) -> std::io::Result<()> {
let args = ["dynamodb", "describe-table", "--table-name", &table_name];
let args = ["dynamodb", "describe-table", "--table-name", table_name];
loop {
let output = Command::new("aws")
.args(args)
Expand Down Expand Up @@ -145,7 +145,7 @@ impl S3Integration {

fn delete_dynamodb_table(table_name: &str) -> std::io::Result<ExitStatus> {
let mut child = Command::new("aws")
.args(["dynamodb", "delete-table", "--table-name", &table_name])
.args(["dynamodb", "delete-table", "--table-name", table_name])
.stdout(Stdio::null())
.spawn()
.expect("aws command is installed");
Expand Down
3 changes: 2 additions & 1 deletion crates/benchmarks/src/bin/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use arrow::datatypes::Schema as ArrowSchema;
use arrow_array::{RecordBatch, StringArray, UInt32Array};
use chrono::Duration;
use clap::{command, Args, Parser, Subcommand};
use datafusion::functions::expr_fn::random;
use datafusion::{datasource::MemTable, prelude::DataFrame};
use datafusion_common::DataFusionError;
use datafusion_expr::{cast, col, lit, random};
use datafusion_expr::{cast, col, lit};
use deltalake_core::protocol::SaveMode;
use deltalake_core::{
arrow::{
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/delta_datafusion/cdf/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ExecutionPlan for DeltaCdfScan {
self.plan.properties()
}

fn children(&self) -> Vec<Arc<dyn ExecutionPlan>> {
fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> {
vec![]
}

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/delta_datafusion/cdf/scan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub fn create_partition_values<F: FileAction>(
partition_values: new_part_values.clone(),
extensions: None,
range: None,
statistics: None,
};

file_groups.entry(new_part_values).or_default().push(part);
Expand Down
66 changes: 18 additions & 48 deletions crates/core/src/delta_datafusion/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use datafusion::execution::context::SessionState;
use datafusion_common::Result as DFResult;
use datafusion_common::{config::ConfigOptions, DFSchema, Result, ScalarValue, TableReference};
use datafusion_expr::{
expr::InList, AggregateUDF, Between, BinaryExpr, Cast, Expr, GetIndexedField, Like, TableSource,
expr::InList, AggregateUDF, Between, BinaryExpr, Cast, Expr, Like, TableSource,
};
use datafusion_sql::planner::{ContextProvider, SqlToRel};
use datafusion_sql::sqlparser::ast::escape_quoted_string;
Expand All @@ -49,7 +49,7 @@ pub(crate) struct DeltaContextProvider<'a> {
}

impl<'a> ContextProvider for DeltaContextProvider<'a> {
fn get_table_provider(&self, _name: TableReference) -> DFResult<Arc<dyn TableSource>> {
fn get_table_source(&self, _name: TableReference) -> DFResult<Arc<dyn TableSource>> {
unimplemented!()
}

Expand All @@ -73,19 +73,15 @@ impl<'a> ContextProvider for DeltaContextProvider<'a> {
self.state.window_functions().get(name).cloned()
}

fn get_table_source(&self, _name: TableReference) -> DFResult<Arc<dyn TableSource>> {
unimplemented!()
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
unimplemented!()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
unimplemented!()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
unimplemented!()
}
}
Expand Down Expand Up @@ -198,7 +194,7 @@ impl<'a> Display for SqlFormat<'a> {
Expr::IsNotFalse(expr) => write!(f, "{} IS NOT FALSE", SqlFormat { expr }),
Expr::IsNotUnknown(expr) => write!(f, "{} IS NOT UNKNOWN", SqlFormat { expr }),
Expr::BinaryExpr(expr) => write!(f, "{}", BinaryExprFormat { expr }),
Expr::ScalarFunction(func) => fmt_function(f, func.func_def.name(), false, &func.args),
Expr::ScalarFunction(func) => fmt_function(f, func.func.name(), false, &func.args),
Expr::Cast(Cast { expr, data_type }) => {
write!(f, "arrow_cast({}, '{}')", SqlFormat { expr }, data_type)
}
Expand Down Expand Up @@ -276,33 +272,6 @@ impl<'a> Display for SqlFormat<'a> {
write!(f, "{expr} IN ({})", expr_vec_fmt!(list))
}
}
Expr::GetIndexedField(GetIndexedField { expr, field }) => match field {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being removed?

Copy link
Contributor Author

@abhiaagarwal abhiaagarwal Jun 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those functions don't exist anymore, and based on my understanding from apache/datafusion#10568, those rewrites happen earlier now so the functionality stays the same, it's just done by DF

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we can catch the new functions and keep the old display formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, I'm not entirely sure this is possible. Those operations have been converted into ScalarFunctions, so the concept of "taking an index of a field" is now "a scalar function that operates on a field and an index". Had to modify a bunch of tests to accommodate.

simple!(
col("_struct").field("a").eq(lit(20_i64)),
"get_field(_struct, 'a') = 20".to_string()
),

It could be possible manually match on scalar functions and convert them into the old style, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it would make the roundtrippable format closer to SQL, but I guess with the timestamp parsing I already kind of stopped doing that 😆

datafusion_expr::GetFieldAccess::NamedStructField { name } => {
write!(
f,
"{}[{}]",
SqlFormat { expr },
ScalarValueFormat { scalar: name }
)
}
datafusion_expr::GetFieldAccess::ListIndex { key } => {
write!(f, "{}[{}]", SqlFormat { expr }, SqlFormat { expr: key })
}
datafusion_expr::GetFieldAccess::ListRange {
start,
stop,
stride,
} => {
write!(
f,
"{expr}[{start}:{stop}:{stride}]",
expr = SqlFormat { expr },
start = SqlFormat { expr: start },
stop = SqlFormat { expr: stop },
stride = SqlFormat { expr: stride }
)
}
},
_ => Err(fmt::Error),
}
}
Expand Down Expand Up @@ -428,11 +397,12 @@ mod test {
use datafusion::prelude::SessionContext;
use datafusion_common::{Column, ScalarValue, ToDFSchema};
use datafusion_expr::expr::ScalarFunction;
use datafusion_expr::{
col, lit, substring, BinaryExpr, Cast, Expr, ExprSchemable, ScalarFunctionDefinition,
};
use datafusion_expr::{col, lit, BinaryExpr, Cast, Expr, ExprSchemable};
use datafusion_functions::core::arrow_cast;
use datafusion_functions::core::expr_ext::FieldAccessor;
use datafusion_functions::encoding::expr_fn::decode;
use datafusion_functions::expr_fn::substring;
use datafusion_functions_array::expr_ext::{IndexAccessor, SliceAccessor};
use datafusion_functions_array::expr_fn::cardinality;

use crate::delta_datafusion::{DataFusionMixins, DeltaSessionContext};
Expand Down Expand Up @@ -564,7 +534,7 @@ mod test {
override_expected_expr: Some(
datafusion_expr::Expr::ScalarFunction(
ScalarFunction {
func_def: ScalarFunctionDefinition::UDF(arrow_cast()),
func: arrow_cast(),
args: vec![
lit(ScalarValue::Int64(Some(1))),
lit(ScalarValue::Utf8(Some("Int32".into())))
Expand Down Expand Up @@ -671,7 +641,7 @@ mod test {
datafusion_expr::Expr::BinaryExpr(BinaryExpr {
left: Box::new(datafusion_expr::Expr::ScalarFunction(
ScalarFunction {
func_def: ScalarFunctionDefinition::UDF(arrow_cast()),
func: arrow_cast(),
args: vec![
col("value"),
lit(ScalarValue::Utf8(Some("Utf8".into())))
Expand All @@ -685,27 +655,27 @@ mod test {
},
simple!(
col("_struct").field("a").eq(lit(20_i64)),
"_struct['a'] = 20".to_string()
"get_field(_struct, 'a') = 20".to_string()
),
simple!(
col("_struct").field("nested").field("b").eq(lit(20_i64)),
"_struct['nested']['b'] = 20".to_string()
"get_field(get_field(_struct, 'nested'), 'b') = 20".to_string()
),
simple!(
col("_list").index(lit(1_i64)).eq(lit(20_i64)),
"_list[1] = 20".to_string()
"array_element(_list, 1) = 20".to_string()
),
simple!(
cardinality(col("_list").range(col("value"), lit(10_i64))),
"cardinality(_list[value:10:1])".to_string()
"cardinality(array_slice(_list, value, 10))".to_string()
),
ParseTest {
expr: col("_timestamp_ntz").gt(lit(ScalarValue::TimestampMicrosecond(Some(1262304000000000), None))),
expected: "_timestamp_ntz > arrow_cast('2010-01-01T00:00:00.000000', 'Timestamp(Microsecond, None)')".to_string(),
override_expected_expr: Some(col("_timestamp_ntz").gt(
datafusion_expr::Expr::ScalarFunction(
ScalarFunction {
func_def: ScalarFunctionDefinition::UDF(arrow_cast()),
func: arrow_cast(),
args: vec![
lit(ScalarValue::Utf8(Some("2010-01-01T00:00:00.000000".into()))),
lit(ScalarValue::Utf8(Some("Timestamp(Microsecond, None)".into())))
Expand All @@ -723,7 +693,7 @@ mod test {
override_expected_expr: Some(col("_timestamp").gt(
datafusion_expr::Expr::ScalarFunction(
ScalarFunction {
func_def: ScalarFunctionDefinition::UDF(arrow_cast()),
func: arrow_cast(),
args: vec![
lit(ScalarValue::Utf8(Some("2010-01-01T00:00:00.000000".into()))),
lit(ScalarValue::Utf8(Some("Timestamp(Microsecond, Some(\"UTC\"))".into())))
Expand Down
13 changes: 11 additions & 2 deletions crates/core/src/delta_datafusion/find_files/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ impl UserDefinedLogicalNodeCore for FindFilesNode {
)
}

fn from_template(&self, _exprs: &[Expr], _inputs: &[LogicalPlan]) -> Self {
self.clone()
fn from_template(&self, exprs: &[Expr], inputs: &[LogicalPlan]) -> Self {
self.with_exprs_and_inputs(exprs.to_vec(), inputs.to_vec())
.unwrap()
}

fn with_exprs_and_inputs(
&self,
_exprs: Vec<Expr>,
_inputs: Vec<LogicalPlan>,
) -> datafusion_common::Result<Self> {
Ok(self.clone())
}
}
Loading
Loading