-
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 3 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 |
---|---|---|
|
@@ -1123,7 +1123,7 @@ case class SubstringIndex(strExpr: Expression, delimExpr: Expression, countExpr: | |
4 | ||
> SELECT _FUNC_('bar', 'foobarbar', 5); | ||
7 | ||
> SELECT POSITION('bar' IN 'foobarbar'); | ||
> SELECT _FUNC_('bar' IN 'foobarbar'); | ||
wangyum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
4 | ||
""", | ||
since = "1.5.0") | ||
|
@@ -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 '); | ||
> SELECT _FUNC_('Spark SQL '); | ||
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. Would it be better show examples for binary data instead of demonstrating synonyms of the function name? 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. And it would be nice to show to users all synonyms in a separate list somewhere in the description 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. Yes. +1 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. |
||
10 | ||
> SELECT CHARACTER_LENGTH('Spark SQL '); | ||
> SELECT _FUNC_('Spark SQL '); | ||
10 | ||
""", | ||
since = "1.5.0") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,21 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession { | |
} | ||
} | ||
|
||
test("using _FUNC_ instead of function names in examples") { | ||
val exampleRe = "(>.*;)".r | ||
val ignoreSet = Set("org.apache.spark.sql.catalyst.expressions.CaseWhen") | ||
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?