From 56543e56695e943d98b25e920d21bbf9d20cf0bd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 15 Dec 2023 14:09:44 +0000 Subject: [PATCH] accessors for custom compression modes (#89) Signed-off-by: Sarthak Aggarwal (cherry picked from commit 804fe117f3251278ace9251f3ccb10474a0e5f4b) Signed-off-by: github-actions[bot] --- .../Lucene95CustomStoredFieldsFormat.java | 13 +++++++++---- .../Lucene95CustomStoredFieldsFormatTests.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormat.java b/src/main/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormat.java index 79d9703..512df54 100644 --- a/src/main/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormat.java +++ b/src/main/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormat.java @@ -27,9 +27,9 @@ public class Lucene95CustomStoredFieldsFormat extends StoredFieldsFormat { /** A key that we use to map to a mode */ public static final String MODE_KEY = Lucene95CustomStoredFieldsFormat.class.getSimpleName() + ".mode"; - private static final int ZSTD_BLOCK_LENGTH = 10 * 48 * 1024; - private static final int ZSTD_MAX_DOCS_PER_BLOCK = 4096; - private static final int ZSTD_BLOCK_SHIFT = 10; + protected static final int ZSTD_BLOCK_LENGTH = 10 * 48 * 1024; + protected static final int ZSTD_MAX_DOCS_PER_BLOCK = 4096; + protected static final int ZSTD_BLOCK_SHIFT = 10; private final CompressionMode zstdCompressionMode; private final CompressionMode zstdNoDictCompressionMode; @@ -122,7 +122,7 @@ StoredFieldsFormat impl(Lucene95CustomCodec.Mode mode) { } } - Lucene95CustomCodec.Mode getMode() { + public Lucene95CustomCodec.Mode getMode() { return mode; } @@ -132,4 +132,9 @@ Lucene95CustomCodec.Mode getMode() { public int getCompressionLevel() { return compressionLevel; } + + public CompressionMode getCompressionMode() { + return mode == Lucene95CustomCodec.Mode.ZSTD_NO_DICT ? zstdNoDictCompressionMode : zstdCompressionMode; + } + } diff --git a/src/test/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormatTests.java b/src/test/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormatTests.java index e87fb56..e669b7f 100644 --- a/src/test/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormatTests.java +++ b/src/test/java/org/opensearch/index/codec/customcodecs/Lucene95CustomStoredFieldsFormatTests.java @@ -44,4 +44,14 @@ public void testZstdNoDictLucene95CustomCodecModeWithCompressionLevel() { assertEquals(randomCompressionLevel, lucene95CustomStoredFieldsFormat.getCompressionLevel()); } + public void testCompressionModes(){ + Lucene95CustomStoredFieldsFormat lucene95CustomStoredFieldsFormat = new Lucene95CustomStoredFieldsFormat(); + assertTrue(lucene95CustomStoredFieldsFormat.getCompressionMode() instanceof ZstdCompressionMode); + } + + public void testZstdNoDictCompressionModes(){ + Lucene95CustomStoredFieldsFormat lucene95CustomStoredFieldsFormat = new Lucene95CustomStoredFieldsFormat(Lucene95CustomCodec.Mode.ZSTD_NO_DICT); + assertTrue(lucene95CustomStoredFieldsFormat.getCompressionMode() instanceof ZstdNoDictCompressionMode); + } + }