Skip to content

Commit

Permalink
Merge branch 'main' into refactor_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgao committed Oct 16, 2024
2 parents d31439e + 747001a commit 6de915d
Show file tree
Hide file tree
Showing 18 changed files with 451 additions and 600 deletions.
2 changes: 1 addition & 1 deletion datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6603,7 +6603,7 @@ mod tests {
let not_nulls = not_nulls.finish();
let not_nulls = Some(NullBuffer::new(not_nulls));

let ar = unsafe { StructArray::new_unchecked(fields, arrays, not_nulls) };
let ar = StructArray::new(fields, arrays, not_nulls);
let s = ScalarValue::Struct(Arc::new(ar));

assert_eq!(s.to_string(), "{a:1,b:2}");
Expand Down
3 changes: 1 addition & 2 deletions datafusion/core/tests/fuzz_cases/window_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ use datafusion_physical_expr::{PhysicalExpr, PhysicalSortExpr};
use test_utils::add_empty_batches;

use datafusion::functions_window::row_number::row_number_udwf;
use datafusion_functions_window::dense_rank::dense_rank_udwf;
use datafusion_functions_window::rank::rank_udwf;
use datafusion_functions_window::rank::{dense_rank_udwf, rank_udwf};
use hashbrown::HashMap;
use rand::distributions::Alphanumeric;
use rand::rngs::StdRng;
Expand Down
14 changes: 12 additions & 2 deletions datafusion/expr-common/src/columnar_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

//! [`ColumnarValue`] represents the result of evaluating an expression.
use arrow::array::ArrayRef;
use arrow::array::NullArray;
use arrow::array::{Array, ArrayRef, NullArray};
use arrow::compute::{kernels, CastOptions};
use arrow::datatypes::{DataType, TimeUnit};
use datafusion_common::format::DEFAULT_CAST_OPTIONS;
Expand Down Expand Up @@ -218,6 +217,17 @@ impl ColumnarValue {
}
}
}

/// Converts an [`ArrayRef`] to a [`ColumnarValue`] based on the supplied arguments.
/// This is useful for scalar UDF implementations to fulfil their contract:
/// if all arguments are scalar values, the result should also be a scalar value.
pub fn from_args_and_result(args: &[Self], result: ArrayRef) -> Result<Self> {
if result.len() == 1 && args.iter().all(|arg| matches!(arg, Self::Scalar(_))) {
Ok(Self::Scalar(ScalarValue::try_from_array(&result, 0)?))
} else {
Ok(Self::Array(result))
}
}
}

#[cfg(test)]
Expand Down
205 changes: 0 additions & 205 deletions datafusion/functions-window/src/dense_rank.rs

This file was deleted.

10 changes: 3 additions & 7 deletions datafusion/functions-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ use datafusion_expr::WindowUDF;

#[macro_use]
pub mod macros;
pub mod dense_rank;
pub mod percent_rank;
pub mod rank;
pub mod row_number;

/// Fluent-style API for creating `Expr`s
pub mod expr_fn {
pub use super::dense_rank::dense_rank;
pub use super::percent_rank::percent_rank;
pub use super::rank::rank;
pub use super::rank::{dense_rank, percent_rank, rank};
pub use super::row_number::row_number;
}

Expand All @@ -49,8 +45,8 @@ pub fn all_default_window_functions() -> Vec<Arc<WindowUDF>> {
vec![
row_number::row_number_udwf(),
rank::rank_udwf(),
dense_rank::dense_rank_udwf(),
percent_rank::percent_rank_udwf(),
rank::dense_rank_udwf(),
rank::percent_rank_udwf(),
]
}
/// Registers all enabled packages with a [`FunctionRegistry`]
Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-window/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ macro_rules! create_udwf_expr {
($UDWF:ident, $OUT_FN_NAME:ident, $DOC:expr) => {
paste::paste! {
#[doc = " Create a [`WindowFunction`](datafusion_expr::Expr::WindowFunction) expression for"]
#[doc = concat!(" [`", stringify!($UDWF), "`] user-defined window function.")]
#[doc = concat!(" `", stringify!($UDWF), "` user-defined window function.")]
#[doc = ""]
#[doc = concat!(" ", $DOC)]
pub fn $OUT_FN_NAME() -> datafusion_expr::Expr {
Expand All @@ -316,7 +316,7 @@ macro_rules! create_udwf_expr {
($UDWF:ident, $OUT_FN_NAME:ident, [$($PARAM:ident),+], $DOC:expr) => {
paste::paste! {
#[doc = " Create a [`WindowFunction`](datafusion_expr::Expr::WindowFunction) expression for"]
#[doc = concat!(" [`", stringify!($UDWF), "`] user-defined window function.")]
#[doc = concat!(" `", stringify!($UDWF), "` user-defined window function.")]
#[doc = ""]
#[doc = concat!(" ", $DOC)]
pub fn $OUT_FN_NAME(
Expand Down
Loading

0 comments on commit 6de915d

Please sign in to comment.