-
Notifications
You must be signed in to change notification settings - Fork 293
feat: add support parse_url
#3563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rafafrdz
wants to merge
9
commits into
apache:main
Choose a base branch
from
rafafrdz:feat/add-support-parse_url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+318
−4
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db21fce
add support parse_url
rafafrdz 9121c6f
edit
rafafrdz 3167045
fix parse_url Spark 4 Invoke rewrite and legacy null semantics
rafafrdz 891b851
edit
rafafrdz 59d38cd
chore: apply spotless formatting
rafafrdz 60be29e
test: fix parse_url test suite
rafafrdz ab5b727
refactor: introduce CometInvokeExpressionSerde trait for generic Invo…
rafafrdz 433aa3d
refactor: simplify CometInvokeExpressionSerde by removing type parameter
rafafrdz 54fc48a
suggestions
rafafrdz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -470,7 +470,7 @@ | |
|
|
||
| ### url_funcs | ||
|
|
||
| - [ ] parse_url | ||
| - [x] parse_url | ||
| - [ ] url_decode | ||
| - [ ] url_encode | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
spark/src/main/scala/org/apache/comet/serde/CometInvokeExpressionSerde.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.comet.serde | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression} | ||
|
|
||
| /** | ||
| * Serializer contract for Spark `Invoke` expressions that wrap a private evaluator object. | ||
| * | ||
| * In Spark 4.0 several built-in functions (e.g. `parse_url`) became `RuntimeReplaceable` and are | ||
| * rewritten by the analyser into an `Invoke(evaluator, arg, ...)` node whose first child is a | ||
| * `Literal` of `ObjectType` holding a private evaluator instance. The Spark expression class that | ||
| * Comet normally dispatches on (e.g. `ParseUrl`) is therefore never seen at serde time on Spark | ||
| * 4.0. | ||
| * | ||
| * Implementors expose: | ||
| * - [[invokeTargetClassName]] - the fully-qualified name of the evaluator class embedded in the | ||
| * first `Literal(_, ObjectType)` child of the `Invoke` node. This is the key used by | ||
| * [[QueryPlanSerde]] to route the node to the correct handler. | ||
| * - [[convertFromInvoke]] - the actual serialization logic, receiving the raw `Invoke` | ||
| * expression (with all children including the evaluator literal). | ||
| * | ||
| * To register a new handler, add the object to [[QueryPlanSerde.invokeSerdeByTargetClassName]]. | ||
| */ | ||
| trait CometInvokeExpressionSerde { | ||
|
|
||
| /** | ||
| * Fully-qualified class name of the private evaluator object held in the first child | ||
| * `Literal(_, ObjectType(...))` of the `Invoke` node. | ||
| * | ||
| * Example: `"org.apache.spark.sql.catalyst.expressions.url.ParseUrlEvaluator"` | ||
| */ | ||
| def invokeTargetClassName: String | ||
|
|
||
| /** | ||
| * Serialize the `Invoke` expression into a Comet proto `Expr`. | ||
| * | ||
| * @param expr | ||
| * The raw `Invoke` expression node (first child is the evaluator literal). | ||
| * @param inputs | ||
| * Resolved input attributes for the enclosing operator. | ||
| * @param binding | ||
| * Whether attributes are bound (relevant for aggregate expressions). | ||
| * @return | ||
| * `Some(Expr)` on success, `None` if the expression cannot be handled (the implementor is | ||
| * responsible for calling `withInfo` to record the reason). | ||
| */ | ||
| def convertFromInvoke( | ||
| expr: Expression, | ||
| inputs: Seq[Attribute], | ||
| binding: Boolean): Option[ExprOuterClass.Expr] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
spark/src/test/resources/sql-tests/expressions/string/parse_url.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| -- 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. | ||
|
|
||
| -- ConfigMatrix: parquet.enable.dictionary=false,true | ||
| -- MinSparkVersion: 3.4 | ||
|
|
||
| statement | ||
| CREATE TABLE test_parse_url(url string) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_parse_url VALUES | ||
| ('http://spark.apache.org/path?query=1'), | ||
| ('https://spark.apache.org/path/to/page?query=1&k2=v2'), | ||
| ('ftp://user:pwd@ftp.example.com:2121/files?x=1#frag'), | ||
| (NULL) | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'HOST') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'QUERY') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'PROTOCOL') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'QUERY', 'query'), parse_url(url, 'QUERY', 'k2') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'PATH') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'FILE') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'REF') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'AUTHORITY') FROM test_parse_url | ||
|
|
||
| query | ||
| SELECT parse_url(url, 'USERINFO') FROM test_parse_url | ||
|
|
||
| -- Literal arguments: exercises the constant-folding code path which may differ from column inputs | ||
| query | ||
| SELECT parse_url('http://spark.apache.org/path?query=1', 'HOST') | ||
|
|
||
| query | ||
| SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY') | ||
|
|
||
| query | ||
| SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query') | ||
|
|
||
| query | ||
| SELECT parse_url('http://spark.apache.org/path?query=1', 'PROTOCOL') | ||
|
|
||
| query | ||
| SELECT parse_url('http://spark.apache.org/path?query=1', 'PATH') | ||
|
|
||
| query | ||
| SELECT parse_url('http://spark.apache.org/path?query=1', 'FILE') | ||
|
|
||
| query | ||
| SELECT parse_url('ftp://user:pwd@ftp.example.com:2121/files?x=1#frag', 'REF') | ||
|
|
||
| query | ||
| SELECT parse_url('ftp://user:pwd@ftp.example.com:2121/files?x=1#frag', 'AUTHORITY') | ||
|
|
||
| query | ||
| SELECT parse_url('ftp://user:pwd@ftp.example.com:2121/files?x=1#frag', 'USERINFO') | ||
|
|
||
| -- Note: try_parse_url is a Comet-internal DataFusion function name used when serializing | ||
| -- parse_url with failOnError=false. It is not a registered Spark SQL function and cannot | ||
| -- be called directly from SQL. The NULL-on-error behaviour is covered by the | ||
| -- "parse_url with invalid URL in legacy mode" Scala test. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a literal arguments query to the SQL file, since literal and column inputs can use different code paths? Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done