From 11895f16893c3cefe871df04233b3899095397f6 Mon Sep 17 00:00:00 2001 From: Sarthak Aggarwal Date: Wed, 28 Aug 2024 18:06:12 +0530 Subject: [PATCH] addressing comments Signed-off-by: Sarthak Aggarwal --- .../datacube/ReadDimension.java | 2 +- .../fileformats/meta/StarTreeMetaWriter.java | 22 +++++++------------ .../fileformats/meta/StarTreeMetaTests.java | 6 ++--- .../index/mapper/StarTreeMapperTests.java | 3 +++ .../opensearch/test/OpenSearchTestCase.java | 8 ------- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java b/server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java index 3b6a02967f384..4264ec87d2c74 100644 --- a/server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java +++ b/server/src/main/java/org/opensearch/index/compositeindex/datacube/ReadDimension.java @@ -15,7 +15,7 @@ import java.util.Objects; /** - * Composite index merge dimension class + * Represents a dimension for reconstructing StarTreeField from file formats during searches and merges. * * @opensearch.experimental */ diff --git a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaWriter.java b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaWriter.java index 112e47d50fde6..9c07bae77c836 100644 --- a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaWriter.java +++ b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaWriter.java @@ -57,7 +57,7 @@ public static void writeStarTreeMetadata( long initialMetaFilePointer = metaOut.getFilePointer(); - writeMetaHeader(metaOut, CompositeMappedFieldType.CompositeFieldType.STAR_TREE, starTreeField.getName()); + writeMetaHeader(metaOut); writeMeta(metaOut, metricAggregatorInfos, starTreeField, numNodes, segmentAggregatedCount, dataFilePointer, dataFileLength); logger.debug( @@ -71,26 +71,14 @@ public static void writeStarTreeMetadata( * Writes the star-tree metadata header. * * @param metaOut the IndexOutput to write the header - * @param compositeFieldType the composite field type of the star-tree field - * @param starTreeFieldName the name of the star-tree field * @throws IOException if an I/O error occurs while writing the header */ - private static void writeMetaHeader( - IndexOutput metaOut, - CompositeMappedFieldType.CompositeFieldType compositeFieldType, - String starTreeFieldName - ) throws IOException { + private static void writeMetaHeader(IndexOutput metaOut) throws IOException { // magic marker for sanity metaOut.writeLong(COMPOSITE_FIELD_MARKER); // version metaOut.writeVInt(VERSION_CURRENT); - - // star tree field name - metaOut.writeString(starTreeFieldName); - - // star tree field type - metaOut.writeString(compositeFieldType.getName()); } /** @@ -115,6 +103,12 @@ private static void writeMeta( long dataFileLength ) throws IOException { + // star tree field name + metaOut.writeString(starTreeField.getName()); + + // star tree field type + metaOut.writeString(CompositeMappedFieldType.CompositeFieldType.STAR_TREE.getName()); + // number of nodes metaOut.writeInt(numNodes); diff --git a/server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaTests.java b/server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaTests.java index 74d9244e16010..c312fdc4b784c 100644 --- a/server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaTests.java +++ b/server/src/test/java/org/opensearch/index/compositeindex/datacube/startree/fileformats/meta/StarTreeMetaTests.java @@ -122,7 +122,7 @@ public void test_starTreeMetadata() throws IOException { new Metric("field4", List.of(MetricStat.SUM)), new Metric("field6", List.of(MetricStat.VALUE_COUNT)) ); - int maxLeafDocs = randomNonNegativeInt(); + int maxLeafDocs = randomInt(Integer.MAX_VALUE); StarTreeFieldConfiguration starTreeFieldConfiguration = new StarTreeFieldConfiguration( maxLeafDocs, Set.of("field10"), @@ -144,10 +144,10 @@ public void test_starTreeMetadata() throws IOException { dataFileLength = randomNonNegativeLong(); dataFilePointer = randomNonNegativeLong(); - segmentDocumentCount = randomNonNegativeInt(); + segmentDocumentCount = randomInt(Integer.MAX_VALUE); metaOut = directory.createOutput("star-tree-metadata", IOContext.DEFAULT); StarTreeWriter starTreeWriter = new StarTreeWriter(); - int numberOfNodes = randomNonNegativeInt(); + int numberOfNodes = randomInt(Integer.MAX_VALUE); starTreeWriter.writeStarTreeMetadata( metaOut, starTreeField, diff --git a/server/src/test/java/org/opensearch/index/mapper/StarTreeMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/StarTreeMapperTests.java index b0145dbde4bee..81454b210d6be 100644 --- a/server/src/test/java/org/opensearch/index/mapper/StarTreeMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/StarTreeMapperTests.java @@ -333,6 +333,9 @@ public void testDimensions() { assertEquals(n1, n2); n2 = new NumericDimension("name1"); assertNotEquals(n1, n2); + } + + public void testReadDimensions() { ReadDimension r1 = new ReadDimension("name"); ReadDimension r2 = new ReadDimension("name"); assertEquals(r1, r2); diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java index 1b740476f89c3..6afc7c23d9e66 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java @@ -807,14 +807,6 @@ public static int randomInt() { return random().nextInt(); } - /** - * @return a int between 0 and Integer.MAX_VALUE (inclusive) chosen uniformly at random. - */ - public static int randomNonNegativeInt() { - int randomInt = randomInt(); - return randomInt == Integer.MIN_VALUE ? 0 : Math.abs(randomInt); - } - /** * @return a long between 0 and Long.MAX_VALUE (inclusive) chosen uniformly at random. */