alamb commented on code in PR #15965:
URL: https://github.com/apache/datafusion/pull/15965#discussion_r2076257011
##########
datafusion/catalog/src/information_schema.rs:
##########
@@ -403,73 +404,89 @@ impl InformationSchemaConfig {
/// returns a tuple of (arg_types, return_type)
fn get_udf_args_and_return_types(
udf: &Arc<ScalarUDF>,
-) -> Result<Vec<(Vec<String>, Option<String>)>> {
+) -> Result<BTreeSet<(Vec<String>, Option<String>)>> {
let signature = udf.signature();
let arg_types = signature.type_signature.get_example_types();
if arg_types.is_empty() {
- Ok(vec![(vec![], None)])
+ Ok(vec![(vec![], None)].into_iter().collect::<BTreeSet<_>>())
} else {
Ok(arg_types
.into_iter()
.map(|arg_types| {
// only handle the function which implemented
[`ScalarUDFImpl::return_type`] method
- let return_type = udf.return_type(&arg_types).ok().map(|t|
t.to_string());
+ let return_type = udf
+ .return_type(&arg_types)
+ .map(|t| remove_native_type_prefix(NativeType::from(t)))
+ .ok();
let arg_types = arg_types
.into_iter()
- .map(|t| t.to_string())
+ .map(|t| remove_native_type_prefix(NativeType::from(t)))
.collect::<Vec<_>>();
(arg_types, return_type)
})
- .collect::<Vec<_>>())
+ .collect::<BTreeSet<_>>())
}
}
fn get_udaf_args_and_return_types(
udaf: &Arc<AggregateUDF>,
-) -> Result<Vec<(Vec<String>, Option<String>)>> {
+) -> Result<BTreeSet<(Vec<String>, Option<String>)>> {
let signature = udaf.signature();
let arg_types = signature.type_signature.get_example_types();
if arg_types.is_empty() {
- Ok(vec![(vec![], None)])
+ Ok(vec![(vec![], None)].into_iter().collect::<BTreeSet<_>>())
} else {
Ok(arg_types
.into_iter()
.map(|arg_types| {
// only handle the function which implemented
[`ScalarUDFImpl::return_type`] method
- let return_type =
- udaf.return_type(&arg_types).ok().map(|t| t.to_string());
+ let return_type = udaf
+ .return_type(&arg_types)
+ .ok()
+ .map(|t| remove_native_type_prefix(NativeType::from(t)));
let arg_types = arg_types
.into_iter()
- .map(|t| t.to_string())
+ .map(|t| remove_native_type_prefix(NativeType::from(t)))
.collect::<Vec<_>>();
(arg_types, return_type)
})
- .collect::<Vec<_>>())
+ .collect::<BTreeSet<_>>())
}
}
fn get_udwf_args_and_return_types(
udwf: &Arc<WindowUDF>,
-) -> Result<Vec<(Vec<String>, Option<String>)>> {
+) -> Result<BTreeSet<(Vec<String>, Option<String>)>> {
let signature = udwf.signature();
let arg_types = signature.type_signature.get_example_types();
if arg_types.is_empty() {
- Ok(vec![(vec![], None)])
+ Ok(vec![(vec![], None)].into_iter().collect::<BTreeSet<_>>())
} else {
Ok(arg_types
.into_iter()
.map(|arg_types| {
// only handle the function which implemented
[`ScalarUDFImpl::return_type`] method
let arg_types = arg_types
.into_iter()
- .map(|t| t.to_string())
+ .map(|t| remove_native_type_prefix(NativeType::from(t)))
.collect::<Vec<_>>();
(arg_types, None)
})
- .collect::<Vec<_>>())
+ .collect::<BTreeSet<_>>())
}
}
+#[inline]
+fn remove_native_type_prefix(native_type: NativeType) -> String {
+ // native_type.to_string() is like "NATIVE_TYPE_PREFIX + native_type"
+ // here is safe to unwrap directly
+ native_type
+ .to_string()
+ .strip_prefix(NATIVE_TYPE_PREFIX)
+ .unwrap()
+ .to_string()
Review Comment:
It would be nice to avoid having to do string manipulations on something we
know is valid at compile time
My reading suggests that this is equivalent and is simpler, and would save a
few copies and allocations
```suggestion
format!("{native_type:?}")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]