You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "soumyakanti3578 (via GitHub)" <gi...@apache.org> on 2023/12/11 19:59:53 UTC
[PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
soumyakanti3578 opened a new pull request, #4936:
URL: https://github.com/apache/hive/pull/4936
…o for num_months
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Second argument of GenericUDFAddMonths `num_months` should accept DECIMAL values with scale zero
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
DECIMALS like `1.0, 2.0`, etc can be easily converted to `INT`s, so they should be valid arguments for the UDF
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Yes, this change enables support of DECIMALS with scale=0 for num_months
### Is the change a dependency upgrade?
<!--
If yes, please attach a file with output from mvn dependency:tree to validate a complete upgrade of dependency.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
`mvn test -Dtest=TestMiniLlapLocalCliDriver -Dtest.output.overwrite=true -Dqfile=udf_add_months.q`
`mvn test -Dtest=TestNegativeLlapCliDriver -Dtest.output.overwrite=true -Dqfile=udf_add_months_error_2.q`
`mvn test -Dtest=TestNegativeLlapCliDriver -Dtest.output.overwrite=true -Dqfile=udf_add_months_error_1.q`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "aturoczy (via GitHub)" <gi...@apache.org>.
aturoczy commented on code in PR #4936:
URL: https://github.com/apache/hive/pull/4936#discussion_r1425575655
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java:
##########
@@ -351,8 +352,12 @@ protected void obtainIntConverter(ObjectInspector[] arguments, int i,
case INT:
case VOID:
break;
+ case DECIMAL:
+ if (inOi.scale() == 0) {
+ break;
+ }
Review Comment:
Agreed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4936:
URL: https://github.com/apache/hive/pull/4936#issuecomment-1853094025
## [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=4936) **Quality Gate passed**
The SonarCloud Quality Gate passed, but some issues were introduced.
[1 New issue](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&inNewCodePeriod=true)
[0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4936&resolved=false&inNewCodePeriod=true)
No data about Coverage
No data about Duplication
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=4936)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "InvisibleProgrammer (via GitHub)" <gi...@apache.org>.
InvisibleProgrammer commented on PR #4936:
URL: https://github.com/apache/hive/pull/4936#issuecomment-1854336692
Firstly, I agree with @aturoczy , it is better to educate the users about a month is an integer type so please use integer types when you work with month.
I have two concerns about this change:
- Now it introduces a decimal -> integer conversation. (Side note, for the first sight, it looks like it would work with decimal -> short conversation as well). Can that extra conversation cause a performance overhead?
- It modifies `GenericUDF.obtainIntConverter`. It is used in 4 other classes as well. Does it means that change adds decimal support for those as well?
<img width="955" alt="image" src="https://github.com/apache/hive/assets/1486749/71744d86-ca52-488b-9819-973db91ea95c">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "soumyakanti3578 (via GitHub)" <gi...@apache.org>.
soumyakanti3578 commented on code in PR #4936:
URL: https://github.com/apache/hive/pull/4936#discussion_r1425676200
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java:
##########
@@ -351,8 +352,12 @@ protected void obtainIntConverter(ObjectInspector[] arguments, int i,
case INT:
case VOID:
break;
+ case DECIMAL:
+ if (inOi.scale() == 0) {
+ break;
+ }
Review Comment:
Yes, I agree that we should limit precision. Since we are using `add(int field, int amount)` method of `java.util.Calendar`, where the `amount` type is an `int`, I think we should limit the value to max value of an int.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "okumin (via GitHub)" <gi...@apache.org>.
okumin commented on code in PR #4936:
URL: https://github.com/apache/hive/pull/4936#discussion_r1425406965
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java:
##########
@@ -351,8 +352,12 @@ protected void obtainIntConverter(ObjectInspector[] arguments, int i,
case INT:
case VOID:
break;
+ case DECIMAL:
+ if (inOi.scale() == 0) {
+ break;
+ }
Review Comment:
I think `precision` should also be small enough to ensure type safety. If we accept any DECIMAL, we should semantically accept LONG just in my opinion.
##########
ql/src/test/queries/clientpositive/udf_add_months.q:
##########
@@ -40,3 +40,15 @@ add_months(cast('2016-01-29 10:30:00' as timestamp), 1),
add_months(cast('2016-02-29 10:30:00' as timestamp), -1),
add_months(cast('2016-02-29 10:30:12' as timestamp), 2, 'YYYY-MM-dd HH:mm:ss'),
add_months(cast(null as timestamp), 1);
+
+select
+add_months('2014-01-14 10:30:00', 1.0),
Review Comment:
I'm just curious when we want to give a floating point to `ADD_MONTHS`.
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java:
##########
@@ -607,6 +612,8 @@ protected Integer getConstantIntValue(ObjectInspector[] arguments, int i)
v = ((ShortWritable) constValue).get();
} else if (constValue instanceof ByteWritable) {
v = ((ByteWritable) constValue).get();
+ } else if (constValue instanceof HiveDecimalWritable) {
+ v = ((HiveDecimalWritable) constValue).intValue();
} else {
throw new UDFArgumentTypeException(i, getFuncName() + " only takes INT/SHORT/BYTE types as "
Review Comment:
It would be more consistent if we updated this message
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4936:
URL: https://github.com/apache/hive/pull/4936#issuecomment-1937928868
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Feel free to reach out on the dev@hive.apache.org list if the patch is in need of reviews.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #4936: HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer…
URL: https://github.com/apache/hive/pull/4936
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "soumyakanti3578 (via GitHub)" <gi...@apache.org>.
soumyakanti3578 commented on PR #4936:
URL: https://github.com/apache/hive/pull/4936#issuecomment-1854437233
Thanks for commenting on the PR. I have seen a case in production where the customer uses a DECIMAL(5, 0) column of a table as the second argument of `add_months`. Since a decimal with scale zero can always be represented as a whole number, I think the customer's case can be supported. But I agree that this is a bad pattern on their end.
I also think we should limit the precision of the DECIMAL because we use `add(int field, int amount)` method of `java.util.Calendar`, where the `amount` type is an `int`.
Regarding the change being in the base class, maybe I can create a new child class and override the method `obtainIntConverter` only for `add_months`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
Re: [PR] HIVE-27949: GenericUDFAddMonths doesn't accept DECIMAL with scale zer… [hive]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4936:
URL: https://github.com/apache/hive/pull/4936#issuecomment-1850880952
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=4936)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4936&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4936&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=4936&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=4936&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=4936&metric=coverage&view=list) No Coverage information
[](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=4936&metric=duplicated_lines_density&view=list) No Duplication information
 The version of Java (11.0.8) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more [here](https://docs.sonarsource.com/sonarcloud/appendices/scanner-environment/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org