|
5 | 5 |
|
6 | 6 | package org.opensearch.sql.ppl.antlr; |
7 | 7 |
|
8 | | -import static org.junit.Assert.assertEquals; |
9 | | -import static org.junit.Assert.assertNotEquals; |
10 | | -import static org.junit.Assert.assertNotNull; |
11 | | -import static org.junit.Assert.assertThrows; |
12 | | -import static org.junit.Assert.assertTrue; |
| 8 | +import static org.junit.Assert.*; |
13 | 9 |
|
14 | 10 | import java.util.List; |
15 | 11 | import org.antlr.v4.runtime.CommonTokenStream; |
@@ -199,11 +195,49 @@ public void testDynamicSourceWithSingleSource() { |
199 | 195 | } |
200 | 196 |
|
201 | 197 | @Test |
202 | | - public void testDynamicSourceRequiresAtLeastOneSource() { |
203 | | - // The grammar requires at least one source reference before optional filter args |
204 | | - // This test documents that behavior |
205 | | - exceptionRule.expect(RuntimeException.class); |
206 | | - new PPLSyntaxParser().parse("source=[fieldIndex=\"httpStatus\", region=\"us-west-2\"]"); |
| 198 | + public void testDynamicSourceWithoutSource() { |
| 199 | + String query = "source=[fieldIndex=\"httpStatus\", region=\"us-west-2\"]"; |
| 200 | + OpenSearchPPLLexer lexer = new OpenSearchPPLLexer(new CaseInsensitiveCharStream(query)); |
| 201 | + OpenSearchPPLParser parser = new OpenSearchPPLParser(new CommonTokenStream(lexer)); |
| 202 | + |
| 203 | + OpenSearchPPLParser.RootContext root = parser.root(); |
| 204 | + OpenSearchPPLParser.SearchFromContext searchFrom = |
| 205 | + (OpenSearchPPLParser.SearchFromContext) |
| 206 | + root.pplStatement().queryStatement().pplCommands().searchCommand(); |
| 207 | + OpenSearchPPLParser.DynamicSourceClauseContext dynamicSource = |
| 208 | + searchFrom.fromClause().dynamicSourceClause(); |
| 209 | + assertNull(dynamicSource.sourceReferences()); |
| 210 | + assertEquals( |
| 211 | + "Should have 2 filter arg", 2, dynamicSource.sourceFilterArgs().sourceFilterArg().size()); |
| 212 | + assertEquals( |
| 213 | + "Filter arg text", |
| 214 | + "fieldIndex=\"httpStatus\",region=\"us-west-2\"", |
| 215 | + dynamicSource.sourceFilterArgs().getText()); |
| 216 | + } |
| 217 | + |
| 218 | + @Test |
| 219 | + public void testDynamicSourceWithAllSources() { |
| 220 | + String query = "source=[`*`, fieldIndex=\"httpStatus\", region=\"us-west-2\"]"; |
| 221 | + OpenSearchPPLLexer lexer = new OpenSearchPPLLexer(new CaseInsensitiveCharStream(query)); |
| 222 | + OpenSearchPPLParser parser = new OpenSearchPPLParser(new CommonTokenStream(lexer)); |
| 223 | + |
| 224 | + OpenSearchPPLParser.RootContext root = parser.root(); |
| 225 | + OpenSearchPPLParser.SearchFromContext searchFrom = |
| 226 | + (OpenSearchPPLParser.SearchFromContext) |
| 227 | + root.pplStatement().queryStatement().pplCommands().searchCommand(); |
| 228 | + OpenSearchPPLParser.DynamicSourceClauseContext dynamicSource = |
| 229 | + searchFrom.fromClause().dynamicSourceClause(); |
| 230 | + assertEquals( |
| 231 | + "Should have 1 source reference", |
| 232 | + 1, |
| 233 | + dynamicSource.sourceReferences().sourceReference().size()); |
| 234 | + assertEquals("Source reference text", "`*`", dynamicSource.sourceReferences().getText()); |
| 235 | + assertEquals( |
| 236 | + "Should have 2 filter arg", 2, dynamicSource.sourceFilterArgs().sourceFilterArg().size()); |
| 237 | + assertEquals( |
| 238 | + "Filter arg text", |
| 239 | + "fieldIndex=\"httpStatus\",region=\"us-west-2\"", |
| 240 | + dynamicSource.sourceFilterArgs().getText()); |
207 | 241 | } |
208 | 242 |
|
209 | 243 | @Test |
|
0 commit comments