-
Notifications
You must be signed in to change notification settings - Fork 28k
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
[SPARK-29237][SQL] Prevent real function names in expression example template #25924
Changes from 5 commits
9e835a3
9ffa734
565368d
c9e8a0c
f7caecd
b722806
aaa003e
62eaea9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1732,9 +1732,9 @@ case class Left(str: Expression, len: Expression, child: Expression) extends Run | |
Examples: | ||
> SELECT _FUNC_('Spark SQL '); | ||
10 | ||
> SELECT CHAR_LENGTH('Spark SQL '); | ||
10 | ||
> SELECT CHARACTER_LENGTH('Spark SQL '); | ||
> SELECT _FUNC_('Spark SQL'); | ||
9 | ||
> SELECT _FUNC_(binary('Spark SQL\\000')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last two examples seems to show to users we also support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I will revert this but #25924 (comment) instead of hard coded names in examples. |
||
10 | ||
""", | ||
since = "1.5.0") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,26 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession { | |
} | ||
} | ||
|
||
test("using _FUNC_ instead of function names in examples") { | ||
val exampleRe = "(>.*;)".r | ||
val ignoreSet = Set( | ||
// Examples for CaseWhen show simpler syntax: | ||
// `CASE WHEN ... THEN ... WHEN ... THEN ... END` | ||
"org.apache.spark.sql.catalyst.expressions.CaseWhen", | ||
// _FUNC_ is replaced by `locate` but `locate(... IN ...)` is not supported | ||
"org.apache.spark.sql.catalyst.expressions.StringLocate") | ||
spark.sessionState.functionRegistry.listFunction().foreach { funcId => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, @MaxGekk . This is super useful. |
||
val info = spark.sessionState.catalog.lookupFunctionInfo(funcId) | ||
val className = info.getClassName | ||
withClue(s"Expression class '$className'") { | ||
val exprExamples = info.getOriginalExamples | ||
if (!exprExamples.isEmpty && !ignoreSet.contains(className)) { | ||
assert(exampleRe.findAllIn(exprExamples).toSet.forall(_.contains("_FUNC_"))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
test("SPARK-6743: no columns from cache") { | ||
Seq( | ||
(83, 0, 38), | ||
|
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.
I don't know that this is worth adding just for testing?
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.
+1 for @srowen 's opinion.
@MaxGekk . Instead of adding this API, shall we use the following format in the test case?
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.
Or can we use
@VisibleForTesting
at least?