asolimando commented on a change in pull request #2230:
URL: https://github.com/apache/calcite/pull/2230#discussion_r514578595



##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -2956,7 +2963,12 @@ public static Object structAccess(Object structObject, 
int index, String fieldNa
     } else {
       Class<?> beanClass = structObject.getClass();
       try {
-        Field structField = beanClass.getDeclaredField(fieldName);
+        Field structField;
+        if (index >= 0 && index < beanClass.getDeclaredFields().length) {
+          structField = beanClass.getDeclaredFields()[index];
+        } else {
+          structField = beanClass.getDeclaredField(fieldName);
+        }

Review comment:
       No, there is no particular reason, on top of that I have realised we 
already check that the index (when numeric) is within its boundaries in 
`SqlItemOperator`, so no need to check again here. 
   
   The code got simplified to:
   ```
   if (fieldName == null) {
     structField = beanClass.getDeclaredFields()[index];
   } else {
     structField = beanClass.getDeclaredField(fieldName);
   }
   ```




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


Reply via email to