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



##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -2517,6 +2517,18 @@ public static Object item(Object object, Object index) {
     if (object instanceof List && index instanceof Number) {
       return arrayItem((List) object, ((Number) index).intValue());
     }
+    if (index instanceof Number) {
+      return structAccess(object, ((Number) index).intValue() - 1, ""); // 1 
indexed
+    }
+    if (index instanceof String) {

Review comment:
       What are we trying to support with this if statement? Is it the 
following pattern?
   ```
   person['1'] 
   person[1]
   ```
   Shouldn't we say that if it is a string it denotes access by field name and 
if it is an int it is access by field index?
   Are there tests for this?

##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -2517,6 +2517,18 @@ public static Object item(Object object, Object index) {
     if (object instanceof List && index instanceof Number) {
       return arrayItem((List) object, ((Number) index).intValue());
     }
+    if (index instanceof Number) {
+      return structAccess(object, ((Number) index).intValue() - 1, ""); // 1 
indexed
+    }
+    if (index instanceof String) {

Review comment:
       We shouldn't rely on the exception for normal code flow, plus its costly 
especially if it happens per access.

##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -2517,6 +2517,18 @@ public static Object item(Object object, Object index) {
     if (object instanceof List && index instanceof Number) {
       return arrayItem((List) object, ((Number) index).intValue());
     }
+    if (index instanceof Number) {

Review comment:
       According to the signature of the operator it should be an Integer, not 
any number, is that right?




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