Skip to content

Commit

Permalink
[SPARK-49638][SQL] Remove the ANSI config suggestion in INVALID_URL
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
This PR updates the suggested fix of `INVALID_URL` error to use `try_parse_url` function added in [this](#48500) PR instead of turning off ANSI mode.

### Why are the changes needed?
INVALID_URL contains suggested fix for turning off ANSI mode. Now that in Spark 4.0.0 we have moved to ANSI mode on by default, we want to keep suggestions of this kind to the minimum. There exist implementations of try_* functions which provide safe way to get behavior as for ANSI mode off and suggestions of this kind should be sufficient.

In this case, try expressions were missing so new expressions were added to patch up the missing implementations.

### Does this PR introduce _any_ user-facing change?
Yes.

### How was this patch tested?
There are tests that check error messages.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes #48616 from jovanm-db/improvedError.

Authored-by: Jovan Markovic <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
jovanm-db authored and MaxGekk committed Oct 23, 2024
1 parent be18b7c commit 5e9dec7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3236,7 +3236,7 @@
},
"INVALID_URL" : {
"message" : [
"The url is invalid: <url>. If necessary set <ansiConfig> to \"false\" to bypass this error."
"The url is invalid: <url>. Use `try_parse_url` to tolerate invalid URL and return NULL instead."
],
"sqlState" : "22P02"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
def invalidUrlError(url: UTF8String, e: URISyntaxException): SparkIllegalArgumentException = {
new SparkIllegalArgumentException(
errorClass = "INVALID_URL",
messageParameters = Map(
"url" -> url.toString,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)),
messageParameters = Map("url" -> url.toString),
cause = e)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.spark.sql

import org.apache.spark.SparkIllegalArgumentException
import org.apache.spark.sql.catalyst.util.TypeUtils.toSQLConf
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession

Expand Down Expand Up @@ -77,10 +76,7 @@ class UrlFunctionsSuite extends QueryTest with SharedSparkSession {
sql(s"SELECT parse_url('$url', 'HOST')").collect()
},
condition = "INVALID_URL",
parameters = Map(
"url" -> url,
"ansiConfig" -> toSQLConf(SQLConf.ANSI_ENABLED.key)
))
parameters = Map("url" -> url))
}
}

Expand Down

0 comments on commit 5e9dec7

Please sign in to comment.