|
5 | 5 | */
|
6 | 6 | package org.elasticsearch.xpack.sql.analysis.analyzer;
|
7 | 7 |
|
8 |
| -import java.util.stream.Collectors; |
9 | 8 | import org.elasticsearch.test.ESTestCase;
|
10 | 9 | import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
|
11 | 10 | import org.elasticsearch.xpack.ql.expression.Alias;
|
|
29 | 28 |
|
30 | 29 | import java.util.List;
|
31 | 30 | import java.util.Map;
|
| 31 | +import java.util.stream.Collectors; |
32 | 32 |
|
33 | 33 | import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN;
|
34 | 34 | import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
|
@@ -277,4 +277,27 @@ public void testGroupByAmbiguity() {
|
277 | 277 | + "matches any of [line 1:37 [m], line 1:55 [m]]",
|
278 | 278 | ex.getMessage());
|
279 | 279 | }
|
| 280 | + |
| 281 | + public void testFunctionOverNonExistingFieldAsArgumentAndSameAlias() throws Exception { |
| 282 | + Map<String, EsField> mapping = TypesTests.loadMapping("mapping-basic.json"); |
| 283 | + EsIndex index = new EsIndex("test", mapping); |
| 284 | + getIndexResult = IndexResolution.valid(index); |
| 285 | + analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier); |
| 286 | + |
| 287 | + VerificationException ex = expectThrows(VerificationException.class, () -> |
| 288 | + plan("SELECT sum(missing) AS missing FROM test WHERE missing = 0")); |
| 289 | + assertEquals("Found 1 problem\nline 1:12: Unknown column [missing]", ex.getMessage()); |
| 290 | + } |
| 291 | + |
| 292 | + public void testFunctionWithExpressionOverNonExistingFieldAsArgumentAndSameAlias() throws Exception { |
| 293 | + Map<String, EsField> mapping = TypesTests.loadMapping("mapping-basic.json"); |
| 294 | + EsIndex index = new EsIndex("test", mapping); |
| 295 | + getIndexResult = IndexResolution.valid(index); |
| 296 | + analyzer = new Analyzer(SqlTestUtils.TEST_CFG, functionRegistry, getIndexResult, verifier); |
| 297 | + |
| 298 | + VerificationException ex = expectThrows(VerificationException.class, () -> |
| 299 | + plan("SELECT LENGTH(CONCAT(missing, 'x')) + 1 AS missing FROM test WHERE missing = 0")); |
| 300 | + assertEquals("Found 1 problem\nline 1:22: Unknown column [missing]", ex.getMessage()); |
| 301 | + } |
| 302 | + |
280 | 303 | }
|
0 commit comments