diff --git a/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 b/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 index e45fdb0..5d05d18 100644 --- a/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 +++ b/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 @@ -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'); diff --git a/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 b/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 index 68341e3..4f8cf55 100644 --- a/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 +++ b/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 @@ -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 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 4b7c52e..636a95d 100644 --- a/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java +++ b/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java @@ -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"; @@ -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", diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_create_regex.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_create_regex.txt new file mode 100644 index 0000000..c2b51e3 --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_create_regex.txt @@ -0,0 +1,46 @@ + + | teragrep exec bloom create regex \w{4} \ No newline at end of file diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_create_table.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_create_table.txt new file mode 100644 index 0000000..0e29e8e --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_create_table.txt @@ -0,0 +1,46 @@ + + | teragrep exec bloom create table myTable \ No newline at end of file diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_update_regex.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_update_regex.txt new file mode 100644 index 0000000..904502d --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_update_regex.txt @@ -0,0 +1,46 @@ + + | teragrep exec bloom update regex \w{4} \ No newline at end of file diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_update_table.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_update_table.txt new file mode 100644 index 0000000..7539e3a --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_bloom_update_table.txt @@ -0,0 +1,46 @@ + + | teragrep exec bloom update table myTable \ No newline at end of file