wayneguow commented on code in PR #47481: URL: https://github.com/apache/spark/pull/47481#discussion_r1693214038
########## sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala: ########## @@ -424,6 +424,29 @@ class StringFunctionsSuite extends QueryTest with SharedSparkSession { df.selectExpr("substring_index(a, '.', 2)"), Row("www.apache") ) + + val testTable = "test_substring_index" + // count is int + withTempPath { path => + withTable(testTable) { + sql(s"CREATE TABLE $testTable (num int) USING parquet LOCATION '${path.toURI.toString}'") + sql(s"INSERT INTO $testTable VALUES (1), (2), (3), (NULL)") + val query = s"SELECT num, SUBSTRING_INDEX('a_a_a', '_', num) as sub_str FROM $testTable" + checkAnswer(sql(query), Seq(Row(1, "a"), Row(2, "a_a"), Row(3, "a_a_a"), Row(null, null))) + } + } + // count is string + withTempPath { path => + withTable(testTable) { + sql(s"CREATE TABLE $testTable (num string) USING parquet " + + s"LOCATION '${path.toURI.toString}'") + sql(s"INSERT INTO $testTable VALUES ('1'), ('2'), ('3'), (NULL)") + val query = s"SELECT num, SUBSTRING_INDEX('a_a_a', '_', num) as sub_str FROM $testTable" + checkAnswer( + sql(query), + Seq(Row("1", "a"), Row("2", "a_a"), Row("3", "a_a_a"), Row(null, null))) + } + } Review Comment: I didn't add a case of string which is illegal integer(for example: "hah"), because when ansi mode is on or off, we will get different results, when off, we will get null value, when on, we will get `CAST_INVALID_INPUT` exception. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org