sunchao commented on code in PR #7329:
URL: https://github.com/apache/datafusion-comet/pull/7329#discussion_r4425132509
##########
native/spark-expr/src/url_funcs/parse_url.rs:
##########
@@ -388,11 +449,100 @@ mod tests {
// Unit tests for parse_url_component
// -----------------------------------------------------------------------
+ #[test]
+ fn http_decomposition_matches_generic_parser() {
+ for scheme in ["http", "https"] {
+ for authority in [
+ "example.com",
+ "u:p@host:80",
+ "",
+ "[::1]:80",
+ "[::1",
+ "host:",
+ "例子.com",
+ ] {
+ for tail in [
+ "",
+ "/",
+ "//a/b",
+ "?",
+ "#",
+ "?#",
+ "?x=1#f?y",
+ "#f?x=1",
+ "/é?k=值#片",
+ "/p?a=?b#f#x",
+ ] {
+ let url = format!("{scheme}://{authority}{tail}");
+ assert_eq!(decompose_http(&url), decompose_generic(&url),
"{url}");
+ }
+ }
+ }
+ for url in ["HTTP://host/p", "https:/p", "ftp://host/p", "mailto:a@b"]
{
+ assert!(decompose_http(url).is_none(), "{url}");
+ }
+ }
+
+ #[test]
+ fn file_and_query_components() -> Result<()> {
+ for (url, part, key, expected) in [
+ ("http://h?x=1#f?y", "FILE", None, "?x=1"),
+ ("http://h?#", "FILE", None, "?"),
+ ("HTTP://h/p?#f", "FILE", None, "/p?"),
+ ("ftp://h/p?x=1#f", "FILE", None, "/p?x=1"),
+ ("https://h/é?k=值#片", "PATH", None, "/é"),
+ // The key may introduce capture groups; both Spark and the
existing
+ // matcher return group 2 of the full pattern, not its last group.
+ ("https://h/?abc=1&v=2", "QUERY", Some("(abc)"), "abc"),
+ ("https://h/?abc=1&v=2", "QUERY", Some("v"), "2"),
+ ("https://h/?abc=1&v=2", "QUERY", Some("(abc)"), "abc"),
+ ] {
+ let result = parse_url_component(url, part, key)?.unwrap();
+ assert_eq!(result, expected);
+ }
+ // Extraction must still reject an invalid component after the
requested host.
+ assert!(parse_url_component("https://host/p#invalid fragment", "HOST",
None).is_err());
+ Ok(())
+ }
+
+ #[test]
+ fn sliced_string_layouts_produce_owned_output() -> Result<()> {
Review Comment:
Removed the three-layout slicing loop, the input-drop check and the
production comment in fd76067fea. I kept one `Utf8View` assertion for buffer
retention. An owning view can remain valid while keeping the entire input
allocation alive. The test checks that extracting the 16-byte host from a 128
KiB URL produces an output smaller than the input buffer.
--
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]