diff --git a/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 b/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 index 3bcfe0f..50addc6 100644 --- a/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 +++ b/src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4 @@ -87,6 +87,7 @@ COMMAND_TERAGREP_MODE_VERSION: 'version'; 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_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 1b14e92..288f226 100644 --- a/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 +++ b/src/main/antlr4/imports/DPLParserTransform_teragrep.g4 @@ -107,7 +107,7 @@ t_loadModeParameter ; t_saveModeParameter - : COMMAND_TERAGREP_MODE_HDFS COMMAND_TERAGREP_MODE_SAVE (t_pathParameter|t_retentionParameter|t_overwriteParameter|t_hdfsFormatParameter|t_headerParameter)* + : COMMAND_TERAGREP_MODE_HDFS COMMAND_TERAGREP_MODE_SAVE (t_codecParameter|t_pathParameter|t_retentionParameter|t_overwriteParameter|t_hdfsFormatParameter|t_headerParameter)* ; t_deleteModeParameter @@ -172,3 +172,7 @@ t_schemaParameter t_retentionParameter : COMMAND_TERAGREP_MODE_RETENTION spanType ; + +t_codecParameter + : COMMAND_TERAGREP_MODE_CODEC stringType + ; \ No newline at end of file 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 f537fed..6517ee6 100644 --- a/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java +++ b/src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java @@ -48,6 +48,7 @@ import com.teragrep.pth_03.ParserStructureTestingUtility; import com.teragrep.pth_03.ParserSyntaxTestingUtility; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.w3c.dom.NodeList; @@ -72,6 +73,8 @@ public class TeragrepSyntaxTests { "teragrep_csv_schema", "teragrep_csv_header", "teragrep_archive_summary", + "teragrep_hdfs_save_all_params", + "teragrep_hdfs_save_codec", "teragrep_syslog_stream", "teragrep_syslog_stream_host_port" }) @@ -304,4 +307,55 @@ void syslogStreamWithHostAndPortTest(String arg) { // includes an eval command i assertEquals(1,portNodes.getLength()); assertEquals(1,evalNodes.getLength()); } -} + + @ParameterizedTest + @ValueSource(strings = { + "teragrep_hdfs_save_codec", + }) + void testHdfsSaveCompression(String arg) { + ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); + String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt"; + String hdfsSavePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter"; + String codecPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_codecParameter"; + + NodeList saveNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, hdfsSavePath, false)); + NodeList codecNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, codecPath, false)); + + // Check that 1 found + assertEquals(1, saveNodes.getLength()); + assertEquals(1, codecNodes.getLength()); + } + + @ParameterizedTest + @ValueSource(strings = { + "teragrep_hdfs_save_all_params", + }) + void testHdfsSaveAllParameters(String arg) { + ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); + String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt"; + String hdfsSavePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter"; + String codecPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_codecParameter"; + String retentionPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_retentionParameter"; + String overwritePath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_overwriteParameter"; + String formatPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_hdfsFormatParameter"; + String headerPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_headerParameter"; + String pathPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_saveModeParameter/t_pathParameter"; + + NodeList saveNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, hdfsSavePath, false)); + NodeList codecNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, codecPath, false)); + NodeList retentionNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, retentionPath, false)); + NodeList overwriteNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, overwritePath, false)); + NodeList formatNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, formatPath, false)); + NodeList headerNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, headerPath, false)); + NodeList pathNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, pathPath, false)); + + // Check that 1 found + assertEquals(1, saveNodes.getLength()); + assertEquals(1, codecNodes.getLength()); + assertEquals(1, retentionNodes.getLength()); + assertEquals(1, overwriteNodes.getLength()); + assertEquals(1, formatNodes.getLength()); + assertEquals(1, headerNodes.getLength()); + assertEquals(1, pathNodes.getLength()); + } +} \ No newline at end of file diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_hdfs_save_all_params.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_hdfs_save_all_params.txt new file mode 100644 index 0000000..d6ec22a --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_hdfs_save_all_params.txt @@ -0,0 +1,46 @@ + +| teragrep exec hdfs save path/path retention=1h overwrite=false format=avro header=true codec=plain \ No newline at end of file diff --git a/src/test/resources/antlr4/commands/teragrep/teragrep_hdfs_save_codec.txt b/src/test/resources/antlr4/commands/teragrep/teragrep_hdfs_save_codec.txt new file mode 100644 index 0000000..35a0d1c --- /dev/null +++ b/src/test/resources/antlr4/commands/teragrep/teragrep_hdfs_save_codec.txt @@ -0,0 +1,46 @@ + +| teragrep exec hdfs save codec=lz4 \ No newline at end of file