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-11296][Table API & SQL] Support truncate in TableAPI #7450

Closed
wants to merge 5 commits into from
Closed

[FLINK-11296][Table API & SQL] Support truncate in TableAPI #7450

wants to merge 5 commits into from

Conversation

XuQianJin-Stars
Copy link
Contributor

What is the purpose of the change

This PR add truncate as core scalar operators in then codegen.

Brief change log

(for example:)

  • docs/dev/table/functions.md
  • table/api/scala/expressionDsl.scala
  • table/codegen/calls/BuiltInMethods.scala
  • table/codegen/calls/FunctionGenerator.scala
  • table/expressions/mathExpressions.scala
  • table/validate/FunctionCatalog.scala
  • table/expressions/ScalarFunctionsTest.scala
  • table/expressions/SqlExpressionTest.scala

Verifying this change

(Please pick either of the following options)

This change added tests in ScalarOperatorsTest and SqlExpressionTest

(example:)

  • Added integration tests for end-to-end deployment with large payloads (100MB)
  • Extended integration test for recovery after master (JobManager) failure
  • Added test that validates that TaskInfo is transferred only once across recoveries
  • Manually verified the change by running a 4 node cluser with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.

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

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

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

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

Thank @XuQianJin-Stars for the work. I left some comments below.

  1. Could you add some more validation tests to ScalarFunctionsValidationTest? e.g. the second parameter is not an int, the first parameter is a String.
  2. I think we should also support single parameter (second parameter deafult as 0)
  3. We should also support FLOAT, INT as the first parameter as they belong to the NUMERIC family. (see org.apache.calcite.sql.type.SqlTypeFamily.NUMERIC)

</td>
<td>
<p>Returns a <i>numeric</i> after the truncation.</p>
<p>E.g. truncate(cast(42.345 as decimal(2, 3)), 2) to 42.34.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Can we use truncate(42.345, 2) as a simpler example here?

<tr>
<td>
{% highlight text %}
TRUNCATE(numeric1, numeric2)
Copy link
Member

Choose a reason for hiding this comment

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

Should the second parameter be an INT?

<tr>
<td>
{% highlight text %}
numeric1.shiftLeft(numeric2)
Copy link
Member

Choose a reason for hiding this comment

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

NUMERIC1.truncate(INT) ?

</td>
<td>
<p>Returns a <i>numeric</i> after the truncation.</p>
<p>E.g. truncate(cast(42.345 as decimal(2, 3)), 2) to 42.34.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Modify this to TalbeApi example.

* n can be negative to cause n digits left of the decimal point of the value to become zero.
*
* @param n
* @return
Copy link
Member

Choose a reason for hiding this comment

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

remove the @param and @return

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

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

Hi @XuQianJin-Stars , it looks good to me overall, I only left some minor comments below.

BTW, please do not squash commits and force-push (otherwise rebase master to solve the conflicts), this will lose the review comment location and make the reviewer have to review the PR totally again.

Please comment in the PR when you addressed all the comment.

'f29.truncate('f30),
"f29.truncate(f30)",
"truncate(f29, f30)",
0.4.toString)
Copy link
Member

Choose a reason for hiding this comment

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

why not use "0.4" here ?

@@ -64,6 +65,42 @@ class ScalarFunctionsValidationTest extends ScalarTypesTestBase {
testSqlApi("BIN(f16)", "101010") // Date type
}

@Test(expected = classOf[ValidationException])
def testInvalidTruncate1(): Unit = {
// The all arguments is of type String
Copy link
Member

Choose a reason for hiding this comment

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

All arguments are string type

{% endhighlight %}
</td>
<td>
<p>Returns a <i>numeric</i> after the truncation.</p>
Copy link
Member

Choose a reason for hiding this comment

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

  1. TRUNCATE(numeric, integer) and TRUNCATE(numeric) should be placed in a row together because they are the same function.
  2. Please explain more about description of the function. For example:
Returns <i>numeric</i> truncated to <i>integer</i> decimal places. If <i>integer</i> is omitted, then <i>numeric</i> is truncated to 0 places. <i>integer</i> can be negative to truncate (make zero) <i>integer</i> digits left of the decimal point.
<p>E.g.  ......   </p>

@XuQianJin-Stars
Copy link
Contributor Author

hi @wuchong I have modified this PR. Do you have time to review it.
best,
qianjin

<tr>
<td>
{% highlight text %}
TRUNCATE(numeric1, integer2)
{% endhighlight %}
</td>
<td>
<p>Returns a <i>numeric</i> after the truncation.</p>
<p>E.g. truncate(42.345, 2) to 42.34.</p>
<p>Returns a <i>numeric</i> of truncated to <i>integer2</i> decimal places. Returns NULL if <i>numeric1</i> or <i>integer2</i> is NULL.If <i>integer2</i> is 0,the result has no decimal point or fractional part.<i>integer2</i> can be negative to cause <i>integer2</i> digits left of the decimal point of the value to become zero.This function can also pass in only one <i>numeric1</i> parameter and not set <i>Integer2</i> to use.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Please describe what's the behavior when pass only one argument.

@XuQianJin-Stars
Copy link
Contributor Author

hi @wuchong Ok, let me revise the description 。
best
qianjin

@XuQianJin-Stars
Copy link
Contributor Author

hi @wuchong I have modified this PR. Do you have time to review it.
best,
qianjin

@wuchong
Copy link
Member

wuchong commented Jan 30, 2019

Thank @XuQianJin-Stars and sorry for the late reply. The PR looks good to me now.

Will merge this soon.

@XuQianJin-Stars
Copy link
Contributor Author

hi @wuchong Thank you very much. I know you are very busy.
best
qianjin

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