-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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-28703: Integral Data Type Overflow Not Enforced for JsonSerDe and UDFs #5608
base: master
Are you sure you want to change the base?
Conversation
2d971c5
to
3d680a4
Compare
Quality Gate passedIssues Measures |
@@ -128,6 +128,11 @@ public ByteWritable evaluate(IntWritable i) { | |||
if (i == null) { | |||
return null; | |||
} else { | |||
int value = i.get(); | |||
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { | |||
throw new IllegalArgumentException("Value out of range for Byte: " + value); |
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.
It is better to use Hive-specific exceptions. Hive has an exception UDFArgumentException
which seems suitable here.
@@ -146,6 +146,10 @@ public IntWritable evaluate(LongWritable i) { | |||
if (i == null) { | |||
return null; | |||
} else { | |||
long value = i.get(); | |||
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { | |||
throw new IllegalArgumentException("Value out of range for Integer: " + value); |
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.
Same here, generic exception.
@@ -128,6 +128,10 @@ public ShortWritable evaluate(IntWritable i) { | |||
if (i == null) { | |||
return null; | |||
} else { | |||
int value = i.get(); | |||
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { | |||
throw new IllegalArgumentException("Value out of range for Short: " + value); |
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.
same, can you please use Hive specific exceptions
What changes were proposed in this pull request?
The pull request addresses the issue of data type overflow not being enforced when using JsonSerDe in Apache Hive. The proposed changes aim to ensure strict data type validation during the insertion and loading of data into tables defined with types like TINYINT, SMALLINT, INT, and BIGINT.
Why are the changes needed?
This behavior can lead to data integrity issues and unexpected results.
Does this PR introduce any user-facing change?
Yes
Is the change a dependency upgrade?
No
How was this patch tested?
Tests introduced in this PR and local machine