Skip to content

Commit

Permalink
Datacube field changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Apr 24, 2024
1 parent c993b9a commit d445522
Show file tree
Hide file tree
Showing 55 changed files with 1,485 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.lucene.codecs.simpletext;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.DataCubesFormat;
import org.apache.lucene.codecs.CompoundFormat;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.FieldInfosFormat;
Expand Down Expand Up @@ -107,4 +108,9 @@ public PointsFormat pointsFormat() {
public KnnVectorsFormat knnVectorsFormat() {
return knnVectorsFormat;
}

@Override
public DataCubesFormat dataCubesFormat() {
return null;//todo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public SegmentInfo read(
diagnostics,
id,
attributes,
indexSort);
indexSort,
null);//todo
info.setFiles(files);
return info;
}
Expand Down
3 changes: 3 additions & 0 deletions lucene/core/src/java/org/apache/lucene/codecs/Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public final String getName() {
/** Encodes/decodes numeric vector fields */
public abstract KnnVectorsFormat knnVectorsFormat();

/** Encodes/decodes multi-field data cubes index */
public abstract DataCubesFormat dataCubesFormat();

/** looks up a codec by name */
public static Codec forName(String name) {
return Holder.getLoader().lookup(name);
Expand Down
40 changes: 40 additions & 0 deletions lucene/core/src/java/org/apache/lucene/codecs/DataCubesFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.apache.lucene.codecs;

import java.io.IOException;
import org.apache.lucene.index.DataCubesConfig;
import org.apache.lucene.index.DataCubeDocValuesConsumer;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.util.NamedSPILoader;


public abstract class DataCubesFormat implements NamedSPILoader.NamedSPI{

private final String name;
protected DataCubesFormat(String name) {
NamedSPILoader.checkServiceName(name);
this.name = name;
}
@Override
public String getName() {
return name;
}

public abstract DataCubesProducer<?> fieldsProducer(SegmentReadState state) throws IOException;

public abstract DataCubeDocValuesConsumer fieldsConsumer(SegmentWriteState state, DataCubesConfig compositeConfig) throws IOException;

public static final DataCubesFormat EMPTY = new DataCubesFormat("EMPTY") {
@Override
public DataCubesProducer<?> fieldsProducer(SegmentReadState state)
throws IOException {
return null;
}

@Override
public DataCubeDocValuesConsumer fieldsConsumer(SegmentWriteState state, DataCubesConfig compositeConfig)
throws IOException {
throw new UnsupportedOperationException("Attempt to write EMPTY composite values");
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.apache.lucene.codecs;

import java.io.Closeable;
import java.io.IOException;
import org.apache.lucene.index.DataCubeValues;


public abstract class DataCubesProducer<T> implements Closeable {

protected DataCubesProducer() {}
public abstract void checkIntegrity() throws IOException;
public abstract DataCubeValues<?> getDataCubeValues(String field) throws IOException;

public DataCubesProducer<T> getMergeInstance() {
return this;
}

}
32 changes: 32 additions & 0 deletions lucene/core/src/java/org/apache/lucene/codecs/DataCubesWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.apache.lucene.codecs;

import java.io.Closeable;
import java.io.IOException;
import org.apache.lucene.codecs.lucene90.Lucene90DocValuesFormat;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.MergeState;
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.index.Sorter;
import org.apache.lucene.util.Accountable;


public abstract class DataCubesWriter<T> implements Accountable, Closeable {

private final DocValuesConsumer docValuesWriter;

public DataCubesWriter(SegmentWriteState state)
throws IOException {
docValuesWriter = new Lucene90DocValuesFormat().fieldsConsumer(state);
}

public abstract DataCubesWriter<?> addField(FieldInfo field) throws IOException;

public void merge(MergeState mergeState) throws IOException {

}
public abstract void finish() throws IOException;

public void flush(SegmentWriteState state, Sorter.DocMap sortMap) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@ public PointsFormat pointsFormat() {
public KnnVectorsFormat knnVectorsFormat() {
return delegate.knnVectorsFormat();
}

@Override
public DataCubesFormat dataCubesFormat() {
return delegate.dataCubesFormat();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Encodes/decodes per-document vector and any associated indexing structures required to support
* nearest-neighbor search
*/
public abstract class KnnVectorsFormat implements NamedSPILoader.NamedSPI {
public abstract class KnnVectorsFormat implements NamedSPILoader.NamedSPI {

/**
* This static holder class prevents classloading deadlock by delaying init of doc values formats
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.apache.lucene.codecs.example;

import java.io.IOException;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.packed.PackedLongValues;


public class BufferedAggregatedDocValues extends NumericDocValues {
final PackedLongValues.Iterator iter;
final DocIdSetIterator docsWithField;
private long value;

public BufferedAggregatedDocValues(PackedLongValues values, DocIdSetIterator docsWithFields) {
this.iter = values.iterator();
this.docsWithField = docsWithFields;
}

@Override
public int docID() {
return docsWithField.docID();
}

@Override
public int nextDoc() throws IOException {


int docID = docsWithField.nextDoc();
if (docID != NO_MORE_DOCS) {
value = iter.next();
}
return docID;
}

@Override
public int advance(int target) {
throw new UnsupportedOperationException();
}

@Override
public boolean advanceExact(int target) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public long cost() {
return docsWithField.cost();
}

@Override
public long longValue() {
return value;
}
}

Loading

0 comments on commit d445522

Please sign in to comment.