-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorginize factory and facade code, minor review comments
Signed-off-by: Martin Gaievski <[email protected]>
- Loading branch information
1 parent
78b4e30
commit af79c68
Showing
13 changed files
with
106 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
src/main/java/org/opensearch/knn/index/codec/KNN91Codec/KNN91DocFormat.java
This file was deleted.
Oops, something went wrong.
9 changes: 1 addition & 8 deletions
9
src/main/java/org/opensearch/knn/index/codec/KNN91Codec/docformat/KNN91BinaryDocValues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
src/main/java/org/opensearch/knn/index/codec/KNN91Codec/docformat/KNN91CompoundFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
...main/java/org/opensearch/knn/index/codec/KNN91Codec/docformat/KNN91DocValuesConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
src/main/java/org/opensearch/knn/index/codec/KNN91Codec/docformat/KNN91DocValuesReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 37 additions & 10 deletions
47
src/main/java/org/opensearch/knn/index/codec/KNNCodecFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
/* | ||
* 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; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.lucene91.Lucene91Codec; | ||
import org.opensearch.knn.index.codec.KNN91Codec.KNN91Codec; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.util.Map; | ||
|
||
/** | ||
* Factory abstraction for KNN codes | ||
*/ | ||
public class KNNCodecFactory { | ||
|
||
public static Codec createKNN91Codec(Codec userCodec) { | ||
return new KNN91Codec(userCodec); | ||
private static Map<KNNCodecVersion, Class> CODEC_BY_VERSION = ImmutableMap.of(KNNCodecVersion.KNN91, KNN91Codec.class); | ||
|
||
private static KNNCodecVersion LATEST_KNN_CODEC_VERSION = KNNCodecVersion.KNN91; | ||
|
||
public static Codec createKNNCodec(final Codec userCodec) { | ||
return getCodec(LATEST_KNN_CODEC_VERSION, userCodec); | ||
} | ||
|
||
public static Codec createKNNCodec(final KNNCodecVersion knnCodecVersion, final Codec userCodec) { | ||
return getCodec(knnCodecVersion, userCodec); | ||
} | ||
|
||
private static Codec getCodec(final KNNCodecVersion knnCodecVersion, final Codec userCodec) { | ||
try { | ||
Constructor<?> constructor = CODEC_BY_VERSION.getOrDefault(knnCodecVersion, CODEC_BY_VERSION.get(LATEST_KNN_CODEC_VERSION)) | ||
.getConstructor(Codec.class); | ||
return (Codec) constructor.newInstance(userCodec); | ||
} catch (Exception ex) { | ||
throw new RuntimeException("Cannot create instance of KNN codec", ex); | ||
} | ||
} | ||
|
||
public static class CodecDelegateFactory { | ||
|
||
public static Codec createKNN91DefaultDelegate() { | ||
return new Lucene91Codec(); | ||
} | ||
} | ||
|
||
enum KNNCodecVersion { | ||
KNN91 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/java/org/opensearch/knn/index/codec/KNNDocFormatFacade.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/java/org/opensearch/knn/index/codec/KNNDocFormatFactory.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/main/java/org/opensearch/knn/index/codec/KNNFormatFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.knn.index.codec; | ||
|
||
import org.apache.lucene.codecs.CompoundFormat; | ||
import org.apache.lucene.codecs.DocValuesFormat; | ||
|
||
/** | ||
* Class abstracts facade for plugin formats. | ||
*/ | ||
public class KNNFormatFacade { | ||
|
||
private final DocValuesFormat docValuesFormat; | ||
private final CompoundFormat compoundFormat; | ||
|
||
public KNNFormatFacade(final DocValuesFormat docValuesFormat, final CompoundFormat compoundFormat) { | ||
this.docValuesFormat = docValuesFormat; | ||
this.compoundFormat = compoundFormat; | ||
} | ||
|
||
public DocValuesFormat docValuesFormat() { | ||
return docValuesFormat; | ||
} | ||
|
||
public CompoundFormat compoundFormat() { | ||
return compoundFormat; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/opensearch/knn/index/codec/KNNFormatFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
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.docformat.KNN91DocValuesFormat; | ||
|
||
/** | ||
* Factory abstraction for KNN document format facades | ||
*/ | ||
public class KNNFormatFactory { | ||
|
||
public static KNNFormatFacade createKNN91Format(final Codec delegate) { | ||
final KNNFormatFacade knnFormatFacade = new KNNFormatFacade( | ||
new KNN91DocValuesFormat(delegate.docValuesFormat()), | ||
new KNN91CompoundFormat(delegate.compoundFormat()) | ||
); | ||
return knnFormatFacade; | ||
} | ||
} |