Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Dec 21, 2024
1 parent 1a75741 commit 2f83cd0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
42 changes: 30 additions & 12 deletions datafusion/core/tests/user_defined/user_defined_scalar_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,40 +1124,58 @@ async fn test_valid_zero_argument_signatures() {
let signatures = vec![
Signature::exact(vec![], Volatility::Immutable),
Signature::any(0, Volatility::Immutable),
Signature::variadic(vec![], Volatility::Immutable),
Signature::variadic_any(Volatility::Immutable),
Signature::uniform(0, vec![], Volatility::Immutable),
Signature::coercible(vec![], Volatility::Immutable),
Signature::comparable(0, Volatility::Immutable),
Signature::nullary(Volatility::Immutable),
];
for signature in signatures {
let ctx = SessionContext::new();
let udf = ScalarFunctionWrapper {
name: "bad_signature".to_string(),
name: "good_signature".to_string(),
expr: lit(1),
signature,
return_type: DataType::Int32,
};
ctx.register_udf(ScalarUDF::from(udf));
let results = ctx
.sql("select bad_signature()")
.sql("select good_signature()")
.await
.unwrap()
.collect()
.await
.unwrap();
let expected = vec![
"+-----------------+",
"| bad_signature() |",
"+-----------------+",
"| 1 |",
"+-----------------+",
"+------------------+",
"| good_signature() |",
"+------------------+",
"| 1 |",
"+------------------+",
];
assert_batches_eq!(expected, &results);
}
}

#[tokio::test]
async fn test_invalid_zero_argument_signatures() {
let signatures = vec![
Signature::variadic(vec![], Volatility::Immutable),
Signature::variadic_any(Volatility::Immutable),
Signature::uniform(0, vec![], Volatility::Immutable),
Signature::coercible(vec![], Volatility::Immutable),
Signature::comparable(0, Volatility::Immutable),
];
for signature in signatures {
let ctx = SessionContext::new();
let udf = ScalarFunctionWrapper {
name: "bad_signature".to_string(),
expr: lit(1),
signature,
return_type: DataType::Int32,
};
ctx.register_udf(ScalarUDF::from(udf));
let results = ctx.sql("select bad_signature()").await.unwrap_err();
assert_contains!(results.to_string(), "Error during planning: Error during planning: bad_signature does not support zero arguments");
}
}

/// Saves whatever is passed to it as a scalar function
#[derive(Debug, Default)]
struct RecordingFunctionFactory {
Expand Down
5 changes: 0 additions & 5 deletions datafusion/expr-common/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ impl TypeSignature {
match &self {
TypeSignature::Exact(vec) => vec.is_empty(),
TypeSignature::Any(0) => true,
TypeSignature::Variadic(vec) => vec.is_empty(),
TypeSignature::VariadicAny => true,
TypeSignature::Uniform(0, _) => true,
TypeSignature::Coercible(vec) => vec.is_empty(),
TypeSignature::Comparable(0) => true,
TypeSignature::Nullary => true,
TypeSignature::OneOf(types) => types
.iter()
Expand Down

0 comments on commit 2f83cd0

Please sign in to comment.