You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/03/19 11:19:35 UTC

[GitHub] [lucene-solr] iverase opened a new pull request #1363: LUCENE-9284: Refactor out logic that serialises the BKD tree

iverase opened a new pull request #1363: LUCENE-9284: Refactor out logic that serialises the BKD tree
URL: https://github.com/apache/lucene-solr/pull/1363
 
 
   Split BKDwriter into the logic that build the Kd-tree and the logic that serialises the tree into the index.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] iverase commented on a change in pull request #1363: LUCENE-9284: Refactor out logic that serialises the BKD tree

Posted by GitBox <gi...@apache.org>.
iverase commented on a change in pull request #1363: LUCENE-9284: Refactor out logic that serialises the BKD tree
URL: https://github.com/apache/lucene-solr/pull/1363#discussion_r394954911
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/util/bkd/BKDIndexWriter.java
 ##########
 @@ -0,0 +1,474 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.util.bkd;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.IntFunction;
+
+import org.apache.lucene.codecs.CodecUtil;
+import org.apache.lucene.store.ByteBuffersDataOutput;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
+
+/** Utility class providing methods to serialize a KD-tree.
+ *
+ * @lucene.experimental */
+public class BKDIndexWriter {
+
+  public static final String CODEC_NAME = "BKD";
+  public static final int VERSION_START = 4; // version used by Lucene 7.0
+  //public static final int VERSION_CURRENT = VERSION_START;
+  public static final int VERSION_LEAF_STORES_BOUNDS = 5;
+  public static final int VERSION_SELECTIVE_INDEXING = 6;
+  public static final int VERSION_LOW_CARDINALITY_LEAVES = 7;
+  public static final int VERSION_CURRENT = VERSION_LOW_CARDINALITY_LEAVES;
+
+  /** How many dimensions we are storing at the leaf (data) nodes */
+  private final int numDataDims;
+
+  /** How many dimensions we are indexing in the internal nodes */
+  private final int numIndexDims;
+
+  /** How many bytes each value in each dimension takes. */
+  private final int bytesPerDim;
+
+  /** numDataDims * bytesPerDim */
+  private final int packedBytesLength;
+
+  /** numIndexDims * bytesPerDim */
+  private final int packedIndexBytesLength;
+
+  private final int maxPointsInLeafNode;
+
+  private final byte[] scratch;
+
+  // Reused when writing leaf blocks
+  private final ByteBuffersDataOutput scratchOut = ByteBuffersDataOutput.newResettableInstance();
+
+  BKDIndexWriter(int numDataDims, int numIndexDims, int bytesPerDim, int maxPointsInLeafNode) {
+    this.numDataDims = numDataDims;
+    this.numIndexDims = numIndexDims;
+    this.bytesPerDim = bytesPerDim;
+    this.packedBytesLength = numDataDims * bytesPerDim;
+    this.packedIndexBytesLength = numIndexDims * bytesPerDim;
+    this.maxPointsInLeafNode = maxPointsInLeafNode;
+    this.scratch = new byte[packedBytesLength];
+  }
+
+  /** writes a leaf block in the provided DataOutput */
+  public void writeLeafBlock(DataOutput out, int[] docIDs, int start, int count,
+                             int[] commonPrefixes, byte[] packedValue,
+                             int sortedDim, IntFunction<BytesRef> packedValues, int leafCardinality) throws IOException {
+    assert count > 0 : "count must be bigger than 0";
+    assert count <= maxPointsInLeafNode: "maxPointsInLeafNode=" + maxPointsInLeafNode + " > count=" + count;
+    assert scratchOut.size() == 0;
+    // Write docIDs first, as their own chunk, so that at intersect time we can add all docIDs w/o
+    // loading the values:
+    writeLeafBlockDocs(scratchOut, docIDs, start, count);
+    // Write common prefixes:
+    writeCommonPrefixes(scratchOut, commonPrefixes, packedValue);
+    // Write point values:
+    writeLeafBlockPackedValues(scratchOut, commonPrefixes, count, sortedDim, packedValues, leafCardinality);
+    scratchOut.copyTo(out);
 
 Review comment:
   I wonder why we are using this ByteBuffersDataOutput?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org