Skip to content

Commit 794a40e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into move-phy-expr-to-common-2
2 parents e4601f5 + 77f43c5 commit 794a40e

49 files changed

Lines changed: 783 additions & 839 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ parquet = { version = "51.0.0", default-features = false, features = ["arrow", "
103103
rand = "0.8"
104104
rstest = "0.19.0"
105105
serde_json = "1"
106-
sqlparser = { version = "0.44.0", features = ["visitor"] }
106+
sqlparser = { version = "0.45.0", features = ["visitor"] }
107107
tempfile = "3"
108108
thiserror = "1.0.44"
109109
tokio = { version = "1.36", features = ["macros", "rt", "sync"] }

datafusion-cli/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/common/src/functional_dependencies.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,48 @@ impl Constraints {
6868
let constraints = constraints
6969
.iter()
7070
.map(|c: &TableConstraint| match c {
71-
TableConstraint::Unique {
72-
columns,
73-
is_primary,
74-
..
75-
} => {
71+
TableConstraint::Unique { name, columns, .. } => {
7672
let field_names = df_schema.field_names();
77-
// Get primary key and/or unique indices in the schema:
73+
// Get unique constraint indices in the schema:
7874
let indices = columns
7975
.iter()
80-
.map(|pk| {
76+
.map(|u| {
8177
let idx = field_names
8278
.iter()
83-
.position(|item| *item == pk.value)
79+
.position(|item| *item == u.value)
8480
.ok_or_else(|| {
81+
let name = name
82+
.as_ref()
83+
.map(|name| format!("with name '{name}' "))
84+
.unwrap_or("".to_string());
8585
DataFusionError::Execution(
86-
"Primary key doesn't exist".to_string(),
86+
format!("Column for unique constraint {}not found in schema: {}", name,u.value)
8787
)
8888
})?;
8989
Ok(idx)
9090
})
9191
.collect::<Result<Vec<_>>>()?;
92-
Ok(if *is_primary {
93-
Constraint::PrimaryKey(indices)
94-
} else {
95-
Constraint::Unique(indices)
96-
})
92+
Ok(Constraint::Unique(indices))
93+
}
94+
TableConstraint::PrimaryKey { columns, .. } => {
95+
let field_names = df_schema.field_names();
96+
// Get primary key indices in the schema:
97+
let indices = columns
98+
.iter()
99+
.map(|pk| {
100+
let idx = field_names
101+
.iter()
102+
.position(|item| *item == pk.value)
103+
.ok_or_else(|| {
104+
DataFusionError::Execution(format!(
105+
"Column for primary key not found in schema: {}",
106+
pk.value
107+
))
108+
})?;
109+
Ok(idx)
110+
})
111+
.collect::<Result<Vec<_>>>()?;
112+
Ok(Constraint::PrimaryKey(indices))
97113
}
98114
TableConstraint::ForeignKey { .. } => {
99115
_plan_err!("Foreign key constraints are not currently supported")

datafusion/common/src/scalar/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,18 @@ impl ScalarValue {
15751575
tz
15761576
)
15771577
}
1578+
DataType::Duration(TimeUnit::Second) => {
1579+
build_array_primitive!(DurationSecondArray, DurationSecond)
1580+
}
1581+
DataType::Duration(TimeUnit::Millisecond) => {
1582+
build_array_primitive!(DurationMillisecondArray, DurationMillisecond)
1583+
}
1584+
DataType::Duration(TimeUnit::Microsecond) => {
1585+
build_array_primitive!(DurationMicrosecondArray, DurationMicrosecond)
1586+
}
1587+
DataType::Duration(TimeUnit::Nanosecond) => {
1588+
build_array_primitive!(DurationNanosecondArray, DurationNanosecond)
1589+
}
15781590
DataType::Interval(IntervalUnit::DayTime) => {
15791591
build_array_primitive!(IntervalDayTimeArray, IntervalDayTime)
15801592
}
@@ -1605,7 +1617,10 @@ impl ScalarValue {
16051617
let arrays = arrays.iter().map(|a| a.as_ref()).collect::<Vec<_>>();
16061618
arrow::compute::concat(arrays.as_slice())?
16071619
}
1608-
DataType::List(_) | DataType::LargeList(_) | DataType::Struct(_) => {
1620+
DataType::List(_)
1621+
| DataType::LargeList(_)
1622+
| DataType::Struct(_)
1623+
| DataType::Union(_, _) => {
16091624
let arrays = scalars.map(|s| s.to_array()).collect::<Result<Vec<_>>>()?;
16101625
let arrays = arrays.iter().map(|a| a.as_ref()).collect::<Vec<_>>();
16111626
arrow::compute::concat(arrays.as_slice())?
@@ -1673,8 +1688,6 @@ impl ScalarValue {
16731688
| DataType::Time32(TimeUnit::Nanosecond)
16741689
| DataType::Time64(TimeUnit::Second)
16751690
| DataType::Time64(TimeUnit::Millisecond)
1676-
| DataType::Duration(_)
1677-
| DataType::Union(_, _)
16781691
| DataType::Map(_, _)
16791692
| DataType::RunEndEncoded(_, _)
16801693
| DataType::Utf8View

datafusion/core/src/datasource/listing/helpers.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ pub fn expr_applicable_for_cols(col_names: &[String], expr: &Expr) -> bool {
9090

9191
Expr::ScalarFunction(scalar_function) => {
9292
match &scalar_function.func_def {
93-
ScalarFunctionDefinition::BuiltIn(fun) => {
94-
match fun.volatility() {
95-
Volatility::Immutable => Ok(TreeNodeRecursion::Continue),
96-
// TODO: Stable functions could be `applicable`, but that would require access to the context
97-
Volatility::Stable | Volatility::Volatile => {
98-
is_applicable = false;
99-
Ok(TreeNodeRecursion::Stop)
100-
}
101-
}
102-
}
10393
ScalarFunctionDefinition::UDF(fun) => {
10494
match fun.signature().volatility {
10595
Volatility::Immutable => Ok(TreeNodeRecursion::Continue),

datafusion/core/src/physical_optimizer/join_selection.rs

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,6 @@ impl PhysicalOptimizerRule for JoinSelection {
305305
/// `CollectLeft` mode is applicable. Otherwise, it will try to swap the join sides.
306306
/// When the `ignore_threshold` is false, this function will also check left
307307
/// and right sizes in bytes or rows.
308-
///
309-
/// For [`JoinType::Full`], it can not use `CollectLeft` mode and will return `None`.
310-
/// For [`JoinType::Left`] and [`JoinType::LeftAnti`], it can not run `CollectLeft`
311-
/// mode as is, but it can do so by changing the join type to [`JoinType::Right`]
312-
/// and [`JoinType::RightAnti`], respectively.
313308
fn try_collect_left(
314309
hash_join: &HashJoinExec,
315310
ignore_threshold: bool,
@@ -318,38 +313,20 @@ fn try_collect_left(
318313
) -> Result<Option<Arc<dyn ExecutionPlan>>> {
319314
let left = hash_join.left();
320315
let right = hash_join.right();
321-
let join_type = hash_join.join_type();
322316

323-
let left_can_collect = match join_type {
324-
JoinType::Left | JoinType::Full | JoinType::LeftAnti => false,
325-
JoinType::Inner
326-
| JoinType::LeftSemi
327-
| JoinType::Right
328-
| JoinType::RightSemi
329-
| JoinType::RightAnti => {
330-
ignore_threshold
331-
|| supports_collect_by_thresholds(
332-
&**left,
333-
threshold_byte_size,
334-
threshold_num_rows,
335-
)
336-
}
337-
};
338-
let right_can_collect = match join_type {
339-
JoinType::Right | JoinType::Full | JoinType::RightAnti => false,
340-
JoinType::Inner
341-
| JoinType::RightSemi
342-
| JoinType::Left
343-
| JoinType::LeftSemi
344-
| JoinType::LeftAnti => {
345-
ignore_threshold
346-
|| supports_collect_by_thresholds(
347-
&**right,
348-
threshold_byte_size,
349-
threshold_num_rows,
350-
)
351-
}
352-
};
317+
let left_can_collect = ignore_threshold
318+
|| supports_collect_by_thresholds(
319+
&**left,
320+
threshold_byte_size,
321+
threshold_num_rows,
322+
);
323+
let right_can_collect = ignore_threshold
324+
|| supports_collect_by_thresholds(
325+
&**right,
326+
threshold_byte_size,
327+
threshold_num_rows,
328+
);
329+
353330
match (left_can_collect, right_can_collect) {
354331
(true, true) => {
355332
if should_swap_join_order(&**left, &**right)?
@@ -916,9 +893,9 @@ mod tests_statistical {
916893
}
917894

918895
#[tokio::test]
919-
async fn test_left_join_with_swap() {
896+
async fn test_left_join_no_swap() {
920897
let (big, small) = create_big_and_small();
921-
// Left out join should alway swap when the mode is PartitionMode::CollectLeft, even left side is small and right side is large
898+
922899
let join = Arc::new(
923900
HashJoinExec::try_new(
924901
Arc::clone(&small),
@@ -942,32 +919,18 @@ mod tests_statistical {
942919
.optimize(join.clone(), &ConfigOptions::new())
943920
.unwrap();
944921

945-
let swapping_projection = optimized_join
946-
.as_any()
947-
.downcast_ref::<ProjectionExec>()
948-
.expect("A proj is required to swap columns back to their original order");
949-
950-
assert_eq!(swapping_projection.expr().len(), 2);
951-
let (col, name) = &swapping_projection.expr()[0];
952-
assert_eq!(name, "small_col");
953-
assert_col_expr(col, "small_col", 1);
954-
let (col, name) = &swapping_projection.expr()[1];
955-
assert_eq!(name, "big_col");
956-
assert_col_expr(col, "big_col", 0);
957-
958-
let swapped_join = swapping_projection
959-
.input()
922+
let swapped_join = optimized_join
960923
.as_any()
961924
.downcast_ref::<HashJoinExec>()
962925
.expect("The type of the plan should not be changed");
963926

964927
assert_eq!(
965928
swapped_join.left().statistics().unwrap().total_byte_size,
966-
Precision::Inexact(2097152)
929+
Precision::Inexact(8192)
967930
);
968931
assert_eq!(
969932
swapped_join.right().statistics().unwrap().total_byte_size,
970-
Precision::Inexact(8192)
933+
Precision::Inexact(2097152)
971934
);
972935
crosscheck_plans(join.clone()).unwrap();
973936
}

0 commit comments

Comments
 (0)