michaelmior commented on a change in pull request #1319: [CALCITE-3195] Handle 
UDF that throws checked exceptions in enumerable code generator
URL: https://github.com/apache/calcite/pull/1319#discussion_r306312753
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
 ##########
 @@ -622,6 +624,35 @@ public Expression handleNull(Expression input, 
RexImpTable.NullAs nullAs) {
     return unboxed;
   }
 
+  /**
+   * Handle checked Exceptions declared in Method. In such case,
+   * method call should be wrapped in a try...catch block.
+   * "
+   *      final Type method_call;
+   *      try {
+   *        method_call = callExpr
+   *      } catch (Exception e) {
+   *        throw new RuntimeException(e);
+   *      }
+   * "
+   */
+  Expression handleMethodCheckedExceptions(Expression callExpr) {
+    // Try statement
+    ParameterExpression methodCall = Expressions.parameter(
+        callExpr.getType(), list.newName("method_call"));
+    list.add(Expressions.declare(Modifier.FINAL, methodCall, null));
+    Statement st = Expressions.statement(
+        Expressions.assign(methodCall, callExpr));
+    // Catch Block, wrap checked exception in unchecked exception
+    ParameterExpression e = Expressions.parameter(0, Exception.class, "e");
+    Expression uncheckedException =
+        Expressions.new_(RuntimeException.class, e);
+    CatchBlock cb = Expressions.catch_(e,
+        Expressions.throw_(uncheckedException));
 
 Review comment:
   The line breaks here seem unnecessary as these L648-651 could fit on two 
lines without being too long. (L644-645 could also be collapsed to a single 
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:
[email protected]


With regards,
Apache Git Services

Reply via email to