Skip to content

Commit

Permalink
Add table name option to | teragrep exec bloom (#87)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
51-code authored Nov 14, 2024
1 parent 8699341 commit 7ea31c1
Show file tree
Hide file tree
Showing 7 changed files with 287 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 @@ -91,6 +91,7 @@ COMMAND_TERAGREP_MODE_ARCHIVE: 'archive';
COMMAND_TERAGREP_MODE_SUMMARY: 'summary' -> pushMode(DEFAULT_MODE);
COMMAND_TERAGREP_MODE_RETENTION: 'retention=' -> pushMode(GET_SPAN);
COMMAND_TERAGREP_MODE_CODEC: 'codec=' -> pushMode(GET_STRING);
COMMAND_TERAGREP_MODE_TABLE: 'table' -> pushMode(GET_FIELD);

COMMAND_TERAGREP_MODE_HDFS_FORMAT: 'format=';
COMMAND_TERAGREP_MODE_CSV_FORMAT: ('csv'|'CSV');
Expand Down
6 changes: 5 additions & 1 deletion src/main/antlr4/imports/DPLParserTransform_teragrep.g4
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ t_getArchiveSummaryParameter
;

t_bloomOptionParameter
: COMMAND_TERAGREP_MODE_UPDATE t_estimatesParameter? t_inputParameter? | COMMAND_TERAGREP_MODE_CREATE t_estimatesParameter? t_inputParameter? | COMMAND_TERAGREP_MODE_ESTIMATE t_inputParameter? t_outputParameter?
: 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?
;

t_tableParameter
: COMMAND_TERAGREP_MODE_TABLE fieldType
;

t_hostParameter
Expand Down
98 changes: 97 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 @@ -79,7 +79,11 @@ public class TeragrepSyntaxTests {
"teragrep_foreachbatch",
"teragrep_foreachbatch_transformStatement",
"teragrep_config_set",
"teragrep_config_get"
"teragrep_config_get",
"teragrep_bloom_create_table",
"teragrep_bloom_update_table",
"teragrep_bloom_create_regex",
"teragrep_bloom_update_regex"
})
public void teragrepSyntaxParseTest(String arg) {
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
Expand Down Expand Up @@ -362,6 +366,98 @@ void testHdfsSaveAllParameters(String arg) {
assertEquals(1, pathNodes.getLength());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_bloom_create_table"
})
void testBloomCreateTableName(String arg) {
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
String tableParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter";
String tableNamePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter/fieldType/value";
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";

NodeList tableParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableParamPath, false));
NodeList tableNameNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableNamePath, false));
NodeList createNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));

assertEquals(1, tableParamNodes.getLength());
assertEquals(1, tableNameNodes.getLength());
assertEquals(1, createNodes.getLength());

assertEquals("myTable", tableNameNodes.item(0).getTextContent());
assertEquals("create", createNodes.item(0).getTextContent());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_bloom_update_table"
})
void testBloomUpdateTableName(String arg) {
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
String tableParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter";
String tableNamePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_tableParameter/fieldType/value";
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";

NodeList tableParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableParamPath, false));
NodeList tableNameNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, tableNamePath, false));
NodeList updateNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));

assertEquals(1, tableParamNodes.getLength());
assertEquals(1, tableNameNodes.getLength());
assertEquals(1, updateNodes.getLength());

assertEquals("myTable", tableNameNodes.item(0).getTextContent());
assertEquals("update", updateNodes.item(0).getTextContent());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_bloom_create_regex"
})
void testBloomCreateRegex(String arg) {
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
String regexParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter";
String regexPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter/stringType/value";
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";

NodeList regexParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexParamPath, false));
NodeList regexNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexPath, false));
NodeList createNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));

assertEquals(1, regexParamNodes.getLength());
assertEquals(1, regexNodes.getLength());
assertEquals(1, createNodes.getLength());

assertEquals("\\w{4}", regexNodes.item(0).getTextContent());
assertEquals("create", createNodes.item(0).getTextContent());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_bloom_update_regex"
})
void testBloomUpdateRegex(String arg) {
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
String regexParamPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter";
String regexPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/t_regexParameter/stringType/value";
String optionModePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_bloomModeParameter/t_bloomOptionParameter/value";

NodeList regexParamNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexParamPath, false));
NodeList regexNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexPath, false));
NodeList updateNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, optionModePath, false));

assertEquals(1, regexParamNodes.getLength());
assertEquals(1, regexNodes.getLength());
assertEquals(1, updateNodes.getLength());

assertEquals("\\w{4}", regexNodes.item(0).getTextContent());
assertEquals("update", updateNodes.item(0).getTextContent());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_regexextract",
Expand Down
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 bloom create regex \w{4}
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 bloom create table myTable
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 bloom update regex \w{4}
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 bloom update table myTable

0 comments on commit 7ea31c1

Please sign in to comment.