alamb commented on code in PR #11488: URL: https://github.com/apache/datafusion/pull/11488#discussion_r1680758744
########## datafusion/functions/src/udf.rs: ########## @@ -0,0 +1,142 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::sync::Arc; + +use arrow::{ + array::{Array, ArrayRef, RecordBatch}, + datatypes::{Field, Schema, SchemaRef}, +}; +use arrow_udf::{function, sig::REGISTRY}; +use datafusion_common::{internal_err, DataFusionError, Result}; +use datafusion_expr::ColumnarValue; +// use arrow_string::predicate::Predicate; + +#[function("eq(boolean, boolean) -> boolean")] Review Comment: this is pretty neat ########## datafusion/functions/src/udf.rs: ########## @@ -0,0 +1,142 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::sync::Arc; + +use arrow::{ + array::{Array, ArrayRef, RecordBatch}, + datatypes::{Field, Schema, SchemaRef}, +}; +use arrow_udf::{function, sig::REGISTRY}; +use datafusion_common::{internal_err, DataFusionError, Result}; +use datafusion_expr::ColumnarValue; +// use arrow_string::predicate::Predicate; + +#[function("eq(boolean, boolean) -> boolean")] +#[function("eq(int8, int8) -> boolean")] +#[function("eq(int16, int16) -> boolean")] +#[function("eq(int32, int32) -> boolean")] +#[function("eq(int64, int64) -> boolean")] +#[function("eq(uint8, uint8) -> boolean")] +#[function("eq(uint16, uint16) -> boolean")] +#[function("eq(uint32, uint32) -> boolean")] +#[function("eq(uint64, uint64) -> boolean")] +#[function("eq(string, string) -> boolean")] +#[function("eq(binary, binary) -> boolean")] +#[function("eq(largestring, largestring) -> boolean")] +#[function("eq(largebinary, largebinary) -> boolean")] +#[function("eq(date32, date32) -> boolean")] +// #[function("eq(struct Dictionary, struct Dictionary) -> boolean")] +fn eq<T: Eq>(lhs: T, rhs: T) -> bool { + lhs == rhs +} + +// Bad, we could not use the non-public API +// fn like(lhs: &str, rhs: &str) -> bool { +// Predicate::like(rhs).unwrap().matches(lhs); +// } + +#[function("concat(string, string) -> string")] +#[function("concat(largestring, largestring) -> largestring")] +fn concat(lhs: &str, rhs: &str) -> String { + format!("{}{}", lhs, rhs) +} + +pub fn apply_udf( Review Comment: This is the code that adapts `ColumnarValue` to being able to call the `arrow-udf` based functions via a record batch, right? -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org