|
5 | 5 |
|
6 | 6 | package org.opensearch.sql.ppl.calcite; |
7 | 7 |
|
| 8 | +import static org.junit.Assert.assertTrue; |
| 9 | +import static org.junit.Assert.fail; |
| 10 | + |
8 | 11 | import org.apache.calcite.rel.RelNode; |
9 | 12 | import org.apache.calcite.test.CalciteAssert; |
10 | 13 | import org.junit.Test; |
@@ -154,19 +157,16 @@ public void testRegexCaseInsensitive() { |
154 | 157 | } |
155 | 158 |
|
156 | 159 | @Test |
157 | | - public void testRegexWithNumericPattern() { |
158 | | - String ppl = "source=EMP | regex SAL='[0-9]{4,}' | fields ENAME, SAL"; |
159 | | - RelNode root = getRelNode(ppl); |
160 | | - String expectedLogical = |
161 | | - "LogicalProject(ENAME=[$1], SAL=[$5])\n" |
162 | | - + " LogicalFilter(condition=[REGEXP_CONTAINS($5, '[0-9]{4,}':VARCHAR)])\n" |
163 | | - + " LogicalTableScan(table=[[scott, EMP]])\n"; |
164 | | - verifyLogical(root, expectedLogical); |
165 | | - |
166 | | - String expectedSparkSql = |
167 | | - "SELECT `ENAME`, `SAL`\n" |
168 | | - + "FROM `scott`.`EMP`\n" |
169 | | - + "WHERE REGEXP_CONTAINS(`SAL`, '[0-9]{4,}')"; |
170 | | - verifyPPLToSparkSQL(root, expectedSparkSql); |
| 160 | + public void testRegexWithNonStringFieldThrowsException() { |
| 161 | + String ppl = "source=EMP | regex EMPNO='123.*'"; |
| 162 | + try { |
| 163 | + getRelNode(ppl); |
| 164 | + fail("Expected IllegalArgumentException for non-string field type"); |
| 165 | + } catch (IllegalArgumentException e) { |
| 166 | + assertTrue( |
| 167 | + "Expected error message about field type", |
| 168 | + e.getMessage().contains("Regex command requires field of string type")); |
| 169 | + assertTrue("Expected error message to mention field name", e.getMessage().contains("EMPNO")); |
| 170 | + } |
171 | 171 | } |
172 | 172 | } |
0 commit comments