maedhroz commented on code in PR #2409:
URL: https://github.com/apache/cassandra/pull/2409#discussion_r1227216477


##########
src/java/org/apache/cassandra/index/sai/disk/v1/kdtree/BKDWriter.java:
##########
@@ -0,0 +1,782 @@
+/*
+ * 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.cassandra.index.sai.disk.v1.kdtree;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.IntFunction;
+
+import com.google.common.base.MoreObjects;
+
+import org.apache.cassandra.index.sai.disk.io.RAMIndexOutput;
+import org.apache.cassandra.index.sai.disk.v1.SAICodecUtils;
+import org.apache.lucene.codecs.MutablePointValues;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.GrowableByteArrayDataOutput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FutureArrays;
+import org.apache.lucene.util.IntroSorter;
+import org.apache.lucene.util.LongBitSet;
+import org.apache.lucene.util.Sorter;
+import org.apache.lucene.util.bkd.MutablePointsReaderUtils;
+
+/**
+ * This is a specialisation of the lucene BKDWriter that only writes a single 
dimension.
+ * <p>
+ * Recursively builds a block KD-tree to assign all incoming points in N-dim 
space to smaller
+ * and smaller N-dim rectangles (cells) until the number of points in a given
+ * rectangle is &lt;= <code>maxPointsInLeafNode</code>.  The tree is
+ * fully balanced, which means the leaf nodes will have between 50% and 100% of
+ * the requested <code>maxPointsInLeafNode</code>.  Values that fall exactly
+ * on a cell boundary may be in either cell.
+ *
+ * <p>
+ * See <a 
href="https://www.cs.duke.edu/~pankaj/publications/papers/bkd-sstd.pdf";>this 
paper</a> for details.
+ *
+ * <p>This consumes heap during writing: it allocates a 
<code>LongBitSet(numPoints)</code>,
+ * and then uses up to the specified {@code maxMBSortInHeap} heap space for 
writing.
+ *
+ * <p>
+ * <b>NOTE</b>: This can write at most Integer.MAX_VALUE * 
<code>maxPointsInLeafNode</code> total points.
+ *
+ * lucene.experimental
+ */
+public class BKDWriter

Review Comment:
   So let's have the naming discussion :)
   
   I guess the first thing to establish is whether or not we're ever going to 
try to actually use the kd-tree for geo-spatial search in the future. It seems 
like a possibility, but not in 5.0...and who knows when after that.
   
   Assuming we ignore the future, we're left w/ how to name `BKDWriter` and 
`OneDimensionBKDWriter`. `BKDWriter` seems like a poor choice, given it both 
doesn't connote the single-dimension aspect of what it does, and it has the 
same name as the Lucene class it's loosely based on. All it really is now is a 
writer for a block-oriented, balanced, binary tree, optimized to be immutable 
on disk. We could call it a lot of things, but I'll just throw some out and see 
what sticks w/ everyone:
   
   `BlockTreeWriter`, `BlockBalancedTreeWriter`, `BlockBinaryTreeWriter`, etc.
   
   (At least a few people have asked why we even have this tree when the trie 
exists, but emphasizing that it's a **balanced** tree and better for large 
range queries, even in our naming, might be nice.)
   
   `OneDimensionBKDWriter` is private, so it doesn't matter much what we name 
it I guess, but I would consider something like `BlockWriter` or `LeafWriter`, 
and I would move the `writeIndex()` call out of `finish()` and into the 
top-level `writeField()` (which I might also rename `writeAll()` or 
`writeTerms()`, etc.) That way it does one thing (writes blocks) and lets the 
top-level writer tie everything together.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to