Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import static com.google.common.collect.ImmutableRangeSet.Builder;
import static com.google.common.collect.ImmutableRangeSet.builder;
Expand Down Expand Up @@ -329,30 +330,43 @@ 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 = deserializeIntArray(jsonNode, FIELD_NAME_PARTITION_KEYS);
final int[] orderKeys = deserializeIntArray(jsonNode, FIELD_NAME_ORDER_KEYS);
final SortOrder[] sortOrders =
deserializeArray(
jsonNode,
FIELD_NAME_ORDER_DIRECTIONS,
node -> SortOrder.valueOf(node.asText()),
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, sortOrders);
}

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 int[] deserializeIntArray(JsonNode jsonNode, String fieldName) {
return deserializeListOrEmpty(jsonNode, fieldName, JsonNode::asInt).stream()
.mapToInt(Integer::intValue)
.toArray();
}

private static <T> T[] deserializeArray(
JsonNode jsonNode,
String fieldName,
Function<JsonNode, T> elementDeserializer,
T[] emptyArray) {
return deserializeListOrEmpty(jsonNode, fieldName, elementDeserializer).toArray(emptyArray);
}

return new RexTableArgCall(callType, inputIndex, partitionKeys, orderKeys, order);
private static <T> List<T> deserializeListOrEmpty(
JsonNode jsonNode, String fieldName, Function<JsonNode, T> elementDeserializer) {
final JsonNode arrayNode = jsonNode.get(fieldName);
if (arrayNode == null || arrayNode.isEmpty()) {
return List.of();
}
final List<T> result = new ArrayList<>(arrayNode.size());
for (final JsonNode element : arrayNode) {
result.add(elementDeserializer.apply(element));
}
return result;
}

private static RexNode deserializeCall(JsonNode jsonNode, SerdeContext serdeContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,23 @@ private static void serializeTableArgCall(
gen.writeStartObject();
gen.writeStringField(FIELD_NAME_KIND, KIND_TABLE_ARG_CALL);
gen.writeNumberField(FIELD_NAME_INPUT_INDEX, tableArgCall.getInputIndex());
gen.writeFieldName(FIELD_NAME_PARTITION_KEYS);
gen.writeArray(tableArgCall.getPartitionKeys(), 0, tableArgCall.getPartitionKeys().length);
gen.writeFieldName(FIELD_NAME_ORDER_KEYS);
gen.writeArray(tableArgCall.getOrderKeys(), 0, tableArgCall.getOrderKeys().length);
gen.writeFieldName(FIELD_NAME_ORDER_DIRECTIONS);
gen.writeStartArray();
for (SortOrder order : tableArgCall.getSortOrder()) {
gen.writeString(order.name());
if (tableArgCall.getPartitionKeys().length > 0) {
gen.writeFieldName(FIELD_NAME_PARTITION_KEYS);
gen.writeArray(
tableArgCall.getPartitionKeys(), 0, tableArgCall.getPartitionKeys().length);
}
if (tableArgCall.getOrderKeys().length > 0) {
gen.writeFieldName(FIELD_NAME_ORDER_KEYS);
gen.writeArray(tableArgCall.getOrderKeys(), 0, tableArgCall.getOrderKeys().length);
if (tableArgCall.getSortOrder().length > 0) {
gen.writeFieldName(FIELD_NAME_ORDER_DIRECTIONS);
gen.writeStartArray();
for (SortOrder order : tableArgCall.getSortOrder()) {
gen.writeString(order.name());
}
gen.writeEndArray();
}
}
gen.writeEndArray();
serializerProvider.defaultSerializeField(FIELD_NAME_TYPE, tableArgCall.getType(), gen);
gen.writeEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
"operands" : [ {
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ ],
"orderKeys" : [ ],
"orderDirections" : [ ],
"type" : "ROW<`id` INT, `op` VARCHAR(2147483647), `name` VARCHAR(2147483647)> NOT NULL"
}, {
"kind" : "CALL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"orderDirections" : [ ],
"type" : {
"type" : "ROW",
"nullable" : false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647), `score` INT> NOT NULL"
}, {
"kind" : "CALL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647), `score` INT> NOT NULL"
}, {
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 1,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647), `city` VARCHAR(2147483647)> NOT NULL"
}, {
"kind" : "CALL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647), `score` INT> NOT NULL"
}, {
"kind" : "CALL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"type" : {
"type" : "ROW",
"nullable" : false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"operands" : [ {
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ ],
"orderKeys" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647), `score` INT> NOT NULL"
}, {
"kind" : "LITERAL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ 0 ],
"orderKeys" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647) NOT NULL, `EXPR$1` BIGINT> NOT NULL"
}, {
"kind" : "CALL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
"operands" : [ {
"kind" : "TABLE_ARG_CALL",
"inputIndex" : 0,
"partitionKeys" : [ ],
"orderKeys" : [ ],
"orderDirections" : [ ],
"type" : "ROW<`name` VARCHAR(2147483647) NOT NULL, `score` BIGINT> NOT NULL"
}, {
"kind" : "CALL",
Expand Down