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



##########
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 (fieldName == null) {
+          structField = beanClass.getDeclaredFields()[index];

Review comment:
       The issue is known as https://issues.apache.org/jira/browse/CALCITE-2489
   
   I suggest we refrain from adding undefined behavior like 
`getDeclaredFields()[index]`, especially taking into account JVM diversity we 
have nowadays.
   
   
   The problem here is the implementation in the current PR might result in 
silent data corruption. For instance, if the input objects have different types 
(e.g. different subtypes of the same base type), then the order of the fields 
might vary across subtypes :-/
   
   So I would suggest:
   a) Use `relType.getFields()[index]` if it is possible (note, I mean struct 
field index rather reflection field index)
   b) Hide the feature under a disabled-by-default feature flag. Then users 
won't accidentally corrupt data "thanks" to an experimental feature.




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