raminqaf commented on code in PR #28283:
URL: https://github.com/apache/flink/pull/28283#discussion_r3329942026


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/serde/RexNodeJsonDeserializer.java:
##########
@@ -329,30 +330,36 @@ private static RexNode deserializeTableArgCall(JsonNode 
jsonNode, SerdeContext s
 
         final int inputIndex = 
jsonNode.required(FIELD_NAME_INPUT_INDEX).intValue();
 
-        final JsonNode partitionKeysNode = 
jsonNode.required(FIELD_NAME_PARTITION_KEYS);
-        final int[] partitionKeys = new int[partitionKeysNode.size()];
-        for (int i = 0; i < partitionKeysNode.size(); ++i) {
-            partitionKeys[i] = partitionKeysNode.get(i).asInt();
-        }
+        final int[] partitionKeys =
+                deserializeArrayOrEmpty(jsonNode, FIELD_NAME_PARTITION_KEYS, 
JsonNode::asInt)
+                        .stream()
+                        .mapToInt(Integer::intValue)
+                        .toArray();
+        final int[] orderKeys =
+                deserializeArrayOrEmpty(jsonNode, FIELD_NAME_ORDER_KEYS, 
JsonNode::asInt).stream()
+                        .mapToInt(Integer::intValue)
+                        .toArray();
+        final SortOrder[] order =
+                deserializeArrayOrEmpty(
+                                jsonNode,
+                                FIELD_NAME_ORDER_DIRECTIONS,
+                                node -> SortOrder.valueOf(node.asText()))
+                        .toArray(new SortOrder[0]);
 
-        final JsonNode orderKeysNode = 
jsonNode.required(FIELD_NAME_ORDER_KEYS);
-        final int[] orderKeys = new int[orderKeysNode.size()];
-        for (int i = 0; i < orderKeysNode.size(); ++i) {
-            orderKeys[i] = orderKeysNode.get(i).asInt();
-        }
+        return new RexTableArgCall(callType, inputIndex, partitionKeys, 
orderKeys, order);
+    }
 
-        final JsonNode orderDirectionsNode = 
jsonNode.get(FIELD_NAME_ORDER_DIRECTIONS);
-        final SortOrder[] order;
-        if (orderDirectionsNode != null && !orderDirectionsNode.isEmpty()) {
-            order = new SortOrder[orderDirectionsNode.size()];
-            for (int i = 0; i < orderDirectionsNode.size(); ++i) {
-                order[i] = 
SortOrder.valueOf(orderDirectionsNode.get(i).asText());
-            }
-        } else {
-            order = new SortOrder[0];
+    private static <T> List<T> deserializeArrayOrEmpty(

Review Comment:
   Renamed to `deserializeListOrEmpty` and used it for objects like 
`SortOrder`. Introduced a new method called `deserializeToIntArray` that uses 
`deserializeListOrEmpty`.



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