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 2020/05/07 15:18:38 UTC

[GitHub] [hive] jcamachor commented on a change in pull request #1006: HIVE-23371 get const value noise

jcamachor commented on a change in pull request #1006:
URL: https://github.com/apache/hive/pull/1006#discussion_r421586996



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
##########
@@ -1637,28 +1639,28 @@ private static ColStatistics buildColStatForConstant(HiveConf conf, long numRows
   }
 
   private static Optional<Number> getConstValue(ExprNodeConstantDesc encd) {
-    if (encd.getValue() != null) {
-      String constant = encd.getValue().toString();
-      PrimitiveCategory category = GenericUDAFSum.getReturnType(encd.getTypeInfo());
-      try {
-        switch (category) {
-        case INT:
-        case BYTE:
-        case SHORT:
-        case LONG:
-          return Optional.of(Long.parseLong(constant));
-        case FLOAT:
-        case DOUBLE:
-        case DECIMAL:
-          return Optional.of(Double.parseDouble(constant));
-        default:
-        }
-      } catch (Exception e) {
-        LOG.debug("Interpreting constant (" + constant + ")  resulted in exception", e);
-      }
+    if (encd.getValue() == null) {
+      return Optional.empty();
+    }
+    String constant = encd.getValue().toString();
+    PrimitiveCategory category = GenericUDAFSum.getReturnType(encd.getTypeInfo());
+    if (category == null) {
+      return Optional.empty();
+    }
+    switch (category) {
+    case INT:
+    case BYTE:
+    case SHORT:
+    case LONG:
+      return Optional.ofNullable(Longs.tryParse(constant));
+    case FLOAT:
+    case DOUBLE:
+    case DECIMAL:
+      return Optional.ofNullable(Doubles.tryParse(constant));
+    default:
+      return Optional.empty();
+    }
     }

Review comment:
       nit. Indentation seems off for this line?




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