Jefffrey commented on code in PR #17485:
URL: https://github.com/apache/datafusion/pull/17485#discussion_r2342725033


##########
datafusion/sqllogictest/test_files/spark/url/try_parse_url.slt:
##########
@@ -0,0 +1,72 @@
+# 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.
+
+# This file was originally created by a porting script from:
+#   
https://github.com/lakehq/sail/blob/b6095cc7fccaf016b47f009ba93b2357dc781a7d/python/pysail/tests/spark/function/test_try_parse_url.txt
+# This file is part of the implementation of the datafusion-spark function 
library.
+# For more information, please see:
+#   https://github.com/apache/datafusion/issues/15914
+
+query T
+SELECT try_parse_url('https://example.com/a?x=1', 'QUERY', 'x');
+----
+1
+
+query T
+SELECT try_parse_url('www.example.com/path?x=1', 'HOST');
+----
+NULL
+
+query T
+SELECT try_parse_url('https://example.com/?a=1', 'QUERY', 'b');
+----
+NULL
+
+query T
+SELECT try_parse_url('https://example.com/path#frag', 'REF');

Review Comment:
   Thanks for confirming this on Spark ❤️ 



##########
datafusion/spark/src/function/url/parse_url.rs:
##########
@@ -47,23 +46,7 @@ impl Default for ParseUrl {
 impl ParseUrl {
     pub fn new() -> Self {
         Self {
-            signature: Signature::one_of(
-                vec![
-                    TypeSignature::Uniform(
-                        1,
-                        vec![DataType::Utf8View, DataType::Utf8, 
DataType::LargeUtf8],
-                    ),
-                    TypeSignature::Uniform(
-                        2,
-                        vec![DataType::Utf8View, DataType::Utf8, 
DataType::LargeUtf8],
-                    ),
-                    TypeSignature::Uniform(
-                        3,
-                        vec![DataType::Utf8View, DataType::Utf8, 
DataType::LargeUtf8],
-                    ),
-                ],
-                Volatility::Immutable,
-            ),
+            signature: Signature::user_defined(Volatility::Immutable),

Review Comment:
   That's correct, but my point was previously (on main), `parse_url` seems to 
be capable of accepting string dictionary types, but with these changes that is 
no longer possible; is this something to be concerned about?



##########
datafusion/spark/src/function/url/parse_url.rs:
##########
@@ -291,11 +562,205 @@ where
         .zip(key_array.iter())
         .map(|((url, part), key)| {
             if let (Some(url), Some(part), key) = (url, part, key) {
-                ParseUrl::parse(url, part, key)
+                handle(ParseUrl::parse(url, part, key))
             } else {
                 Ok(None)
             }
         })
         .collect::<Result<T>>()
         .map(|array| Arc::new(array) as ArrayRef)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use arrow::array::{ArrayRef, Int32Array, LargeStringArray, StringArray};
+    use arrow::datatypes::DataType;
+    use datafusion_common::Result;
+    use std::sync::Arc;
+
+    fn sa(vals: &[Option<&str>]) -> ArrayRef {
+        Arc::new(StringArray::from(vals.to_vec())) as ArrayRef
+    }
+    fn lsa(vals: &[Option<&str>]) -> ArrayRef {
+        Arc::new(LargeStringArray::from(vals.to_vec())) as ArrayRef
+    }
+
+    #[test]

Review Comment:
   I feel quite a few of these tests could be done as slt tests; @alamb do we 
have a preference on where tests should be done? Should we prefer slt over rust 
tests, and fallback only to rust if it is something that slt can't handle?
   
   Took a look at https://datafusion.apache.org/contributor-guide/testing.html 
but it doesn't mention if we have a specific preference, other than slt's being 
easier to maintain.



##########
datafusion/spark/src/function/url/mod.rs:
##########
@@ -20,15 +20,18 @@ use datafusion_functions::make_udf_function;
 use std::sync::Arc;
 
 pub mod parse_url;
+pub mod try_parse_url;
 
 make_udf_function!(parse_url::ParseUrl, parse_url);
+make_udf_function!(try_parse_url::TryParseUrl, try_parse_url);
 
 pub mod expr_fn {
     use datafusion_functions::export_functions;
 
     export_functions!((parse_url, "Extracts a part from a URL.", args));
+    export_functions!((try_parse_url, "This is a special version of parse_url 
that performs the same operation, but returns a NULL value instead of raising 
an error if the parsing cannot be performed.", args));

Review Comment:
   ```suggestion
   export_functions!((parse_url, "Extracts a part from a URL, throwing an error 
if an invalid URL is provided.", args));
       export_functions!((try_parse_url, "Same as parse_url but returns NULL if 
an invalid URL is provided.", args));
   ```
   
   Thoughts on simplifying + clarifying wording like this?



-- 
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

Reply via email to