Skip to content

Commit

Permalink
Remove datafusion-functions-array dependency from datafusion-optimizer (
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Mar 16, 2024
1 parent 81b0a01 commit 00a1225
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 52 deletions.
4 changes: 1 addition & 3 deletions datafusion/optimizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ name = "datafusion_optimizer"
path = "src/lib.rs"

[features]
array_expressions = ["datafusion-functions-array"]
crypto_expressions = ["datafusion-physical-expr/crypto_expressions"]
default = ["unicode_expressions", "crypto_expressions", "regex_expressions", "array_expressions"]
default = ["unicode_expressions", "crypto_expressions", "regex_expressions"]
regex_expressions = ["datafusion-physical-expr/regex_expressions"]
unicode_expressions = ["datafusion-physical-expr/unicode_expressions"]

Expand All @@ -45,7 +44,6 @@ async-trait = { workspace = true }
chrono = { workspace = true }
datafusion-common = { workspace = true, default-features = true }
datafusion-expr = { workspace = true }
datafusion-functions-array = { workspace = true, optional = true }
datafusion-physical-expr = { workspace = true }
hashbrown = { version = "0.14", features = ["raw"] }
itertools = { workspace = true }
Expand Down
51 changes: 2 additions & 49 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,11 @@ mod test {
use std::sync::{Arc, OnceLock};

use crate::analyzer::type_coercion::{
cast_expr, coerce_case_expression, TypeCoercion, TypeCoercionRewriter,
coerce_case_expression, TypeCoercion, TypeCoercionRewriter,
};
use crate::test::assert_analyzed_plan_eq;

use arrow::array::{FixedSizeListArray, Int32Array};
use arrow::datatypes::{DataType, Field, TimeUnit};
use arrow::datatypes::{DataType, TimeUnit};
use datafusion_common::tree_node::{TransformedResult, TreeNode};
use datafusion_common::{DFField, DFSchema, DFSchemaRef, Result, ScalarValue};
use datafusion_expr::expr::{self, InSubquery, Like, ScalarFunction};
Expand All @@ -776,7 +775,6 @@ mod test {
LogicalPlan, Operator, ScalarUDF, ScalarUDFImpl, Signature, SimpleAggregateUDF,
Subquery, Volatility,
};
use datafusion_functions_array::expr_fn::make_array;
use datafusion_physical_expr::expressions::AvgAccumulator;

fn empty() -> Arc<LogicalPlan> {
Expand Down Expand Up @@ -1257,51 +1255,6 @@ mod test {
Ok(())
}

#[test]
fn test_casting_for_fixed_size_list() -> Result<()> {
let val = lit(ScalarValue::FixedSizeList(Arc::new(
FixedSizeListArray::new(
Arc::new(Field::new("item", DataType::Int32, true)),
3,
Arc::new(Int32Array::from(vec![1, 2, 3])),
None,
),
)));
let expr = make_array(vec![val.clone()]);
let schema = Arc::new(DFSchema::new_with_metadata(
vec![DFField::new_unqualified(
"item",
DataType::FixedSizeList(
Arc::new(Field::new("a", DataType::Int32, true)),
3,
),
true,
)],
std::collections::HashMap::new(),
)?);
let mut rewriter = TypeCoercionRewriter { schema };
let result = expr.rewrite(&mut rewriter).data()?;

let schema = Arc::new(DFSchema::new_with_metadata(
vec![DFField::new_unqualified(
"item",
DataType::List(Arc::new(Field::new("a", DataType::Int32, true))),
true,
)],
std::collections::HashMap::new(),
)?);
let expected_casted_expr = cast_expr(
&val,
&DataType::List(Arc::new(Field::new("item", DataType::Int32, true))),
&schema,
)?;

let expected = make_array(vec![expected_casted_expr]);

assert_eq!(result, expected);
Ok(())
}

#[test]
fn test_type_coercion_rewrite() -> Result<()> {
// gt
Expand Down
13 changes: 13 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -6025,12 +6025,25 @@ select make_array(arrow_cast(f0, 'List(Int64)')) from fixed_size_list_array
[[1, 2]]
[[3, 4]]

query T
select arrow_typeof(make_array(arrow_cast(f0, 'List(Int64)'))) from fixed_size_list_array
----
List(Field { name: "item", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
List(Field { name: "item", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })

query ?
select make_array(f0) from fixed_size_list_array
----
[[1, 2]]
[[3, 4]]

query T
select arrow_typeof(make_array(f0)) from fixed_size_list_array
----
List(Field { name: "item", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })
List(Field { name: "item", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })


query ?
select array_concat(column1, [7]) from arrays_values_v2;
----
Expand Down

0 comments on commit 00a1225

Please sign in to comment.