Skip to content

Commit

Permalink
Fix issues with object type
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <jmazane@amazon.com>
  • Loading branch information
jmazanec15 committed Jan 29, 2025
1 parent c3483df commit 6e104f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,12 @@ public class NestedPerFieldDerivedVectorInjector implements PerFieldDerivedVecto
@Override
public void inject(int parentDocId, Map<String, Object> sourceAsMap) throws IOException {
// If the parent has the field, then it is just an object field.
if (getLowestDocIdForField(childFieldInfo.name, parentDocId) == parentDocId) {
int lowestDocIdForFieldWithParentAsOffset = getLowestDocIdForField(childFieldInfo.name, parentDocId);
if (lowestDocIdForFieldWithParentAsOffset == parentDocId) {
injectObject(parentDocId, sourceAsMap);
return;
}

if (ParentChildHelper.splitPath(childFieldInfo.name).length > 2) {
// We do not support nested fields beyond one level
log.warn("Nested fields beyond one level are not supported. Field: {}", childFieldInfo.name);
return;
}

// Setup the iterator. Return if no parent
String childFieldName = ParentChildHelper.getChildField(childFieldInfo.name);
String parentFieldName = ParentChildHelper.getParentField(childFieldInfo.name);
Expand All @@ -62,6 +57,10 @@ public void inject(int parentDocId, Map<String, Object> sourceAsMap) throws IOEx
parentDocId
);

if (nestedPerFieldParentToDocIdIterator.numChildren() == 0) {
return;
}

// Initializes the parent field so that there is a list to put each of the children
Object originalParentValue = sourceAsMap.get(parentFieldName);
List<Map<String, Object>> reconstructedSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public int childId() {
return children.get(currentChild);
}

/**
*
* @return the number of children for this parent
*/
public int numChildren() {
return children.size();
}

/**
* For parentDocId of this class, find the one just before it to be used for matching children.
*
Expand Down Expand Up @@ -122,6 +130,10 @@ private int previousParent() throws IOException {
* @throws IOException if there is an error reading the children
*/
private List<Integer> getChildren() throws IOException {
if (this.parentDocId - this.previousParentDocId <= 1) {
return Collections.emptyList();
}

// First, we need to get the currect PostingsEnum for the key as _nested_path and the value the actual parent
// path.
String childField = childFieldInfo.name;
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/opensearch/knn/integ/DerivedSourceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.Builder;
import lombok.Data;
import lombok.SneakyThrows;
import org.junit.Ignore;
import org.opensearch.common.CheckedConsumer;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
Expand All @@ -30,7 +29,7 @@
* Integration tests for derived source feature for vector fields. Currently, with derived source, there are
* a few gaps in functionality. Ignoring tests for now as feature is experimental.
*/
@Ignore
// @Ignore
public class DerivedSourceIT extends KNNRestTestCase {

private final static String NESTED_NAME = "test_nested";
Expand Down

0 comments on commit 6e104f2

Please sign in to comment.