Jefffrey commented on code in PR #17485: URL: https://github.com/apache/datafusion/pull/17485#discussion_r2338341400
########## 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: Kinda unrelated to this PR, but should this query work even if the part is lowercase, e.g. ``` SELECT try_parse_url('https://example.com/path#frag', 'ref'); ``` ? ########## 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: Does this change interfere with dictionary types now? I think this works on main but doesn't work on this PR: ``` query T SELECT parse_url(arrow_cast('http://spark.apache.org/path?query=1', 'Dictionary(Int32, Utf8)'), 'HOST'::string); ---- spark.apache.org ``` ########## datafusion/spark/src/function/url/parse_url.rs: ########## @@ -152,22 +135,39 @@ impl ScalarUDFImpl for ParseUrl { arg_types.len() ); } + // The return type should match the largest size datatype match arg_types.len() { - 2 | 3 => { + 2 | 3 if arg_types.iter().all(is_string_type) => { if arg_types .iter() .any(|arg| matches!(arg, DataType::LargeUtf8)) { Ok(DataType::LargeUtf8) - } else if arg_types - .iter() - .any(|arg| matches!(arg, DataType::Utf8View)) - { - Ok(DataType::Utf8View) } else { Ok(DataType::Utf8) } } + 2 | 3 => plan_err!( + "`{}` expects STRING arguments, got {:?}", + &self.name(), + arg_types + ), + _ => plan_err!( + "`{}` expects 2 or 3 arguments, got {}", + &self.name(), + arg_types.len() + ), Review Comment: This covers the initial if check before the match, so might as well remove that and keep this instead. -- 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