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

[FLINK-9332][TableAPI & SQL] Fix Codegen error of CallGenerator #5988

Closed
wants to merge 1 commit into from

Conversation

Xpray
Copy link
Contributor

@Xpray Xpray commented May 11, 2018

What is the purpose of the change

Fix bugs that nullTerm do not handle function call return value correctly.

Brief change log

  • check function call return value and reset nullTerm if necessary.

Verifying this change

This change added tests and can be verified as follows:
org.apache.flink.table.runtime.stream.sql.SqlITCase#testNullableFunctionCall

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? no

Copy link
Contributor

@fhueske fhueske left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @Xpray!
I had a look and left a few comments.
Thanks, Fabian

val nullTermCode = if (
nullCheck &&
isReference(returnType) &&
!TypeCheckUtils.isTemporal(returnType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you exclude temporal types here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In flink we use primitive types such as 'long' in code generation while it's returnType is a time type with isReference is true, so I exclude it to avoid these cases like
long a; if (a == null) {}

val resultCode = if (nullCheck && operands.nonEmpty) {
s"""
|${operands.map(_.code).mkString("\n")}
|boolean $nullTerm = ${operands.map(_.nullTerm).mkString(" || ")};
|$resultTypeTerm $resultTerm;
|if ($nullTerm) {
| $resultTerm = $defaultValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we need this case if the result value is a primitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've set the value to defaultValue at line 85

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry. Overlooked that one. Thanks!

@@ -686,6 +686,28 @@ class SqlITCase extends StreamingWithStateTestBase {

assertEquals(List(expected.toString()), StreamITCase.testResults.sorted)
}

@Test
def testNullableFunctionCall(): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should test this more lightweight with a unit test instead of running a complete query.
We can extend ScalarFunctionsTest.testLPad() with

testSqlApi(
   "LPAD('hello', -1, 'x') IS NULL", "true"
)

to cover this case

@fhueske
Copy link
Contributor

fhueske commented May 11, 2018

Merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants