Skip to content

Commit b909cdf

Browse files
committed
fix return type in extract multi
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent 39d0961 commit b909cdf

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/function/udf/RexExtractMultiFunction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public RexExtractMultiFunction() {
3131

3232
@Override
3333
public SqlReturnTypeInference getReturnTypeInference() {
34-
return call ->
35-
call.getTypeFactory()
36-
.createArrayType(call.getTypeFactory().createSqlType(SqlTypeName.VARCHAR, 2000), -1);
34+
return call -> {
35+
var elementType = call.getTypeFactory().createSqlType(SqlTypeName.VARCHAR, 2000);
36+
return call.getTypeFactory()
37+
.createArrayType(call.getTypeFactory().createTypeWithNullability(elementType, true), -1);
38+
};
3739
}
3840

3941
@Override

core/src/test/java/org/opensearch/sql/expression/function/udf/RexExtractMultiFunctionTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ public void testReturnTypeInference() {
160160
assertNotNull(function.getReturnTypeInference(), "Return type inference should not be null");
161161
}
162162

163+
@Test
164+
public void testNullReturnTypeCompatibility() {
165+
List<String> result1 =
166+
RexExtractMultiFunction.extractMultipleGroups("no match", "(\\d+)", 1, 5);
167+
assertNull(result1, "Should return null when no matches found");
168+
169+
List<String> result2 = RexExtractMultiFunction.extractMultipleGroups("abc", "(\\w+)", 2, 5);
170+
assertNull(result2, "Should return null for invalid group index");
171+
172+
List<String> result3 = RexExtractMultiFunction.extractMultipleGroups("", "(\\w+)", 1, 5);
173+
assertNull(result3, "Should return null for empty string with no matches");
174+
}
175+
163176
@Test
164177
public void testOperandMetadata() {
165178
assertNotNull(function.getOperandMetadata(), "Operand metadata should not be null");

0 commit comments

Comments
 (0)