Skip to content

Commit 7ea31c1

Browse files
authored
Add table name option to | teragrep exec bloom (#87)
* Add table name option to | teragrep exec bloom Fix typo in bloomOptionParameter Add table name option to | teragrep exec bloom * Add regex parameter to | teragrep exec bloom
1 parent 8699341 commit 7ea31c1

7 files changed

Lines changed: 287 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
@@ -91,6 +91,7 @@ COMMAND_TERAGREP_MODE_ARCHIVE: 'archive';
9191
COMMAND_TERAGREP_MODE_SUMMARY: 'summary' -> pushMode(DEFAULT_MODE);
9292
COMMAND_TERAGREP_MODE_RETENTION: 'retention=' -> pushMode(GET_SPAN);
9393
COMMAND_TERAGREP_MODE_CODEC: 'codec=' -> pushMode(GET_STRING);
94+
COMMAND_TERAGREP_MODE_TABLE: 'table' -> pushMode(GET_FIELD);
9495

9596
COMMAND_TERAGREP_MODE_HDFS_FORMAT: 'format=';
9697
COMMAND_TERAGREP_MODE_CSV_FORMAT: ('csv'|'CSV');

src/main/antlr4/imports/DPLParserTransform_teragrep.g4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ t_getArchiveSummaryParameter
161161
;
162162

163163
t_bloomOptionParameter
164-
: COMMAND_TERAGREP_MODE_UPDATE t_estimatesParameter? t_inputParameter? | COMMAND_TERAGREP_MODE_CREATE t_estimatesParameter? t_inputParameter? | COMMAND_TERAGREP_MODE_ESTIMATE t_inputParameter? t_outputParameter?
164+
: COMMAND_TERAGREP_MODE_UPDATE t_tableParameter? t_regexParameter? t_estimatesParameter? t_inputParameter? | COMMAND_TERAGREP_MODE_CREATE t_tableParameter? t_regexParameter? t_estimatesParameter? t_inputParameter? | COMMAND_TERAGREP_MODE_ESTIMATE t_inputParameter? t_outputParameter?
165+
;
166+
167+
t_tableParameter
168+
: COMMAND_TERAGREP_MODE_TABLE fieldType
165169
;
166170

167171
t_hostParameter

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

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public class TeragrepSyntaxTests {
7979
"teragrep_foreachbatch",
8080
"teragrep_foreachbatch_transformStatement",
8181
"teragrep_config_set",
82-
"teragrep_config_get"
82+
"teragrep_config_get",
83+
"teragrep_bloom_create_table",
84+
"teragrep_bloom_update_table",
85+
"teragrep_bloom_create_regex",
86+
"teragrep_bloom_update_regex"
8387
})
8488
public void teragrepSyntaxParseTest(String arg) {
8589
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
@@ -362,6 +366,98 @@ void testHdfsSaveAllParameters(String arg) {
362366
assertEquals(1, pathNodes.getLength());
363367
}
364368

369+
@ParameterizedTest
370+
@ValueSource(strings = {
371+
"teragrep_bloom_create_table"
372+
})
373+
void testBloomCreateTableName(String arg) {
374+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
375+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
376+
String tableParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter";
377+
String tableNamePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter/fieldType/value";
378+
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";
379+
380+
NodeList tableParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableParamPath, false));
381+
NodeList tableNameNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableNamePath, false));
382+
NodeList createNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));
383+
384+
assertEquals(1, tableParamNodes.getLength());
385+
assertEquals(1, tableNameNodes.getLength());
386+
assertEquals(1, createNodes.getLength());
387+
388+
assertEquals("myTable", tableNameNodes.item(0).getTextContent());
389+
assertEquals("create", createNodes.item(0).getTextContent());
390+
}
391+
392+
@ParameterizedTest
393+
@ValueSource(strings = {
394+
"teragrep_bloom_update_table"
395+
})
396+
void testBloomUpdateTableName(String arg) {
397+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
398+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
399+
String tableParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter";
400+
String tableNamePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter/fieldType/value";
401+
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";
402+
403+
NodeList tableParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableParamPath, false));
404+
NodeList tableNameNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableNamePath, false));
405+
NodeList updateNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));
406+
407+
assertEquals(1, tableParamNodes.getLength());
408+
assertEquals(1, tableNameNodes.getLength());
409+
assertEquals(1, updateNodes.getLength());
410+
411+
assertEquals("myTable", tableNameNodes.item(0).getTextContent());
412+
assertEquals("update", updateNodes.item(0).getTextContent());
413+
}
414+
415+
@ParameterizedTest
416+
@ValueSource(strings = {
417+
"teragrep_bloom_create_regex"
418+
})
419+
void testBloomCreateRegex(String arg) {
420+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
421+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
422+
String regexParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter";
423+
String regexPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter/stringType/value";
424+
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";
425+
426+
NodeList regexParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexParamPath, false));
427+
NodeList regexNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexPath, false));
428+
NodeList createNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));
429+
430+
assertEquals(1, regexParamNodes.getLength());
431+
assertEquals(1, regexNodes.getLength());
432+
assertEquals(1, createNodes.getLength());
433+
434+
assertEquals("\\w{4}", regexNodes.item(0).getTextContent());
435+
assertEquals("create", createNodes.item(0).getTextContent());
436+
}
437+
438+
@ParameterizedTest
439+
@ValueSource(strings = {
440+
"teragrep_bloom_update_regex"
441+
})
442+
void testBloomUpdateRegex(String arg) {
443+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
444+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
445+
String regexParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter";
446+
String regexPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter/stringType/value";
447+
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";
448+
449+
NodeList regexParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexParamPath, false));
450+
NodeList regexNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexPath, false));
451+
NodeList updateNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));
452+
453+
assertEquals(1, regexParamNodes.getLength());
454+
assertEquals(1, regexNodes.getLength());
455+
assertEquals(1, updateNodes.getLength());
456+
457+
assertEquals("\\w{4}", regexNodes.item(0).getTextContent());
458+
assertEquals("update", updateNodes.item(0).getTextContent());
459+
}
460+
365461
@ParameterizedTest
366462
@ValueSource(strings = {
367463
"teragrep_regexextract",
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 bloom create regex \w{4}
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 bloom create table myTable
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 bloom update regex \w{4}
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 bloom update table myTable

0 commit comments

Comments
 (0)