[ 
https://issues.apache.org/jira/browse/PHOENIX-7073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17788191#comment-17788191
 ] 

ASF GitHub Bot commented on PHOENIX-7073:
-----------------------------------------

tkhurana commented on code in PR #1712:
URL: https://github.com/apache/phoenix/pull/1712#discussion_r1399886203


##########
phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java:
##########
@@ -497,42 +502,98 @@ public static RowProjector compile(StatementContext 
context, SelectStatement sta
             index++;
         }
 
-        for (int i = arrayProjectedColumnRefs.size() - 1; i >= 0; i--) {
-            Expression expression = arrayProjectedColumnRefs.get(i);
-            Integer count = arrayExpressionCounts.get(expression);
+        for (int i = serverParsedProjectedColumnRefs.size() - 1; i >= 0; i--) {
+            Expression expression = serverParsedProjectedColumnRefs.get(i);
+            Integer count = serverParsedExpressionCounts.get(expression);
             if (count != 0) {
-                arrayKVRefs.remove(i);
-                arrayKVFuncs.remove(i);
-                arrayOldFuncs.remove(i);
+                serverParsedKVRefs.remove(i);
+                serverParsedKVFuncs.remove(i);
+                serverParsedOldFuncs.remove(i);
             }
         }
 
-        if (arrayKVFuncs.size() > 0 && arrayKVRefs.size() > 0) {
-            serailizeArrayIndexInformationAndSetInScan(context, arrayKVFuncs, 
arrayKVRefs);
+        if (serverParsedKVFuncs.size() > 0 && serverParsedKVRefs.size() > 0) {
+            String[]
+                    scanAttributes =
+                    new String[] { 
BaseScannerRegionObserver.SPECIFIC_ARRAY_INDEX,
+                            BaseScannerRegionObserver.JSON_VALUE_FUNCTION,
+                            BaseScannerRegionObserver.JSON_QUERY_FUNCTION };
+            Map<String, Class> attributeToFunctionMap = new HashMap<String, 
Class>() {{
+                put(scanAttributes[0], ArrayIndexFunction.class);
+                put(scanAttributes[1], JsonValueFunction.class);
+                put(scanAttributes[2], JsonQueryFunction.class);
+            }};
+            // This map is to keep track of the positions that get swapped 
with rearranging
+            // the functions in the serialized data to server.
+            Map<Integer, Integer> initialToShuffledPositionMap = new 
HashMap<>();
+            Map<String, List<Expression>>
+                    serverAttributeToFuncExpressionMap =
+                    new HashMap<String, List<Expression>>() {{
+                        for (String attribute : 
attributeToFunctionMap.keySet()) {
+                            put(attribute, new ArrayList<>());
+                        }
+                    }};
+            Map<String, List<KeyValueColumnExpression>>
+                    serverAttributeToKVExpressionMap =
+                    new HashMap<String, List<KeyValueColumnExpression>>() {{
+                        for (String attribute : 
attributeToFunctionMap.keySet()) {
+                            put(attribute, new ArrayList<>());
+                        }
+                    }};
+            int counter = 0;
+            for (String attribute : scanAttributes) {
+                for (int i = 0; i < serverParsedKVFuncs.size(); i++) {
+                    if (attributeToFunctionMap.get(attribute)
+                            .isInstance(serverParsedKVFuncs.get(i))) {
+                        initialToShuffledPositionMap.put(i, counter++);
+                        serverAttributeToFuncExpressionMap.get(attribute)
+                                .add(serverParsedKVFuncs.get(i));
+                        serverAttributeToKVExpressionMap.get(attribute)
+                                .add(serverParsedKVRefs.get(i));
+                    }
+                }
+            }
+            for (Map.Entry<String, Class> entry : 
attributeToFunctionMap.entrySet()) {
+                if 
(serverAttributeToFuncExpressionMap.get(entry.getKey()).size() > 0) {
+                    
serializeServerParsedExpressionInformationAndSetInScan(context, entry.getKey(),
+                            
serverAttributeToFuncExpressionMap.get(entry.getKey()),
+                            
serverAttributeToKVExpressionMap.get(entry.getKey()));
+                }
+            }
             KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0);
-            for (Expression expression : arrayKVRefs) {
+            for (Expression expression : serverParsedKVRefs) {
                 builder.addField(expression);
             }
             KeyValueSchema kvSchema = builder.build();
             ValueBitSet arrayIndexesBitSet = ValueBitSet.newInstance(kvSchema);
             builder = new KeyValueSchemaBuilder(0);
-            for (Expression expression : arrayKVFuncs) {
+            for (Expression expression : serverParsedKVFuncs) {
                 builder.addField(expression);
             }
             KeyValueSchema arrayIndexesSchema = builder.build();
 
             Map<Expression, Expression> replacementMap = new HashMap<>();
-            for(int i = 0; i < arrayOldFuncs.size(); i++){
-                Expression function =arrayKVFuncs.get(i);
-                replacementMap.put(arrayOldFuncs.get(i), new 
ArrayIndexExpression(i, function.getDataType(), arrayIndexesBitSet, 
arrayIndexesSchema));
+            for (int i = 0; i < serverParsedOldFuncs.size(); i++) {
+                Expression function = serverParsedKVFuncs.get(i);
+                replacementMap.put(serverParsedOldFuncs.get(i),
+                        new 
ArrayIndexExpression(initialToShuffledPositionMap.get(i),

Review Comment:
   I didn't quite understand why we are creating ArrayIndexExpression here ? 
Does this code not apply to json expressions ?





> Parse JSON columns on the server side
> -------------------------------------
>
>                 Key: PHOENIX-7073
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-7073
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Ranganath Govardhanagiri
>            Assignee: Ranganath Govardhanagiri
>            Priority: Major
>
> One of the optimizations mentioned in the Design spec is to _"pass the json 
> path to server side as part of the select and do the parsing on the server 
> side and then return the result to the client."_
> This is the task to track that change



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to