You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/05/13 13:23:30 UTC

[GitHub] [hive] kasakrisz opened a new pull request #2268: HIVE-25109: CBO fails when updating table has constraints defined

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


   <!--
   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?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### 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'.
   -->
   
   
   ### 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.
   -->
   


-- 
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.

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



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


[GitHub] [hive] kgyrtkirk commented on a change in pull request #2268: HIVE-25109: CBO fails when updating table has constraints defined

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #2268:
URL: https://github.com/apache/hive/pull/2268#discussion_r635129376



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
##########
@@ -5031,7 +5038,7 @@ private RelNode genLogicalPlan(QB qb, boolean outerMostQB,
 
       // Build Rel for Constraint checks
       Pair<RelNode, RowResolver> constraintPair =
-          genConstraintFilterLogicalPlan(qb, srcRel, outerNameToPosMap, outerRR);
+          genConstraintFilterLogicalPlan(qb, selPair, outerNameToPosMap, outerRR);

Review comment:
       will this work okay when `selectRel == null`?
   previous code was passing `srcRel` which is optionally the previous `srcRel`

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
##########
@@ -3475,15 +3475,22 @@ private RelNode genFilterLogicalPlan(QB qb, RelNode srcRel, ImmutableMap<String,
         return null;
       }
 
-      RowResolver inputRR = relToHiveRR.get(srcRel);
+      RowResolver inputRR = relToHiveRR.get(selPair.left);
       RexNode constraintUDF = RexNodeTypeCheck.genConstraintsExpr(
           conf, cluster.getRexBuilder(), getTargetTable(qb, dest), updating(dest), inputRR);
       if (constraintUDF == null) {
         return null;
       }
 
-      RelNode constraintRel = genFilterRelNode(constraintUDF, srcRel, outerNameToPosMap, outerRR);
-      return new Pair<>(constraintRel, inputRR);
+      RelNode constraintRel = genFilterRelNode(constraintUDF, selPair.left, outerNameToPosMap, outerRR);
+
+      List<RexNode> originalInputRefs = toRexNodeList(selPair.left);
+      List<RexNode> selectedRefs = Lists.newArrayList();
+      for (int index = 0; index < selPair.right.getColumnInfos().size(); index++) {
+        selectedRefs.add(originalInputRefs.get(index));
+      }

Review comment:
       I'm not sure about this; this block could be replaced with something like 
   ```
   selectedRefs.addAll(originalInputRefs.sublist(selPair.right.getColumnInfos().size()))
   ```
   which looks odd to me because it would mean that the `selected` ones may only be a prefix of the original ones - is that true in every case?
   shouldn't this code be checking the `ref` of the `RexInputRefs` 




-- 
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.

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



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


[GitHub] [hive] kasakrisz merged pull request #2268: HIVE-25109: CBO fails when updating table has constraints defined

Posted by GitBox <gi...@apache.org>.
kasakrisz merged pull request #2268:
URL: https://github.com/apache/hive/pull/2268


   


-- 
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.

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



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


[GitHub] [hive] kasakrisz commented on a change in pull request #2268: HIVE-25109: CBO fails when updating table has constraints defined

Posted by GitBox <gi...@apache.org>.
kasakrisz commented on a change in pull request #2268:
URL: https://github.com/apache/hive/pull/2268#discussion_r635199267



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
##########
@@ -5031,7 +5038,7 @@ private RelNode genLogicalPlan(QB qb, boolean outerMostQB,
 
       // Build Rel for Constraint checks
       Pair<RelNode, RowResolver> constraintPair =
-          genConstraintFilterLogicalPlan(qb, srcRel, outerNameToPosMap, outerRR);
+          genConstraintFilterLogicalPlan(qb, selPair, outerNameToPosMap, outerRR);

Review comment:
       Went through the code where `selectRel` gets its value and I found that it can not be null:
   If is coming from `internalGenSelectLogicalPlan` which can create it with the following way
   ```
   outputRel = genUDTFPlan(genericUDTF, genericUDTFName, udtfTableAlias, udtfColAliases, qb,
   ...
           RelNode udtf = HiveTableFunctionScan.create(cluster, traitSet, list, rexNode, null, retType,
             null);
   outputRel = genSelectRelNode(columnList, outputRR, srcRel);
   ...
         HiveRelNode selRel = HiveProject.create(
   
   outputRel = new HiveAggregate(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION),
   ```




-- 
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.

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



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


[GitHub] [hive] kasakrisz commented on a change in pull request #2268: HIVE-25109: CBO fails when updating table has constraints defined

Posted by GitBox <gi...@apache.org>.
kasakrisz commented on a change in pull request #2268:
URL: https://github.com/apache/hive/pull/2268#discussion_r635190684



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java
##########
@@ -3475,15 +3475,22 @@ private RelNode genFilterLogicalPlan(QB qb, RelNode srcRel, ImmutableMap<String,
         return null;
       }
 
-      RowResolver inputRR = relToHiveRR.get(srcRel);
+      RowResolver inputRR = relToHiveRR.get(selPair.left);
       RexNode constraintUDF = RexNodeTypeCheck.genConstraintsExpr(
           conf, cluster.getRexBuilder(), getTargetTable(qb, dest), updating(dest), inputRR);
       if (constraintUDF == null) {
         return null;
       }
 
-      RelNode constraintRel = genFilterRelNode(constraintUDF, srcRel, outerNameToPosMap, outerRR);
-      return new Pair<>(constraintRel, inputRR);
+      RelNode constraintRel = genFilterRelNode(constraintUDF, selPair.left, outerNameToPosMap, outerRR);
+
+      List<RexNode> originalInputRefs = toRexNodeList(selPair.left);
+      List<RexNode> selectedRefs = Lists.newArrayList();
+      for (int index = 0; index < selPair.right.getColumnInfos().size(); index++) {
+        selectedRefs.add(originalInputRefs.get(index));
+      }

Review comment:
       The Project may contains columns which are not in the top Project and not present in the row schema. However these columns may referenced in constraint filter expressions or sort and order by keys.
   I found that at the end of Project generation all columns coming from the input RowResolver of the Project are added to the output RowResolver:
   https://github.com/apache/hive/blob/d0d3f0aa50fa7b50ec74cae0dda0b93271799313/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java#L4738
   
   Since these are added to the end of the list the selected ones should be a prefix of the full list.




-- 
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.

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



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