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 2022/07/30 15:40:18 UTC

[GitHub] [hive] jfsii commented on a diff in pull request #3487: HIVE-26438: Remove unnecessary optimization in canHandleQbForCbo()

jfsii commented on code in PR #3487:
URL: https://github.com/apache/hive/pull/3487#discussion_r933840592


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -987,30 +985,29 @@ private static String canHandleQbForCbo(QueryProperties queryProperties, HiveCon
 
     // Not ok to run CBO, build error message.
     String msg = "";
-    if (verbose) {
-      if (queryProperties.hasClusterBy()) {
-        msg += "has cluster by; ";
-      }
-      if (queryProperties.hasDistributeBy()) {
-        msg += "has distribute by; ";
-      }
-      if (queryProperties.hasSortBy() && queryProperties.hasLimit()) {
-        msg += "has sort by with limit; ";
-      }
-      if (queryProperties.hasPTF()) {
-        msg += "has PTF; ";
-      }
-      if (queryProperties.usesScript()) {
-        msg += "uses scripts; ";
-      }
-      if (queryProperties.hasLateralViews()) {
-        msg += "has lateral views; ";
-      }
-      if (msg.isEmpty()) {
-        msg += "has some unspecified limitations; ";
-      }
-      msg = msg.substring(0, msg.length() - 2);
+    if (queryProperties.hasClusterBy()) {
+      msg += "has cluster by; ";
+    }
+    if (queryProperties.hasDistributeBy()) {
+      msg += "has distribute by; ";
+    }
+    if (queryProperties.hasSortBy() && queryProperties.hasLimit()) {
+      msg += "has sort by with limit; ";
+    }
+    if (queryProperties.hasPTF()) {
+      msg += "has PTF; ";
     }
+    if (queryProperties.usesScript()) {
+      msg += "uses scripts; ";
+    }
+    if (queryProperties.hasLateralViews()) {
+      msg += "has lateral views; ";
+    }
+    if (msg.isEmpty()) {
+    msg += "has some unspecified limitations; ";

Review Comment:
   indenting is incorrect  -
   one positive change from my suggestions above is that it enforces anyone who modifies this section of code with new conditions - would be forced to also provide a valid error message (so the only time msgs/reason would/should be empty is if it is a valid QB for  CBO).



##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -987,30 +985,29 @@ private static String canHandleQbForCbo(QueryProperties queryProperties, HiveCon
 
     // Not ok to run CBO, build error message.
     String msg = "";
-    if (verbose) {
-      if (queryProperties.hasClusterBy()) {
-        msg += "has cluster by; ";
-      }
-      if (queryProperties.hasDistributeBy()) {
-        msg += "has distribute by; ";
-      }
-      if (queryProperties.hasSortBy() && queryProperties.hasLimit()) {
-        msg += "has sort by with limit; ";
-      }
-      if (queryProperties.hasPTF()) {
-        msg += "has PTF; ";
-      }
-      if (queryProperties.usesScript()) {
-        msg += "uses scripts; ";
-      }
-      if (queryProperties.hasLateralViews()) {
-        msg += "has lateral views; ";
-      }
-      if (msg.isEmpty()) {
-        msg += "has some unspecified limitations; ";
-      }
-      msg = msg.substring(0, msg.length() - 2);
+    if (queryProperties.hasClusterBy()) {

Review Comment:
   I would maybe change this to something like (but this is more of an opinion):
   List<String> reasons = new ArrayList();
   and in each if () { reason.add(errorMsg); }
   and at the end do:
   return Strings.join("; ", reasons);
   
   You could technically combine the top if check for validity with the error message processing to force each case to always have a valid error message by deleting the top if (conditions) { return null },
   add the missing condition to the error messages (queryProperties.isCBOSupportedLateralViews())) and change the last return to be something like:
   return reasons.isEmpty() ? null : Strings.join("; ",  reasons);
   
   Hopefully that makes sense? It is also a matter of style - feel free to ignore if you do not think the above suggestions make the code more readable or less fragile. (I'm not 100% sure they make it better - but in my head I think they do).



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

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