Skip to content

Commit 42ae75f

Browse files
authored
add '| teragrep exec foreachbatch' with tests (#85)
1 parent 840f155 commit 42ae75f

5 files changed

Lines changed: 134 additions & 2 deletions

File tree

src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ COMMAND_TERAGREP_MODE_PORT: 'port' -> pushMode(COMMAND_TERAGREP_IP_MODE);
8080
COMMAND_TERAGREP_MODE_DOT: '.';
8181
COMMAND_TERAGREP_MODE_TOKENIZER: 'tokenizer';
8282
COMMAND_TERAGREP_MODE_REGEXEXTRACT: 'regexextract';
83+
COMMAND_TERAGREP_MODE_FOREACHBATCH: 'foreachbatch';
8384
COMMAND_TERAGREP_MODE_SYSLOG: 'syslog';
8485
COMMAND_TERAGREP_MODE_STREAM: 'stream';
8586
COMMAND_TERAGREP_MODE_LOAD: 'load';

src/main/antlr4/imports/DPLParserTransform_teragrep.g4

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ t_execParameter
6060
| t_bloomModeParameter
6161
| t_tokenizerParameter
6262
| t_regexextractParameter
63-
| t_dynatraceParameter)
63+
| t_dynatraceParameter
64+
| t_forEachBatchParameter)
65+
;
66+
67+
t_forEachBatchParameter
68+
: COMMAND_TERAGREP_MODE_FOREACHBATCH
6469
;
6570

6671
t_dynatraceParameter

src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public class TeragrepSyntaxTests {
7575
"teragrep_hdfs_save_all_params",
7676
"teragrep_hdfs_save_codec",
7777
"teragrep_syslog_stream",
78-
"teragrep_syslog_stream_host_port"
78+
"teragrep_syslog_stream_host_port",
79+
"teragrep_foreachbatch",
80+
"teragrep_foreachbatch_transformStatement"
7981
})
8082
public void teragrepSyntaxParseTest(String arg) {
8183
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
@@ -393,4 +395,36 @@ void testRegexExtractWithParams(String arg) {
393395
assertEquals(1, inputNodes.getLength());
394396
assertEquals(1, outputNodes.getLength());
395397
}
398+
399+
@ParameterizedTest
400+
@ValueSource(strings = {
401+
"teragrep_foreachbatch",
402+
})
403+
void testTeragrepForEachBatch(String arg) {
404+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
405+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
406+
407+
String febParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_forEachBatchParameter";
408+
NodeList febParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, febParamPath, false));
409+
410+
// Check that 1 found for each path
411+
assertEquals(1, febParamNodes.getLength());
412+
}
413+
414+
@ParameterizedTest
415+
@ValueSource(strings = {
416+
"teragrep_foreachbatch_transformStatement",
417+
})
418+
void testTeragrepForEachBatchWithTransformStatement(String arg) {
419+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
420+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
421+
422+
String febParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_forEachBatchParameter";
423+
String transformStmtPath = "/root/transformStatement/transformStatement/statsTransformation";
424+
NodeList febParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, febParamPath, false));
425+
NodeList transformStmtNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, transformStmtPath, false));
426+
427+
assertEquals(1, febParamNodes.getLength());
428+
assertEquals(1, transformStmtNodes.getLength());
429+
}
396430
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- /*
2+
* Teragrep Data Processing Language Parser Library PTH-03
3+
* Copyright (C) 2019, 2020, 2021, 2022, 2023 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/ -->
46+
| teragrep exec foreachbatch
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- /*
2+
* Teragrep Data Processing Language Parser Library PTH-03
3+
* Copyright (C) 2019, 2020, 2021, 2022, 2023 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/ -->
46+
| teragrep exec foreachbatch | stats count(field) by anotherField

0 commit comments

Comments
 (0)