Skip to content

Commit

Permalink
Add codec parameter to hdfs save command (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
51-code authored Aug 28, 2024
1 parent 1983e46 commit db2055c
Show file tree
Hide file tree
Showing 5 changed files with 153 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 @@ -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');
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 @@ -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
Expand Down Expand Up @@ -172,3 +172,7 @@ t_schemaParameter
t_retentionParameter
: COMMAND_TERAGREP_MODE_RETENTION spanType
;

t_codecParameter
: COMMAND_TERAGREP_MODE_CODEC stringType
;
56 changes: 55 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 @@ -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;
Expand All @@ -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"
})
Expand Down Expand Up @@ -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());
}
}
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 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 hdfs save path/path retention=1h overwrite=false format=avro header=true codec=plain
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 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 hdfs save codec=lz4

0 comments on commit db2055c

Please sign in to comment.