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
Conversation
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.
Thank @XuQianJin-Stars for the work. I left some comments below.
- Could you add some more validation tests to
ScalarFunctionsValidationTest
? e.g. the second parameter is not an int, the first parameter is a String. - I think we should also support single parameter (second parameter deafult as 0)
- 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)
docs/dev/table/functions.md
Outdated
</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> |
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.
Can we use truncate(42.345, 2)
as a simpler example here?
docs/dev/table/functions.md
Outdated
<tr> | ||
<td> | ||
{% highlight text %} | ||
TRUNCATE(numeric1, numeric2) |
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.
Should the second parameter be an INT?
docs/dev/table/functions.md
Outdated
<tr> | ||
<td> | ||
{% highlight text %} | ||
numeric1.shiftLeft(numeric2) |
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.
NUMERIC1.truncate(INT) ?
docs/dev/table/functions.md
Outdated
</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> |
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.
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 |
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.
remove the @param
and @return
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.
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) |
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.
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 |
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.
All arguments are string type
docs/dev/table/functions.md
Outdated
{% endhighlight %} | ||
</td> | ||
<td> | ||
<p>Returns a <i>numeric</i> after the truncation.</p> |
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.
- TRUNCATE(numeric, integer) and TRUNCATE(numeric) should be placed in a row together because they are the same function.
- 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>
hi @wuchong I have modified this PR. Do you have time to review it. |
docs/dev/table/functions.md
Outdated
<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> |
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.
Please describe what's the behavior when pass only one argument.
hi @wuchong Ok, let me revise the description 。 |
hi @wuchong I have modified this PR. Do you have time to review it. |
Thank @XuQianJin-Stars and sorry for the late reply. The PR looks good to me now. Will merge this soon. |
hi @wuchong Thank you very much. I know you are very busy. |
What is the purpose of the change
This PR add
truncate
as core scalar operators in then codegen.Brief change log
(for example:)
Verifying this change
(Please pick either of the following options)
This change added tests in
ScalarOperatorsTest
andSqlExpressionTest
(example:)
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (yes / no)Documentation