Skip to content

Commit

Permalink
Refactor codec and doc format classes for Lucene 9.1
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski committed Mar 22, 2022
1 parent 7711d48 commit f4bca46
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.lucene91.Lucene91Codec;
import org.opensearch.knn.index.codec.KNNDocFormatFacade;
import org.opensearch.knn.index.codec.KNNDocFormatFactory;

/**
* Extends the Codec to support a new file format for KNN index
Expand All @@ -24,10 +26,8 @@
*/
public final class KNN91Codec extends FilterCodec {

private final DocValuesFormat docValuesFormat;
private final CompoundFormat compoundFormat;

public static final String KNN_91 = "KNN91Codec";
private KNNDocFormatFacade docFormatFacade;

/**
* No arg constructor that uses Lucene91 as the delegate
Expand All @@ -43,17 +43,16 @@ public KNN91Codec() {
*/
public KNN91Codec(Codec delegate) {
super(KNN_91, delegate);
this.docValuesFormat = new KNN91DocValuesFormat(delegate.docValuesFormat());
this.compoundFormat = new KNN91CompoundFormat(delegate.compoundFormat());
docFormatFacade = KNNDocFormatFactory.createKNN91DocFormat(delegate);
}

@Override
public DocValuesFormat docValuesFormat() {
return this.docValuesFormat;
return docFormatFacade.docValuesFormat();
}

@Override
public CompoundFormat compoundFormat() {
return this.compoundFormat;
return docFormatFacade.compoundFormat();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;

import org.apache.lucene.codecs.CompoundFormat;
import org.apache.lucene.codecs.DocValuesFormat;
import org.opensearch.knn.index.codec.KNNDocFormatFacade;

public class KNN91DocFormat implements KNNDocFormatFacade {

private final DocValuesFormat docValuesFormat;
private final CompoundFormat compoundFormat;

public KNN91DocFormat(final DocValuesFormat docValuesFormat, final CompoundFormat compoundFormat) {
this.docValuesFormat = docValuesFormat;
this.compoundFormat = compoundFormat;
}

@Override
public DocValuesFormat docValuesFormat() {
return docValuesFormat;
}

@Override
public CompoundFormat compoundFormat() {
return compoundFormat;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocIDMerger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import org.apache.lucene.codecs.CompoundDirectory;
import org.apache.lucene.codecs.CompoundFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import com.google.common.collect.ImmutableMap;
import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BinaryDocValues;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/opensearch/knn/index/codec/KNNCodecFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec;

import org.apache.lucene.codecs.Codec;
import org.opensearch.knn.index.codec.KNN91Codec.KNN91Codec;

public class KNNCodecFactory {

public static Codec createKNN91Codec(Codec userCodec) {
return new KNN91Codec(userCodec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.opensearch.index.codec.CodecServiceConfig;
import org.apache.lucene.codecs.Codec;
import org.opensearch.index.codec.CodecService;
import org.opensearch.knn.index.codec.KNN91Codec.KNN91Codec;

/**
* KNNCodecService to inject the right KNNCodec version
Expand All @@ -27,6 +26,6 @@ public KNNCodecService(CodecServiceConfig codecServiceConfig) {
*/
@Override
public Codec codec(String name) {
return new KNN91Codec(super.codec(name));
return KNNCodecFactory.createKNN91Codec(super.codec(name));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec;

import org.apache.lucene.codecs.CompoundFormat;
import org.apache.lucene.codecs.DocValuesFormat;

public interface KNNDocFormatFacade {

DocValuesFormat docValuesFormat();

CompoundFormat compoundFormat();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec;

import org.apache.lucene.codecs.Codec;
import org.opensearch.knn.index.codec.KNN91Codec.docformat.KNN91CompoundFormat;
import org.opensearch.knn.index.codec.KNN91Codec.KNN91DocFormat;
import org.opensearch.knn.index.codec.KNN91Codec.docformat.KNN91DocValuesFormat;

public class KNNDocFormatFactory {

public static KNNDocFormatFacade createKNN91DocFormat(Codec delegate) {
final KNNDocFormatFacade knnDocFormatFacade = new KNN91DocFormat(
new KNN91DocValuesFormat(delegate.docValuesFormat()),
new KNN91CompoundFormat(delegate.compoundFormat())
);
return knnDocFormatFacade;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import com.google.common.collect.ImmutableList;
import org.apache.lucene.index.BinaryDocValues;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.CompoundDirectory;
Expand All @@ -16,6 +22,7 @@
import org.junit.BeforeClass;
import org.opensearch.common.util.set.Sets;
import org.opensearch.knn.KNNTestCase;
import org.opensearch.knn.index.codec.KNN91Codec.KNN91Codec;
import org.opensearch.knn.index.codec.KNNCodecTestUtil;
import org.opensearch.knn.index.util.KNNEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.codec.KNN91Codec;
package org.opensearch.knn.index.codec.KNN91Codec.docformat;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down

0 comments on commit f4bca46

Please sign in to comment.