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-28589: Not null constraint does not enforced at invalid cast #5518

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kasakrisz
Copy link
Contributor

What changes were proposed in this pull request?

Move Filter operator with enforce constraint call generation after conversion Select operator generation and make the Filter operator the child operator of the conversion Select operator.

Why are the changes needed?

Currently, implicit type conversion occurs after constraints are enforced; however, the result of an invalid cast can be null. In these cases, the null value is inserted despite the fact that a not-null constraint is specified on the target column.

See the execution plan if this simple insert:

set hive.stats.autogather=false;

create table t1(
  date_col date not null
);

explain
insert into t1 values ('2024-99-99');
                        Filter Operator
                          predicate: enforce_constraint(_col0 is not null) (type: boolean)
                          Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column stats: COMPLETE
                          Select Operator
                            expressions: CAST( _col0 AS DATE) (type: date)
                            outputColumnNames: _col0
                            Statistics: Num rows: 1 Data size: 56 Basic stats: COMPLETE Column stats: COMPLETE

Does this PR introduce any user-facing change?

Yes. Such inserts will fail with an error message like:

org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError: Either CHECK or NOT NULL constraint violated!

Is the change a dependency upgrade?

No

How was this patch tested?

mvn test -Dtest.output.overwrite -Dtest=TestNegativeLlapLocalCliDriver -Dqfile=constraint_invalid_cast.q,constraint_invalid_cast_partition.q -pl itests/qtest -Pitests

@kasakrisz kasakrisz marked this pull request as draft October 25, 2024 11:52
@kasakrisz kasakrisz changed the title HIVE-28589: Not null not constraint does not enforced at invalid cast HIVE-28589: Not null constraint does not enforced at invalid cast Nov 4, 2024
Copy link

sonarcloud bot commented Nov 19, 2024

@kasakrisz kasakrisz marked this pull request as ready for review November 19, 2024 12:52
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.

2 participants