Skip to content

Commit

Permalink
add '| teragrep exec foreachbatch' with tests (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemhu authored Oct 23, 2024
1 parent 840f155 commit 42ae75f
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 6 additions & 1 deletion src/main/antlr4/imports/DPLParserTransform_teragrep.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- /*
* Teragrep Data Processing Language Parser Library PTH-03
* Copyright (C) 2019, 2020, 2021, 2022, 2023 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
*
*
* Additional permission under GNU Affero General Public License version 3
* section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with other code, such other code is not for that reason alone subject to any
* of the requirements of the GNU Affero GPL version 3 as long as this Program
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
* modifications.
*
* Supplemented terms under GNU Affero General Public License version 3
* section 7
*
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
* versions must be marked as "Modified version of" The Program.
*
* Names of the licensors and authors may not be used for publicity purposes.
*
* No rights are granted for use of trade names, trademarks, or service marks
* which are in The Program if any.
*
* Licensee must indemnify licensors and authors for any liability that these
* contractual assumptions impose on licensors and authors.
*
* To the extent this program is licensed as part of the Commercial versions of
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/ -->
| teragrep exec foreachbatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- /*
* Teragrep Data Processing Language Parser Library PTH-03
* Copyright (C) 2019, 2020, 2021, 2022, 2023 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
*
*
* Additional permission under GNU Affero General Public License version 3
* section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with other code, such other code is not for that reason alone subject to any
* of the requirements of the GNU Affero GPL version 3 as long as this Program
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
* modifications.
*
* Supplemented terms under GNU Affero General Public License version 3
* section 7
*
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
* versions must be marked as "Modified version of" The Program.
*
* Names of the licensors and authors may not be used for publicity purposes.
*
* No rights are granted for use of trade names, trademarks, or service marks
* which are in The Program if any.
*
* Licensee must indemnify licensors and authors for any liability that these
* contractual assumptions impose on licensors and authors.
*
* To the extent this program is licensed as part of the Commercial versions of
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/ -->
| teragrep exec foreachbatch | stats count(field) by anotherField

0 comments on commit 42ae75f

Please sign in to comment.