Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Sep 25, 2019

What changes were proposed in this pull request?

In the PR, I propose to replace function names in some expression examples by _FUNC_, and add a test to check that _FUNC_ always present in all examples.

Why are the changes needed?

Binding of a function name to an expression is performed in FunctionRegistry which is single source of truth. Expression examples should avoid using function name directly because this can make the examples invalid in the future.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added new test to SQLQuerySuite which analyses expression example, and check presence of _FUNC_.

@@ -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 ');
Copy link
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. +1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SparkQA
Copy link

SparkQA commented Sep 25, 2019

Test build #111331 has finished for PR 25924 at commit 565368d.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

> SELECT CHARACTER_LENGTH('Spark SQL ');
> SELECT _FUNC_('Spark SQL');
9
> SELECT _FUNC_(binary('Spark SQL\\000'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last two examples seems to show to users we also support CHAR_LENGTH and CHARACTER_LENGTH :
https://issues.apache.org/jira/browse/SPARK-20749

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@SparkQA
Copy link

SparkQA commented Sep 25, 2019

Test build #111334 has finished for PR 25924 at commit f7caecd.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -56,6 +56,8 @@ public String getArguments() {
return arguments;
}

public String getOriginalExamples() { return examples; }
Copy link
Member

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?

Copy link
Member

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?

val examplesField = classOf[ExpressionInfo].getDeclaredField("examples")
examplesField.setAccessible(true)
val examples = examplesField.get(e).asInstanceOf[String]

Copy link
Member

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?

@SparkQA
Copy link

SparkQA commented Sep 25, 2019

Test build #111336 has finished for PR 25924 at commit b722806.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

"org.apache.spark.sql.catalyst.expressions.Remainder",
// Examples demonstrate alternative names, see SPARK-20749
"org.apache.spark.sql.catalyst.expressions.Length")
spark.sessionState.functionRegistry.listFunction().foreach { funcId =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @MaxGekk . This is super useful.

@SparkQA
Copy link

SparkQA commented Sep 25, 2019

Test build #111342 has finished for PR 25924 at commit aaa003e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@MaxGekk
Copy link
Member Author

MaxGekk commented Sep 25, 2019 via email

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-29237][SQL][DOC] Avoid usage of function names in expression examples [SPARK-29237][SQL] Prevent real function names in expression example template Sep 25, 2019
@SparkQA
Copy link

SparkQA commented Sep 25, 2019

Test build #111352 has finished for PR 25924 at commit 62eaea9.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@MaxGekk
Copy link
Member Author

MaxGekk commented Sep 25, 2019

jenkins, retest this, please

@SparkQA
Copy link

SparkQA commented Sep 25, 2019

Test build #111362 has finished for PR 25924 at commit 62eaea9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Merged to master.
Thank you, @MaxGekk , @wangyum , @srowen !

@MaxGekk MaxGekk deleted the fix-func-examples branch October 5, 2019 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants