Skip to content

Commit 60f0bd6

Browse files
committed
WIP: debuging expand
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 7220ed0 commit 60f0bd6

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -842,34 +842,40 @@ public RelNode visitExpand(Expand expand, CalcitePlanContext context) {
842842

843843
var relBuilder = context.relBuilder;
844844

845-
// 3. Get the field to expand
845+
// 2. Get the field to expand
846846
Field arrayField = expand.getField();
847847

848-
// 5. Unnest the array field
848+
// 3. Unnest the array field
849849
// Analyze the array field to get its RexNode
850-
RexNode arrayFieldRex = rexVisitor.analyze(arrayField, context);
851-
850+
RexInputRef arrayFieldRex = (RexInputRef) rexVisitor.analyze(arrayField, context);
852851
// Push the original table to the RelBuilder stack
853852
RelNode originalTable = relBuilder.peek();
854853
// No alias is provided in the expand command, so we remove the original array field,
855854
// then replace it with the unnest result.
856-
relBuilder.projectExcept(arrayFieldRex);
857-
relBuilder.push(originalTable);
855+
// relBuilder.projectExcept(arrayFieldRex);
858856

859-
// Join on ROW_NUMBER_COLUMN_NAME
857+
// Capture the outer row in a CorrelationId
860858
Holder<RexCorrelVariable> correlVariable = Holder.empty();
861859
relBuilder.variable(correlVariable::set);
862860

863-
relBuilder.project(List.of(arrayFieldRex), List.of(), false, List.of(correlVariable.get().id));
861+
relBuilder.push(originalTable);
862+
863+
RexNode correlArrayField =
864+
relBuilder.field(
865+
context.rexBuilder.makeCorrel(originalTable.getRowType(), correlVariable.get().id),
866+
arrayFieldRex.getIndex());
867+
868+
relBuilder.project(
869+
List.of(correlArrayField),
870+
List.of(arrayField.getField().toString()),
871+
false,
872+
List.of(correlVariable.get().id));
873+
864874
// Alias is not supported in expand yet, we pass in an empty list
865875
relBuilder.uncollect(List.of(), false);
866876

867-
List<RexNode> allFields =
868-
relBuilder.peek().getRowType().getFieldList().stream()
869-
.map(f -> (RexNode) relBuilder.field(f.getName()))
870-
.toList();
871-
872-
relBuilder.correlate(JoinRelType.INNER, correlVariable.get().id, relBuilder.fields());
877+
// ImmutableBitSet requiredFields = originalTable.getRowType().getFieldList()
878+
relBuilder.correlate(JoinRelType.INNER, correlVariable.get().id, arrayFieldRex);
873879

874880
return relBuilder.peek();
875881
}

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteExpandIT.java renamed to integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteExpandCommandIT.java

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"index":{"_id":"1"}}
2+
{"numbers":[1, 2],"strings": ["a", "b"]}
3+
{"index":{"_id":"2"}}
4+
{"numbers":[3, 4],"strings": ["c", "d", "e"]}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"mappings": {
3+
"properties": {
4+
"numbers": {
5+
"type": "long"
6+
},
7+
"strings": {
8+
"type": "text",
9+
"fields": {
10+
"keyword": {
11+
"type": "keyword",
12+
"ignore_above": 256
13+
}
14+
}
15+
}
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)