From 42ae75f911eea3ce158620f690660b73f32dd0cf Mon Sep 17 00:00:00 2001 From: eemhu <125959687+eemhu@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:27:30 +0300 Subject: [PATCH] add '| teragrep exec foreachbatch' with tests (#85) --- .../antlr4/imports/COMMAND_TERAGREP_MODE.g4 | 1 + .../imports/DPLParserTransform_teragrep.g4 | 7 ++- .../pth_03/tests/TeragrepSyntaxTests.java | 36 ++++++++++++++- .../teragrep/teragrep_foreachbatch.txt | 46 +++++++++++++++++++ ...ragrep_foreachbatch_transformStatement.txt | 46 +++++++++++++++++++ 5 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch.txt create mode 100644 src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch_transformStatement.txt diff --git a/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 b/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 index 9c69eff..d914eb6 100644 --- a/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 +++ b/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 @@ -80,6 +80,7 @@ COMMAND_TERAGREP_MODE_PORT: 'port' -> pushMode(COMMAND_TERAGREP_IP_MODE); COMMAND_TERAGREP_MODE_DOT: '.'; COMMAND_TERAGREP_MODE_TOKENIZER: 'tokenizer'; COMMAND_TERAGREP_MODE_REGEXEXTRACT: 'regexextract'; +COMMAND_TERAGREP_MODE_FOREACHBATCH: 'foreachbatch'; COMMAND_TERAGREP_MODE_SYSLOG: 'syslog'; COMMAND_TERAGREP_MODE_STREAM: 'stream'; COMMAND_TERAGREP_MODE_LOAD: 'load'; diff --git a/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 b/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 index ee7e864..a3fa440 100644 --- a/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 +++ b/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 @@ -60,7 +60,12 @@ t_execParameter | t_bloomModeParameter | t_tokenizerParameter | t_regexextractParameter - | t_dynatraceParameter) + | t_dynatraceParameter + | t_forEachBatchParameter) + ; + +t_forEachBatchParameter + : COMMAND_TERAGREP_MODE_FOREACHBATCH ; t_dynatraceParameter diff --git a/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java b/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java index 893e4ea..7128315 100644 --- a/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java +++ b/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java @@ -75,7 +75,9 @@ public class TeragrepSyntaxTests { "teragrep_hdfs_save_all_params", "teragrep_hdfs_save_codec", "teragrep_syslog_stream", - "teragrep_syslog_stream_host_port" + "teragrep_syslog_stream_host_port", + "teragrep_foreachbatch", + "teragrep_foreachbatch_transformStatement" }) public void teragrepSyntaxParseTest(String arg) { String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt"; @@ -393,4 +395,36 @@ void testRegexExtractWithParams(String arg) { assertEquals(1, inputNodes.getLength()); assertEquals(1, outputNodes.getLength()); } + + @ParameterizedTest + @ValueSource(strings = { + "teragrep_foreachbatch", + }) + void testTeragrepForEachBatch(String arg) { + ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); + String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt"; + + String febParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_forEachBatchParameter"; + NodeList febParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, febParamPath, false)); + + // Check that 1 found for each path + assertEquals(1, febParamNodes.getLength()); + } + + @ParameterizedTest + @ValueSource(strings = { + "teragrep_foreachbatch_transformStatement", + }) + void testTeragrepForEachBatchWithTransformStatement(String arg) { + ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); + String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt"; + + String febParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_forEachBatchParameter"; + String transformStmtPath = "/root/transformStatement/transformStatement/statsTransformation"; + NodeList febParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, febParamPath, false)); + NodeList transformStmtNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, transformStmtPath, false)); + + assertEquals(1, febParamNodes.getLength()); + assertEquals(1, transformStmtNodes.getLength()); + } } \ No newline at end of file diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch.txt new file mode 100644 index 0000000..0d8aa3f --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch.txt @@ -0,0 +1,46 @@ + +| teragrep exec foreachbatch diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch_transformStatement.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch_transformStatement.txt new file mode 100644 index 0000000..02ccaf1 --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_foreachbatch_transformStatement.txt @@ -0,0 +1,46 @@ + +| teragrep exec foreachbatch | stats count(field) by anotherField