From 6afb63ea3b98aa95c6bcf19d673d3ac484e620de Mon Sep 17 00:00:00 2001 From: Peng Huo Date: Thu, 29 Jan 2026 17:52:33 -0800 Subject: [PATCH 1/2] Improve expand command error message for non-nested fields Signed-off-by: Peng Huo --- .../sql/calcite/CalciteRelNodeVisitor.java | 12 +++++ .../rest-api-spec/test/issues/5065.yml | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/5065.yml diff --git a/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java b/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java index f1bc5fd6a0..e2f18630ac 100644 --- a/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java +++ b/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java @@ -3331,6 +3331,18 @@ private void flattenParsedPattern( private void buildExpandRelNode( RexInputRef arrayFieldRex, String arrayFieldName, String alias, CalcitePlanContext context) { + // Validate that the field is an array type. + // Only nested array fields are supported by expand command. + RelDataType fieldType = arrayFieldRex.getType(); + if (fieldType.getSqlTypeName() != SqlTypeName.ARRAY) { + throw new UnsupportedOperationException( + String.format( + "Expand command only supports nested array fields. " + + "Field '%s' has type '%s' which is not a nested array.", + arrayFieldName, + fieldType.getSqlTypeName())); + } + // 3. Capture the outer row in a CorrelationId Holder correlVariable = Holder.empty(); context.relBuilder.variable(correlVariable::set); diff --git a/integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/5065.yml b/integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/5065.yml new file mode 100644 index 0000000000..422adffc7f --- /dev/null +++ b/integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/5065.yml @@ -0,0 +1,45 @@ +setup: + - do: + indices.create: + index: test-idx-5065 + body: + settings: + number_of_shards: 1 + mappings: + properties: + nums: + type: long + - do: + index: + index: test-idx-5065 + id: 1 + refresh: true + body: + nums: [1, 2, 3] + - do: + query.settings: + body: + transient: + plugins.calcite.enabled: true +--- +teardown: + - do: + query.settings: + body: + transient: + plugins.calcite.enabled: false + - do: + indices.delete: + index: test-idx-5065 + ignore_unavailable: true + +--- +"Expand on scalar type should fail with clear error message": + - do: + catch: bad_request + ppl: + body: + query: 'source=test-idx-5065 | expand nums' + - match: { error.type: "UnsupportedOperationException" } + - match: { error.reason: "/.*Expand command only works on array types.*/" } + - match: { error.details: "/.*nums.*BIGINT.*/" } From a7a20b5bd958bfc78fa527032085ed762c7f8792 Mon Sep 17 00:00:00 2001 From: Peng Huo Date: Fri, 30 Jan 2026 10:12:25 -0800 Subject: [PATCH 2/2] Update Signed-off-by: Peng Huo --- .../org/opensearch/sql/calcite/CalciteRelNodeVisitor.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java b/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java index e2f18630ac..280085968b 100644 --- a/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java +++ b/core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java @@ -3339,10 +3339,9 @@ private void buildExpandRelNode( String.format( "Expand command only supports nested array fields. " + "Field '%s' has type '%s' which is not a nested array.", - arrayFieldName, - fieldType.getSqlTypeName())); + arrayFieldName, fieldType.getSqlTypeName())); } - + // 3. Capture the outer row in a CorrelationId Holder correlVariable = Holder.empty(); context.relBuilder.variable(correlVariable::set);