Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions datafusion/functions-nested/src/make_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use datafusion_expr::{
ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
Volatility,
};
use datafusion_expr_common::sort_properties::ExprProperties;
use datafusion_macros::user_doc;
use itertools::Itertools as _;

Expand Down Expand Up @@ -113,6 +114,11 @@ impl ScalarUDFImpl for MakeArray {
&self.aliases
}

fn strictly_order_preserving(&self, _inputs: &[ExprProperties]) -> Result<bool> {
// Not strictly order preserving since null input does not correspond to null output
Ok(false)
}

fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
if arg_types.is_empty() {
Ok(vec![])
Expand Down
7 changes: 7 additions & 0 deletions datafusion/functions-nested/src/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use datafusion_expr::{
Volatility,
};
use datafusion_expr_common::signature::{Coercion, TypeSignatureClass};
use datafusion_expr_common::sort_properties::ExprProperties;
use datafusion_macros::user_doc;
use std::mem::size_of;
use std::sync::Arc;
Expand Down Expand Up @@ -137,6 +138,12 @@ impl ScalarUDFImpl for ArrayRepeat {
make_scalar_function(array_repeat_inner)(&args.args)
}

fn strictly_order_preserving(&self, _inputs: &[ExprProperties]) -> Result<bool> {
// this is not strictly order preserving
// since array_repeat(NULL, 2) = [NULL, NULL] and not NULL
Ok(false)
}

fn aliases(&self) -> &[String] {
&self.aliases
}
Expand Down
12 changes: 12 additions & 0 deletions datafusion/functions/src/math/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use datafusion_expr::{
ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
Volatility,
};
use datafusion_expr_common::sort_properties::{ExprProperties, SortProperties};
use datafusion_macros::user_doc;

#[user_doc(
Expand Down Expand Up @@ -116,6 +117,17 @@ impl ScalarUDFImpl for FactorialFunc {
}
}

fn output_ordering(&self, inputs: &[ExprProperties]) -> Result<SortProperties> {
// Keep the same ordering as the input
Ok(inputs[0].sort_properties)
}

fn strictly_order_preserving(&self, _inputs: &[ExprProperties]) -> Result<bool> {
// There is one-to-one mapping between input and output and nulls maps to nulls
// and because overflow will be resulted in an error and not wrapping or saturating we are ok
Ok(true)
Comment on lines +126 to +128

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is right: factorial(0) == factorial(1) == 1.

}

fn documentation(&self) -> Option<&Documentation> {
self.doc()
}
Expand Down
5 changes: 5 additions & 0 deletions datafusion/functions/src/math/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ impl ScalarUDFImpl for FloorFunc {
Ok(input[0].sort_properties)
}

fn strictly_order_preserving(&self, _inputs: &[ExprProperties]) -> Result<bool> {
// floor allow distinct inputs to collapse into equal outputs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"allows"

Ok(false)
}

fn evaluate_bounds(&self, inputs: &[&Interval]) -> Result<Interval> {
let data_type = inputs[0].data_type();
Interval::make_unbounded(&data_type)
Expand Down
7 changes: 7 additions & 0 deletions datafusion/functions/src/string/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use datafusion_common::{
use datafusion_expr::{ColumnarValue, Documentation, Volatility};
use datafusion_expr::{ScalarFunctionArgs, ScalarUDFImpl, Signature};
use datafusion_expr_common::signature::{Coercion, TypeSignatureClass};
use datafusion_expr_common::sort_properties::ExprProperties;
use datafusion_macros::user_doc;

#[user_doc(
Expand Down Expand Up @@ -160,6 +161,12 @@ impl ScalarUDFImpl for RepeatFunc {
fn documentation(&self) -> Option<&Documentation> {
self.doc()
}

fn strictly_order_preserving(&self, _inputs: &[ExprProperties]) -> Result<bool> {
// repeat does not strictly preserve ordering since for the following 2 rows:
// "bc" and "bca" and repeat(2) the result will be "bcbc" and "bcabca" which now the order is different
Comment on lines +166 to +167

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// repeat does not strictly preserve ordering since for the following 2 rows:
// "bc" and "bca" and repeat(2) the result will be "bcbc" and "bcabca" which now the order is different
// repeat('bc', 2) = 'bcbc' > repeat('bca', 2) = 'bcabca', so ordering is not preserved

Ok(false)
}
}

/// Computes repeat for a single string value with max size check
Expand Down
Loading