Skip to content

Commit

Permalink
Fixed compilation errors after recent changes in core (#1031)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
  • Loading branch information
martin-gaievski authored Aug 8, 2023
1 parent 0d97aba commit 0a7fc4e
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.knn.bwc;

import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.knn.index.SpaceType;

Expand Down Expand Up @@ -96,21 +95,20 @@ public void testKNNIndexCustomMethodFieldMapping() throws Exception {
// test null parameters
public void testNullParametersOnUpgrade() throws Exception {
if (isRunningAgainstOldCluster()) {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, String.valueOf(DIMENSIONS))
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.field(PARAMETERS, (String) null)
.endObject()
.endObject()
.endObject()
.endObject()
);
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, String.valueOf(DIMENSIONS))
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.field(PARAMETERS, (String) null)
.endObject()
.endObject()
.endObject()
.endObject()
.toString();

createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);
} else {
Expand All @@ -121,21 +119,20 @@ public void testNullParametersOnUpgrade() throws Exception {
// test empty parameters
public void testEmptyParametersOnUpgrade() throws Exception {
if (isRunningAgainstOldCluster()) {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, String.valueOf(DIMENSIONS))
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.field(PARAMETERS, "")
.endObject()
.endObject()
.endObject()
.endObject()
);
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, String.valueOf(DIMENSIONS))
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.field(PARAMETERS, "")
.endObject()
.endObject()
.endObject()
.endObject()
.toString();

createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);
} else {
Expand All @@ -146,20 +143,19 @@ public void testEmptyParametersOnUpgrade() throws Exception {
// test no parameters
public void testNoParametersOnUpgrade() throws Exception {
if (isRunningAgainstOldCluster()) {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, String.valueOf(DIMENSIONS))
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.endObject()
.endObject()
.endObject()
.endObject()
);
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(TEST_FIELD)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(DIMENSION, String.valueOf(DIMENSIONS))
.startObject(KNN_METHOD)
.field(NAME, METHOD_HNSW)
.endObject()
.endObject()
.endObject()
.endObject()
.toString();

createKnnIndex(testIndex, getKNNDefaultIndexSettings(), mapping);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.common.Strings;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.xcontent.XContentParser;
Expand Down Expand Up @@ -245,17 +244,16 @@ public void trainKNNModelDefault(String modelId, String trainingIndexName, Strin

// mapping to create index from model
public String modelIndexMapping(String fieldName, String modelId) throws IOException {
return Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(fieldName)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(MODEL_ID, modelId)
.endObject()
.endObject()
.endObject()
);
return XContentFactory.jsonBuilder()
.startObject()
.startObject(PROPERTIES)
.startObject(fieldName)
.field(VECTOR_TYPE, KNN_VECTOR)
.field(MODEL_ID, modelId)
.endObject()
.endObject()
.endObject()
.toString();
}

private ModelMetadata getModelMetadata() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.apache.lucene.document.FieldType;
import org.opensearch.common.Explicit;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.knn.index.KNNMethodContext;
import org.opensearch.knn.index.util.KNNEngine;
Expand Down Expand Up @@ -50,7 +49,7 @@ public class MethodFieldMapper extends KNNVectorFieldMapper {
try {
this.fieldType.putAttribute(
PARAMETERS,
Strings.toString(XContentFactory.jsonBuilder().map(knnEngine.getMethodAsMap(knnMethodContext)))
XContentFactory.jsonBuilder().map(knnEngine.getMethodAsMap(knnMethodContext)).toString()
);
} catch (IOException ioe) {
throw new RuntimeException(String.format("Unable to create KNNVectorFieldMapper: %s", ioe));
Expand Down
30 changes: 14 additions & 16 deletions src/test/java/org/opensearch/knn/index/FaissIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.knn.KNNRestTestCase;
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.knn.KNNResult;
import org.opensearch.knn.TestUtils;
Expand Down Expand Up @@ -98,7 +97,7 @@ public void testEndToEnd_fromMethod() throws Exception {
.endObject();

Map<String, Object> mappingMap = xContentBuilderToMap(builder);
String mapping = Strings.toString(builder);
String mapping = builder.toString();

createKnnIndex(indexName, mapping);
assertEquals(new TreeMap<>(mappingMap), new TreeMap<>(getIndexMappingAsMap(indexName)));
Expand Down Expand Up @@ -175,7 +174,7 @@ public void testDocUpdate() throws IOException {
.endObject()
.endObject();

String mapping = Strings.toString(builder);
String mapping = builder.toString();
createKnnIndex(indexName, mapping);

Float[] vector = { 6.0f, 6.0f };
Expand Down Expand Up @@ -211,7 +210,7 @@ public void testDocDeletion() throws IOException {
.endObject()
.endObject();

String mapping = Strings.toString(builder);
String mapping = builder.toString();
createKnnIndex(indexName, mapping);

Float[] vector = { 6.0f, 6.0f };
Expand Down Expand Up @@ -255,17 +254,16 @@ public void testKNNQuery_withModelDifferentCombination_thenSuccess() {
// Create knn index from model
String fieldName = "test-field-name";
String indexName = "test-index-name";
String indexMapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(fieldName)
.field("type", "knn_vector")
.field(MODEL_ID, modelId)
.endObject()
.endObject()
.endObject()
);
String indexMapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(fieldName)
.field("type", "knn_vector")
.field(MODEL_ID, modelId)
.endObject()
.endObject()
.endObject()
.toString();

createKnnIndex(indexName, getKNNDefaultIndexSettings(), indexMapping);

Expand Down Expand Up @@ -389,7 +387,7 @@ protected void setupKNNIndexForFilterQuery() throws Exception {
.endObject()
.endObject()
.endObject();
final String mapping = Strings.toString(builder);
final String mapping = builder.toString();

createKnnIndex(INDEX_NAME, mapping);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.google.common.collect.ImmutableMap;
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.knn.KNNSingleNodeTestCase;
Expand Down Expand Up @@ -75,17 +74,16 @@ public void testCreateIndexFromModel() throws IOException, InterruptedException
String indexName = "test-index";
String fieldName = "test-field";

final String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(fieldName)
.field("type", "knn_vector")
.field("model_id", modelId)
.endObject()
.endObject()
.endObject()
);
final String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(fieldName)
.field("type", "knn_vector")
.field("model_id", modelId)
.endObject()
.endObject()
.endObject()
.toString();

modelDao.put(model, ActionListener.wrap(indexResponse -> {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin()
Expand Down
11 changes: 5 additions & 6 deletions src/test/java/org/opensearch/knn/index/LuceneEngineIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.common.Strings;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.index.query.QueryBuilders;
Expand Down Expand Up @@ -101,7 +100,7 @@ public void testQuery_innerProduct_notSupported() throws Exception {
.endObject()
.endObject();

String mapping = Strings.toString(builder);
String mapping = builder.toString();

createIndex(INDEX_NAME, getKNNDefaultIndexSettings());

Expand Down Expand Up @@ -179,7 +178,7 @@ public void testQuery_multipleEngines() throws Exception {
.endObject()
.endObject()
.endObject();
String mapping = Strings.toString(builder);
String mapping = builder.toString();
createKnnIndex(INDEX_NAME, mapping);

for (int i = 0; i < TEST_INDEX_VECTORS.length; i++) {
Expand Down Expand Up @@ -219,7 +218,7 @@ public void testAddDoc() throws Exception {
.endObject();

Map<String, Object> mappingMap = xContentBuilderToMap(builder);
String mapping = Strings.toString(builder);
String mapping = builder.toString();

createKnnIndex(INDEX_NAME, mapping);
assertEquals(new TreeMap<>(mappingMap), new TreeMap<>(getIndexMappingAsMap(INDEX_NAME)));
Expand Down Expand Up @@ -305,7 +304,7 @@ public void testQuery_filterWithNonLuceneEngine() throws Exception {
.endObject()
.endObject();

String mapping = Strings.toString(builder);
String mapping = builder.toString();
createKnnIndex(INDEX_NAME, mapping);

addKnnDocWithAttributes(
Expand Down Expand Up @@ -371,7 +370,7 @@ private void createKnnIndexMappingWithLuceneEngine(int dimension, SpaceType spac
.endObject()
.endObject();

String mapping = Strings.toString(builder);
String mapping = builder.toString();
createKnnIndex(INDEX_NAME, mapping);
}

Expand Down
Loading

0 comments on commit 0a7fc4e

Please sign in to comment.