ranganathg commented on code in PR #1712:
URL: https://github.com/apache/phoenix/pull/1712#discussion_r1399927195
##########
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:
This applies to JSON Expressions too. At a logical level ARRAY_ELM(array,
Index) and JSON_FUN(root, path) are identical in structure and evaluation path.
We are reusing it. Actually I had a local change to introduce
JSONPathExpression and create different code path and that needed multiple
conditional checks at multiple places. So continued with this. What's your
recommendation?
--
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]