Skip to content

Commit be129ec

Browse files
authored
Map Calcite ROW to STRUCT in convertSqlTypeNameToExprType (#5737)
convertExprTypeToRelDataType builds STRUCT as MAP<VARCHAR, ANY>, since the v2 path only passes _source JSON through and needs no field types. So the reverse mapping only had `case MAP -> STRUCT` — a genuine Calcite ROW matched nothing, fell through to `default -> UNKNOWN`, and surfaced as "type": "unknown" in the response schema. That is reachable from the analytics engine, which materializes an `object` field as a real ROW built from typed columns. Before, `fields city` reported "unknown"; now "struct", matching what a lucene-only cluster returns for the same mapping. Signed-off-by: Marc Handalian <handalm@amazon.com> Signed-off-by: Marc Handalian <marc.handalian@gmail.com>
1 parent be527b5 commit be129ec

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/utils/OpenSearchTypeFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ public static ExprType convertSqlTypeNameToExprType(SqlTypeName sqlTypeName) {
252252
INTERVAL;
253253
case ARRAY -> ARRAY;
254254
case MAP -> STRUCT;
255+
// Calcite spells a struct as ROW. convertExprTypeToRelDataType builds STRUCT as
256+
// MAP<VARCHAR, ANY> since the v2 path only passes _source JSON through, so a genuine ROW —
257+
// from an engine that builds a struct out of typed columns — matched nothing and fell
258+
// through to UNKNOWN.
259+
case ROW -> STRUCT;
255260
case GEOMETRY -> GEO_POINT;
256261
case NULL, ANY, OTHER -> UNDEFINED;
257262
default -> UNKNOWN;

core/src/test/java/org/opensearch/sql/calcite/utils/OpenSearchTypeFactoryTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ public void testConvertExprTypeBinaryToNullableVarbinary() {
286286
assertTrue(result.isNullable());
287287
}
288288

289+
@Test
290+
public void testConvertRowReturnsStructExprType() {
291+
assertEquals(
292+
ExprCoreType.STRUCT, OpenSearchTypeFactory.convertSqlTypeNameToExprType(SqlTypeName.ROW));
293+
}
294+
289295
// ---------- convertAnalyticsEngineRelDataTypeToExprType ----------
290296
// UDT-aware variant for the response-schema path. Must agree with the
291297
// planner-internal convertRelDataTypeToExprType on every non-UDT input.

0 commit comments

Comments
 (0)