-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Handle overflow in IntegerNumberToVarcharCoercer #14179
Handle overflow in IntegerNumberToVarcharCoercer #14179
Conversation
Before the change, `IntegerNumberToVarcharCoercer` could produce a `Slice` value that's not valid value for destination `VarcharType`.
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.
See #5015
I think we decided that the behaviour should match Hive (since this is coercion within connector not the engine) which ignores the bounds?
(However I also think that the Hive behaviour makes no sense and I prefer this implementation)
It cannot ignore bounds. The code before change is obviously wrong: it can produce a value of length n+1 for a varchar(n) data type, which is obviously illegal. Thus, @hashhar I am not removing any compatibility with Hive. I am replacing silent correctness problem with explicit check.
I actually didn't check what's the Hive behavior. And also prefer this version to alternatives (truncate, replace with NULL, etc). |
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.
I misunderstood your goal here.
LGTM.
Hive behaviour is documented in #5015
|
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.
testable?
yes, but not worth it IMO if we want to implement actual hive logic from #5015 (comment), this should go with a test. |
long value = fromType.getLong(block, position); | ||
Slice converted = utf8Slice(String.valueOf(value)); | ||
if (!toType.isUnbounded() && countCodePoints(converted) > toType.getBoundedLength()) { | ||
throw new TrinoException(INVALID_ARGUMENTS, format("Varchar representation of %s exceed %s bounds", value, toType)); |
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.
exceed
--> exceeds
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.
Do we want a release note for this? |
Nope |
Before the change,
IntegerNumberToVarcharCoercer
could produce aSlice
value that's not valid value for destinationVarcharType
.Fixes #5015