Skip to content

Commit 35b5363

Browse files
authored
Refactor Spark bitshift signature (apache#18649)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> Part of apache#12725 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> Prefer to avoid user_defined for consistency in function definitions. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Refactor signature of Spark bit shift functions (left, right, right unsigned) to use coercion API instead of being user defined. Also refactor the bit shift code to have a common base struct. Move the Rust unit tests to SLTs. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Existing tests. ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No. <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent dae99ac commit 35b5363

File tree

6 files changed

+489
-592
lines changed

6 files changed

+489
-592
lines changed

datafusion/functions/src/macros.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ macro_rules! export_functions {
7777
}
7878

7979
/// Creates a singleton `ScalarUDF` of the `$UDF` function and a function
80-
/// named `$NAME` which returns that singleton.
80+
/// named `$NAME` which returns that singleton. Optionally use a custom constructor
81+
/// `$CTOR` which defaults to `$UDF::new()` if not specified.
8182
///
8283
/// This is used to ensure creating the list of `ScalarUDF` only happens once.
8384
#[macro_export]
@@ -97,6 +98,21 @@ macro_rules! make_udf_function {
9798
std::sync::Arc::clone(&INSTANCE)
9899
}
99100
};
101+
($UDF:ty, $NAME:ident, $CTOR:path) => {
102+
#[allow(rustdoc::redundant_explicit_links)]
103+
#[doc = concat!("Return a [`ScalarUDF`](datafusion_expr::ScalarUDF) implementation of ", stringify!($NAME))]
104+
pub fn $NAME() -> std::sync::Arc<datafusion_expr::ScalarUDF> {
105+
// Singleton instance of the function
106+
static INSTANCE: std::sync::LazyLock<
107+
std::sync::Arc<datafusion_expr::ScalarUDF>,
108+
> = std::sync::LazyLock::new(|| {
109+
std::sync::Arc::new(datafusion_expr::ScalarUDF::new_from_impl(
110+
$CTOR(),
111+
))
112+
});
113+
std::sync::Arc::clone(&INSTANCE)
114+
}
115+
};
100116
}
101117

102118
/// Creates a singleton `ScalarUDF` of the `$UDF` function and a function

0 commit comments

Comments
 (0)