MCPcopy Create free account
hub / github.com/apache/datafusion / spark_pmod

Function spark_pmod

datafusion/spark/src/function/math/modulus.rs:71–86  ·  view source on GitHub ↗

Spark-compatible `pmod` function In ANSI mode, division by zero throws an error. In legacy mode, division by zero returns NULL (Spark behavior).

(
    args: &[ColumnarValue],
    enable_ansi_mode: bool,
)

Source from the content-addressed store, hash-verified

69/// In ANSI mode, division by zero throws an error.
70/// In legacy mode, division by zero returns NULL (Spark behavior).
71pub fn spark_pmod(
72 args: &[ColumnarValue],
73 enable_ansi_mode: bool,
74) -> Result<ColumnarValue> {
75 assert_eq_or_internal_err!(args.len(), 2, "pmod expects exactly two arguments");
76 let args = ColumnarValue::values_to_arrays(args)?;
77 let left = &args[0];
78 let right = &args[1];
79 let zero = ScalarValue::new_zero(left.data_type())?.to_array_of_size(left.len())?;
80 let result = try_rem(left, right, enable_ansi_mode)?;
81 let neg = lt(&result, &zero)?;
82 let plus = zip(&neg, right, &zero)?;
83 let result = add(&plus, &result)?;
84 let result = try_rem(&result, right, enable_ansi_mode)?;
85 Ok(ColumnarValue::Array(result))
86}
87
88/// SparkMod implements the Spark-compatible modulo function
89#[derive(Debug, PartialEq, Eq, Hash)]

Callers 11

invoke_with_argsMethod · 0.85
test_pmod_int32Function · 0.85
test_pmod_int64Function · 0.85
test_pmod_float64Function · 0.85
test_pmod_float32Function · 0.85
test_pmod_scalarFunction · 0.85
test_pmod_edge_casesFunction · 0.85

Calls 6

values_to_arraysFunction · 0.85
try_remFunction · 0.85
addFunction · 0.85
to_array_of_sizeMethod · 0.45
data_typeMethod · 0.45
lenMethod · 0.45

Tested by 10

test_pmod_int32Function · 0.68
test_pmod_int64Function · 0.68
test_pmod_float64Function · 0.68
test_pmod_float32Function · 0.68
test_pmod_scalarFunction · 0.68
test_pmod_edge_casesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…