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

HIVE-27439: Support Decimal(precision, scale) format #4417

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

leesf
Copy link
Contributor

@leesf leesf commented Jun 14, 2023

What changes were proposed in this pull request?

Now, TypeInfoUtils#parseType only support Decimal(precision,scale) instead of Decimal(precision, scale), for example, support decimal(10,2) instead of decimal(10, 2) with a blank before 2, however, users may create decimal in this format decimal(10, 2) and it will throw exception in


Integer.parseInt(params[1]);

we need fix this issue.

Why are the changes needed?

Fix the Decimal(precision, scale) parsing error.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added UT

@@ -489,7 +489,7 @@ private TypeInfo parseType() {
} else if (params.length == 2) {
// New metadata always have two parameters.
precision = Integer.parseInt(params[0]);
scale = Integer.parseInt(params[1]);
scale = Integer.parseInt(params[1].trim());
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this issue. IMO, we can fix it in upstream invoking code, then we can avoid other potential type problems caused by the blank character. Like this:

diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java b/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java
index b23e3cfc44..4788558d4b 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/typeinfo/TypeInfoUtils.java
@@ -334,7 +334,7 @@ private static boolean isTypeChar(char c) {
             || !isTypeChar(typeInfoString.charAt(end))) {
           Token t = new Token();
           t.position = begin;
-          t.text = typeInfoString.substring(begin, end);
+          t.text = typeInfoString.substring(begin, end).trim();
           t.isType = isTypeChar(typeInfoString.charAt(begin));
           tokens.add(t);
           begin = end;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@zhangbutao zhangbutao left a comment

Choose a reason for hiding this comment

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

LGTM. +1 non-binding.

@leesf
Copy link
Contributor Author

leesf commented Jun 16, 2023

cc @nrg4878

@leesf
Copy link
Contributor Author

leesf commented Jun 20, 2023

cc @ayushtkn would you please take a look

Copy link
Member

@ayushtkn ayushtkn left a comment

Choose a reason for hiding this comment

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

LGTM, if the tests pass

@leesf
Copy link
Contributor Author

leesf commented Jun 21, 2023

LGTM, if the tests pass

@ayushtkn The tests have already passed

@zhangbutao
Copy link
Contributor

@leesf The linked JIRA is HIVE-27439 not HIVE-27321. Please change the PR description.

"decimal(10,2)",
"decimal(10, 2)",
"decimal(10, 2 )",
"decimal( 10, 2 )"
Copy link
Contributor

Choose a reason for hiding this comment

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

HIVE-11476 added a special case that allowing spaces in some types. e.g struct<user id:int,user group: int> but it not added the test case. Could you please add this test case here to make sure we won't get a regression?

BTW, i have tested the case struct<user id:int,user group: int> with this change locally and it worked well. But i think it is necessary to add it explicitly. cc @ayushtkn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, added the case.

@leesf leesf changed the title HIVE-27321: Support Decimal(precision, scale) format HIVE-27439: Support Decimal(precision, scale) format Jun 23, 2023
@leesf
Copy link
Contributor Author

leesf commented Jun 23, 2023

@leesf The linked JIRA is HIVE-27439 not HIVE-27321. Please change the PR description.

done

@sonarcloud
Copy link

sonarcloud bot commented Jun 23, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@ayushtkn ayushtkn merged commit ac60b97 into apache:master Jun 23, 2023
@leesf leesf deleted the HIVE-27439 branch June 24, 2023 08:01
yeahyung pushed a commit to yeahyung/hive that referenced this pull request Jul 20, 2023
tarak271 pushed a commit to tarak271/hive-1 that referenced this pull request Dec 19, 2023
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