snuyanzin commented on code in PR #4889:
URL: https://github.com/apache/calcite/pull/4889#discussion_r3089053461


##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -4173,43 +4172,27 @@ private static class LastImplementor implements 
MatchImplementor {
 
       final String alpha = ((RexPatternFieldRef) 
call.getOperands().get(0)).getAlpha();
 
-      // TODO: verify if the variable is needed
-      @SuppressWarnings("unused")
-      final BinaryExpression lastIndex =
-          Expressions.subtract(
-              Expressions.call(rows, BuiltInMethod.COLLECTION_SIZE.method),
-              Expressions.constant(1));
-
       // Just take the last one, if exists
       if ("*".equals(alpha)) {
         setInputGetterIndex(translator, i);
-        // Important, unbox the node / expression to avoid NullAs.NOT_POSSIBLE
-        final RexPatternFieldRef ref = (RexPatternFieldRef) node;
-        final RexPatternFieldRef newRef =
-            new RexPatternFieldRef(ref.getAlpha(),
-                ref.getIndex(),
-                translator.typeFactory.createTypeWithNullability(ref.getType(),
-                    true));
-        final Expression expression = translator.translate(newRef, 
NullAs.NULL);
-        setInputGetterIndex(translator, null);
-        return expression;
       } else {
         // Alpha != "*" so we have to search for a specific one to find and 
use that, if found
+        // otherwise pick the last one
         setInputGetterIndex(translator,
-            Expressions.call(BuiltInMethod.MATCH_UTILS_LAST_WITH_SYMBOL.method,
-                Expressions.constant(alpha), rows, symbols, i));
-
-        // Important, unbox the node / expression to avoid NullAs.NOT_POSSIBLE
-        final RexPatternFieldRef ref = (RexPatternFieldRef) node;
-        final RexPatternFieldRef newRef =
-            new RexPatternFieldRef(ref.getAlpha(),
-                ref.getIndex(),
-                translator.typeFactory.createTypeWithNullability(ref.getType(),
-                    true));
-        final Expression expression = translator.translate(newRef, 
NullAs.NULL);
-        setInputGetterIndex(translator, null);

Review Comment:
   since in both branches the code is almost same, extracted it



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to