Skip to content

Commit fae99b5

Browse files
committed
disi
1 parent a63e853 commit fae99b5

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/ES87TSDBDocValuesConsumer.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.lucene.util.BytesRef;
4040
import org.apache.lucene.util.BytesRefBuilder;
4141
import org.apache.lucene.util.LongsRef;
42+
import org.apache.lucene.util.RoaringDocIdSet;
4243
import org.apache.lucene.util.StringHelper;
4344
import org.apache.lucene.util.compress.LZ4;
4445
import org.apache.lucene.util.packed.DirectMonotonicWriter;
@@ -145,28 +146,10 @@ private long[] writeField(
145146
numValues += count;
146147
}
147148
}
148-
149-
if (numDocsWithValue == 0) { // meta[-2, 0]: No documents with values
150-
meta.writeLong(-2); // docsWithFieldOffset
151-
meta.writeLong(0L); // docsWithFieldLength
152-
meta.writeShort((short) -1); // jumpTableEntryCount
153-
meta.writeByte((byte) -1); // denseRankPower
154-
} else if (numDocsWithValue == maxDoc) { // meta[-1, 0]: All documents have values
155-
meta.writeLong(-1); // docsWithFieldOffset
156-
meta.writeLong(0L); // docsWithFieldLength
157-
meta.writeShort((short) -1); // jumpTableEntryCount
158-
meta.writeByte((byte) -1); // denseRankPower
159-
} else { // meta[data.offset, data.length]: IndexedDISI structure for documents with values
160-
long offset = data.getFilePointer();
161-
meta.writeLong(offset); // docsWithFieldOffset
162-
values = valuesProducer.getSortedNumeric(field);
163-
final short jumpTableEntryCount = IndexedDISI.writeBitSet(values, data, IndexedDISI.DEFAULT_DENSE_RANK_POWER);
164-
meta.writeLong(data.getFilePointer() - offset); // docsWithFieldLength
165-
meta.writeShort(jumpTableEntryCount);
166-
meta.writeByte(IndexedDISI.DEFAULT_DENSE_RANK_POWER);
167-
}
168149
meta.writeLong(numValues);
169150

151+
// TODO: write DISI to temp file and append it later to data part:
152+
var docIdSetBuilder = new RoaringDocIdSet.Builder(maxDoc);
170153
if (numValues > 0) {
171154
// Special case for maxOrd of 1, signal -1 that no blocks will be written
172155
meta.writeInt(maxOrd != 1 ? ES87TSDBDocValuesFormat.DIRECT_MONOTONIC_BLOCK_SHIFT : -1);
@@ -193,6 +176,7 @@ private long[] writeField(
193176

194177
for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
195178
numDocsWithValue++;
179+
docIdSetBuilder.add(doc);
196180
final int count = values.docValueCount();
197181
if (docCountConsumer != null) {
198182
docCountConsumer.accept(count);
@@ -235,6 +219,35 @@ private long[] writeField(
235219
meta.writeLong(valuesDataOffset);
236220
meta.writeLong(valuesDataLength);
237221
}
222+
if (numDocsWithValue == 0) { // meta[-2, 0]: No documents with values
223+
meta.writeLong(-2); // docsWithFieldOffset
224+
meta.writeLong(0L); // docsWithFieldLength
225+
meta.writeShort((short) -1); // jumpTableEntryCount
226+
meta.writeByte((byte) -1); // denseRankPower
227+
} else if (numDocsWithValue == maxDoc) { // meta[-1, 0]: All documents have values
228+
meta.writeLong(-1); // docsWithFieldOffset
229+
meta.writeLong(0L); // docsWithFieldLength
230+
meta.writeShort((short) -1); // jumpTableEntryCount
231+
meta.writeByte((byte) -1); // denseRankPower
232+
} else { // meta[data.offset, data.length]: IndexedDISI structure for documents with values
233+
long offset = data.getFilePointer();
234+
meta.writeLong(offset); // docsWithFieldOffset
235+
final short jumpTableEntryCount;
236+
if (maxOrd != 1) {
237+
var bitSet = docIdSetBuilder.build();
238+
var iterator = bitSet.iterator();
239+
if (iterator == null) {
240+
iterator = DocIdSetIterator.empty();
241+
}
242+
jumpTableEntryCount = IndexedDISI.writeBitSet(iterator, data, IndexedDISI.DEFAULT_DENSE_RANK_POWER);
243+
} else {
244+
values = valuesProducer.getSortedNumeric(field);
245+
jumpTableEntryCount = IndexedDISI.writeBitSet(values, data, IndexedDISI.DEFAULT_DENSE_RANK_POWER);
246+
}
247+
meta.writeLong(data.getFilePointer() - offset); // docsWithFieldLength
248+
meta.writeShort(jumpTableEntryCount);
249+
meta.writeByte(IndexedDISI.DEFAULT_DENSE_RANK_POWER);
250+
}
238251

239252
return new long[] { numDocsWithValue, numValues };
240253
}

server/src/main/java/org/elasticsearch/index/codec/tsdb/ES87TSDBDocValuesProducer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,6 @@ private static DocValuesSkipperEntry readDocValueSkipperMeta(IndexInput meta) th
905905
}
906906

907907
private static void readNumeric(IndexInput meta, NumericEntry entry) throws IOException {
908-
entry.docsWithFieldOffset = meta.readLong();
909-
entry.docsWithFieldLength = meta.readLong();
910-
entry.jumpTableEntryCount = meta.readShort();
911-
entry.denseRankPower = meta.readByte();
912908
entry.numValues = meta.readLong();
913909
if (entry.numValues > 0) {
914910
final int indexBlockShift = meta.readInt();
@@ -926,6 +922,10 @@ private static void readNumeric(IndexInput meta, NumericEntry entry) throws IOEx
926922
entry.valuesOffset = meta.readLong();
927923
entry.valuesLength = meta.readLong();
928924
}
925+
entry.docsWithFieldOffset = meta.readLong();
926+
entry.docsWithFieldLength = meta.readLong();
927+
entry.jumpTableEntryCount = meta.readShort();
928+
entry.denseRankPower = meta.readByte();
929929
}
930930

931931
private BinaryEntry readBinary(IndexInput meta) throws IOException {

0 commit comments

Comments
 (0)