Github user janplus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14008#discussion_r69385849
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/StringExpressionsSuite.scala
 ---
    @@ -725,4 +725,51 @@ class StringExpressionsSuite extends SparkFunSuite 
with ExpressionEvalHelper {
         checkEvaluation(FindInSet(Literal("abf"), Literal("abc,b,ab,c,def")), 
0)
         checkEvaluation(FindInSet(Literal("ab,"), Literal("abc,b,ab,c,def")), 
0)
       }
    +
    +  test("ParseUrl") {
    +    def checkParseUrl(expected: String, urlStr: String, partToExtract: 
String): Unit = {
    +      checkEvaluation(
    +        ParseUrl(Seq(Literal.create(urlStr, StringType),
    +          Literal.create(partToExtract, StringType))), expected)
    +    }
    +    def checkParseUrlWithKey(
    +        expected: String, urlStr: String,
    +        partToExtract: String, key: String): Unit = {
    +      checkEvaluation(
    +        ParseUrl(Seq(Literal.create(urlStr, StringType), 
Literal.create(partToExtract, StringType),
    +          Literal.create(key, StringType))), expected)
    +    }
    +
    +    checkParseUrl("spark.apache.org", 
"http://spark.apache.org/path?query=1";, "HOST")
    +    checkParseUrl("/path", "http://spark.apache.org/path?query=1";, "PATH")
    +    checkParseUrl("query=1", "http://spark.apache.org/path?query=1";, 
"QUERY")
    +    checkParseUrl("Ref", "http://spark.apache.org/path?query=1#Ref";, "REF")
    +    checkParseUrl("http", "http://spark.apache.org/path?query=1";, 
"PROTOCOL")
    +    checkParseUrl("/path?query=1", "http://spark.apache.org/path?query=1";, 
"FILE")
    +    checkParseUrl("spark.apache.org:8080", 
"http://spark.apache.org:8080/path?query=1";, "AUTHORITY")
    +    checkParseUrl("userinfo", 
"http://useri...@spark.apache.org/path?query=1";, "USERINFO")
    +    checkParseUrlWithKey("1", "http://spark.apache.org/path?query=1";, 
"QUERY", "query")
    +
    +    // Null checking
    +    checkParseUrl(null, null, "HOST")
    +    checkParseUrl(null, "http://spark.apache.org/path?query=1";, null)
    +    checkParseUrl(null, null, null)
    +    checkParseUrl(null, "test", "HOST")
    +    checkParseUrl(null, "http://spark.apache.org/path?query=1";, "NO")
    +    checkParseUrlWithKey(null, "http://spark.apache.org/path?query=1";, 
"HOST", "query")
    +    checkParseUrlWithKey(null, "http://spark.apache.org/path?query=1";, 
"QUERY", "quer")
    +    checkParseUrlWithKey(null, "http://spark.apache.org/path?query=1";, 
"QUERY", null)
    +    checkParseUrlWithKey(null, "http://spark.apache.org/path?query=1";, 
"QUERY", "")
    +
    +    // exceptional cases
    +    intercept[java.util.regex.PatternSyntaxException] {
    --- End diff --
    
    Yes, definitely I can do that. In fact I have finished it.
    But before I do the commit, let us get thought it first.
    In `checkAnalysis` method for `LogicalPlan`, the only method will be called 
for `Expression` is `checkInputDataTypes`
    
https://github.com/apache/spark/blob/d1e8108854deba3de8e2d87eb4389d11fb17ee57/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala#L64
    
    Which means we can only implement this validation in `checkInputDataTypes` 
of `ParseUrl`. In that circumstance spark will give the AnalysisException like 
this
    > org.apache.spark.sql.AnalysisException: cannot resolve 
'parse_url("http://spark.apache.org/path?";, "QUERY", "???")' due to data type 
mismatch: wrong key "???"; line 1 pos 0
    
    But obviously this should not be a data type mismatch. This message may 
confuse the users. Also the different message for **Literal** `key` and **Not 
Literal** `key` may make them confused too.
    Otherwise, if we do not validate the **Literal** `key`, the `Executor` will 
get an exception at the first row. It seems not that unacceptable.
    So compared the both sides, I think we should not do the Literal `key` 
validation.
    How do you think about this?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to