[ 
https://issues.apache.org/jira/browse/HIVE-26438?focusedWorklogId=796641&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-796641
 ]

ASF GitHub Bot logged work on HIVE-26438:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Jul/22 15:40
            Start Date: 30/Jul/22 15:40
    Worklog Time Spent: 10m 
      Work Description: 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).





Issue Time Tracking
-------------------

    Worklog Id:     (was: 796641)
    Time Spent: 20m  (was: 10m)

> Remove unnecessary optimization in canHandleQbForCbo() method
> -------------------------------------------------------------
>
>                 Key: HIVE-26438
>                 URL: https://issues.apache.org/jira/browse/HIVE-26438
>             Project: Hive
>          Issue Type: Bug
>            Reporter: Abhay
>            Assignee: Abhay
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> This ticket is an improvement on 
> https://issues.apache.org/jira/browse/HIVE-26426.  The canHandleQbForCbo() 
> checks whether Calcite handle the query or not and it returns null if the 
> query can be handled; non-null reason string if it cannot be. 
> But currently, it returns an empty string if INFO Log is not enabled. This is 
> probably a performance optimization that is not needed and can be simplified. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to