kasakrisz opened a new pull request, #5518:
URL: https://github.com/apache/hive/pull/5518

   <!--
   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?
   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?
   <!--
   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. 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?
   <!--
   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.output.overwrite -Dtest=TestNegativeLlapLocalCliDriver 
-Dqfile=constraint_invalid_cast.q,constraint_invalid_cast_partition.q -pl 
itests/qtest -Pitests
   ```


-- 
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-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to