Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Lombok #393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ plugins {
id 'idea'
id 'jacoco'
id "com.diffplug.spotless" version "6.3.0" apply false
id 'io.freefair.lombok' version '6.4.3'
}

apply from: 'gradle/formatting.gradle'
Expand Down Expand Up @@ -79,6 +80,13 @@ allprojects {
}
}

compileJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
}
compileTestJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
}

def usingRemoteCluster = System.properties.containsKey('tests.rest.cluster') || System.properties.containsKey('tests.cluster')
def usingMultiNode = project.properties.containsKey('numNodes')
// Only apply jacoco test coverage if we are running a local single node cluster
Expand Down
3 changes: 3 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public void testWrite() throws IOException {
String.format("%s_faiss3%s", segmentName, KNNEngine.FAISS.getExtension())
);

SegmentInfo segmentInfo = KNNCodecTestUtil.SegmentInfoBuilder.builder(directory, segmentName, segmentFiles.size(), codec).build();
SegmentInfo segmentInfo = KNNCodecTestUtil.segmentInfoBuilder()
.directory(directory)
.segmentName(segmentName)
.docsInSegment(segmentFiles.size())
.codec(codec)
.build();

for (String name : segmentFiles) {
IndexOutput indexOutput = directory.createOutput(name, IOContext.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ public void testAddKNNBinaryField_fromScratch_nmslibCurrent() throws IOException
SpaceType spaceType = SpaceType.COSINESIMIL;
int dimension = 16;

SegmentInfo segmentInfo = KNNCodecTestUtil.SegmentInfoBuilder.builder(directory, segmentName, docsInSegment, codec).build();
SegmentInfo segmentInfo = KNNCodecTestUtil.segmentInfoBuilder()
.directory(directory)
.segmentName(segmentName)
.docsInSegment(docsInSegment)
.codec(codec)
.build();

KNNMethodContext knnMethodContext = new KNNMethodContext(
knnEngine,
Expand Down Expand Up @@ -198,7 +203,12 @@ public void testAddKNNBinaryField_fromScratch_nmslibLegacy() throws IOException
SpaceType spaceType = SpaceType.COSINESIMIL;
int dimension = 16;

SegmentInfo segmentInfo = KNNCodecTestUtil.SegmentInfoBuilder.builder(directory, segmentName, docsInSegment, codec).build();
SegmentInfo segmentInfo = KNNCodecTestUtil.segmentInfoBuilder()
.directory(directory)
.segmentName(segmentName)
.docsInSegment(docsInSegment)
.codec(codec)
.build();

FieldInfo[] fieldInfoArray = new FieldInfo[] {
KNNCodecTestUtil.FieldInfoBuilder.builder(fieldName)
Expand Down Expand Up @@ -241,7 +251,12 @@ public void testAddKNNBinaryField_fromScratch_faissCurrent() throws IOException
SpaceType spaceType = SpaceType.INNER_PRODUCT;
int dimension = 16;

SegmentInfo segmentInfo = KNNCodecTestUtil.SegmentInfoBuilder.builder(directory, segmentName, docsInSegment, codec).build();
SegmentInfo segmentInfo = KNNCodecTestUtil.segmentInfoBuilder()
.directory(directory)
.segmentName(segmentName)
.docsInSegment(docsInSegment)
.codec(codec)
.build();

KNNMethodContext knnMethodContext = new KNNMethodContext(
knnEngine,
Expand Down Expand Up @@ -327,7 +342,12 @@ public void testAddKNNBinaryField_fromModel_faiss() throws IOException, Executio
int docsInSegment = 100;
String fieldName = String.format("test_field%s", randomAlphaOfLength(4));

SegmentInfo segmentInfo = KNNCodecTestUtil.SegmentInfoBuilder.builder(directory, segmentName, docsInSegment, codec).build();
SegmentInfo segmentInfo = KNNCodecTestUtil.segmentInfoBuilder()
.directory(directory)
.segmentName(segmentName)
.docsInSegment(docsInSegment)
.codec(codec)
.build();

FieldInfo[] fieldInfoArray = new FieldInfo[] {
KNNCodecTestUtil.FieldInfoBuilder.builder(fieldName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import lombok.Builder;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
Expand Down Expand Up @@ -52,86 +53,6 @@

public class KNNCodecTestUtil {

// Utility class to help build SegmentInfo with reasonable defaults
public static class SegmentInfoBuilder {

private final Directory directory;
private final String segmentName;
private final int docsInSegment;
private final Codec codec;

private Version version;
private Version minVersion;
private boolean isCompoundFile;
private byte[] segmentId;
private final Map<String, String> attributes;
private Sort indexSort;

public static SegmentInfoBuilder builder(Directory directory, String segmentName, int docsInSegment, Codec codec) {
return new SegmentInfoBuilder(directory, segmentName, docsInSegment, codec);
}

private SegmentInfoBuilder(Directory directory, String segmentName, int docsInSegment, Codec codec) {
this.directory = directory;
this.segmentName = segmentName;
this.docsInSegment = docsInSegment;
this.codec = codec;

this.version = Version.LATEST;
this.minVersion = Version.LATEST;
this.isCompoundFile = false;
this.segmentId = randomByteArrayOfLength(StringHelper.ID_LENGTH);
this.attributes = new HashMap<>();
this.indexSort = Sort.INDEXORDER;
}

public SegmentInfoBuilder version(Version version) {
this.version = version;
return this;
}

public SegmentInfoBuilder minVersion(Version minVersion) {
this.minVersion = minVersion;
return this;
}

public SegmentInfoBuilder isCompoundFile(boolean isCompoundFile) {
this.isCompoundFile = isCompoundFile;
return this;
}

public SegmentInfoBuilder segmentId(byte[] segmentId) {
this.segmentId = segmentId;
return this;
}

public SegmentInfoBuilder addAttribute(String key, String value) {
this.attributes.put(key, value);
return this;
}

public SegmentInfoBuilder indexSort(Sort indexSort) {
this.indexSort = indexSort;
return this;
}

public SegmentInfo build() {
return new SegmentInfo(
directory,
version,
minVersion,
segmentName,
docsInSegment,
isCompoundFile,
codec,
Collections.emptyMap(),
segmentId,
attributes,
indexSort
);
}
}

// Utility class to help build FieldInfo
public static class FieldInfoBuilder {
private final String fieldName;
Expand Down Expand Up @@ -430,4 +351,21 @@ public static float[] getRandomVector(int dimension) {
}
return data;
}

@Builder(builderMethodName = "segmentInfoBuilder")
public static SegmentInfo newSegmentInfo(final Directory directory, final String segmentName, int docsInSegment, final Codec codec) {
return new SegmentInfo(
directory,
Version.LATEST,
Version.LATEST,
segmentName,
docsInSegment,
false,
codec,
Collections.emptyMap(),
randomByteArrayOfLength(StringHelper.ID_LENGTH),
ImmutableMap.of(),
Sort.INDEXORDER
);
}
}