Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: bharath-techie <[email protected]>
  • Loading branch information
bharath-techie committed Nov 7, 2024
1 parent 63e90b0 commit df6a3a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.opensearch.index.codec.composite.CompositeIndexFieldInfo;
import org.opensearch.index.codec.composite.CompositeIndexReader;
import org.opensearch.index.codec.composite.LuceneDocValuesConsumerFactory;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeField;
import org.opensearch.index.compositeindex.datacube.startree.builder.StarTreesBuilder;
import org.opensearch.index.compositeindex.datacube.startree.index.CompositeIndexValues;
import org.opensearch.index.compositeindex.datacube.startree.index.StarTreeValues;
Expand Down Expand Up @@ -263,7 +262,9 @@ public SortedSetDocValues getSortedSet(FieldInfo field) {
return DocValues.emptySortedSet();
}
});
} else {
}
// TODO : change this logic to evaluate for sortedNumericField specifically
else {
fieldProducerMap.put(compositeField, new EmptyDocValuesProducer() {
@Override
public SortedNumericDocValues getSortedNumeric(FieldInfo field) {
Expand Down Expand Up @@ -302,7 +303,6 @@ private void mergeCompositeFields(MergeState mergeState) throws IOException {
*/
private void mergeStarTreeFields(MergeState mergeState) throws IOException {
Map<String, List<StarTreeValues>> starTreeSubsPerField = new HashMap<>();
StarTreeField starTreeField = null;
for (int i = 0; i < mergeState.docValuesProducers.length; i++) {
CompositeIndexReader reader = null;
if (mergeState.docValuesProducers[i] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DirectoryReader;
Expand Down Expand Up @@ -150,8 +151,9 @@ public void testStarTreeDocValuesWithDeletions() throws IOException {
Directory directory = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(null);
conf.setMergePolicy(newLogMergePolicy());
conf.setSoftDeletesField(Lucene.SOFT_DELETES_FIELD);
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
RandomIndexWriter iw = new RandomIndexWriter(random(), directory, conf);

int iterations = 3;
Map<String, Integer> map = new HashMap<>();
List<String> allIds = new ArrayList<>();
Expand All @@ -172,17 +174,25 @@ public void testStarTreeDocValuesWithDeletions() throws IOException {

doc.add(new SortedNumericDocValuesField("dv", dvValue));
map.put(sndvValue + "-" + dvValue, fieldValue + map.getOrDefault(sndvValue + "-" + dvValue, 0));
doc.add(new NumericDocValuesField("field-ndv", fieldValue));

iw.addDocument(doc);
}
iw.flush();
}
iw.commit();
// Delete random number of documents
// Update random number of documents
int docsToDelete = random().nextInt(9); // Delete up to 9 documents
for (int i = 0; i < docsToDelete; i++) {
if (!allIds.isEmpty()) {
String idToDelete = allIds.remove(random().nextInt(allIds.size() - 1));
iw.deleteDocuments(new Term("_id", idToDelete));
Document doc = new Document();
doc.add(new NumericDocValuesField("field-ndv", 1L));
iw.w.softUpdateDocuments(
new Term("_id", idToDelete),
List.of(doc),
new NumericDocValuesField(Lucene.SOFT_DELETES_FIELD, 1)
);
allIds.remove(idToDelete);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.document.StringField;
Expand Down Expand Up @@ -171,12 +172,18 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {

iw.flush();

// Delete random number of documents
// Update random number of documents
int docsToDelete = random().nextInt(5); // Delete up to 5 documents
for (int i = 0; i < docsToDelete; i++) {
if (!allIds.isEmpty()) {
String idToDelete = allIds.iterator().next();
iw.deleteDocuments(new Term("_id", idToDelete));
Document doc = new Document();
doc.add(new NumericDocValuesField("field-ndv", 1L));
iw.w.softUpdateDocuments(
new Term("_id", idToDelete),
List.of(doc),
new NumericDocValuesField(Lucene.SOFT_DELETES_FIELD, 1)
);
allIds.remove(idToDelete);
documents.remove(idToDelete);
}
Expand Down

0 comments on commit df6a3a7

Please sign in to comment.