Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Aug 28, 2024
1 parent a0200b2 commit 11895f1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
}

/**
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,14 +807,6 @@ public static int randomInt() {
return random().nextInt();
}

/**
* @return a <code>int</code> between <code>0</code> and <code>Integer.MAX_VALUE</code> (inclusive) chosen uniformly at random.
*/
public static int randomNonNegativeInt() {
int randomInt = randomInt();
return randomInt == Integer.MIN_VALUE ? 0 : Math.abs(randomInt);
}

/**
* @return a <code>long</code> between <code>0</code> and <code>Long.MAX_VALUE</code> (inclusive) chosen uniformly at random.
*/
Expand Down

0 comments on commit 11895f1

Please sign in to comment.