adelapena commented on code in PR #2556:
URL: https://github.com/apache/cassandra/pull/2556#discussion_r1379056650


##########
src/java/org/apache/cassandra/db/MultiClusteringBuilder.java:
##########
@@ -0,0 +1,437 @@
+/*
+ * 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.db;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.cql3.statements.Bound;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.UniqueComparator;
+import org.apache.cassandra.utils.btree.BTreeSet;
+
+/**
+ * Builder that allows to build multiple {@link Clustering}/{@link 
ClusteringBound} at the same time.
+ * Builds a set of clusterings incrementally, by computing cartesian products 
of
+ * sets of values present in each statement restriction. The typical use of 
this builder is as follows:
+ * <ol>
+ * <li>Call {@link MultiClusteringBuilder#extend(ClusteringElements, List)} or 
{@link MultiClusteringBuilder#extend(List, List)}
+ * method once per each restriction. Slice restrictons, if they exist, must be 
added last.
+ * <li>Finally, call {@link MultiClusteringBuilder#build()} or {@link 
MultiClusteringBuilder#buildBound(boolean)} method
+ * to obtain the set of clusterings / clustering bounds.</li>
+ * </ol>
+ * <p>
+ * Important: When dealing with slices, you likely want the number of start 
and end bounds to match.
+ * If some columns are restricted from one side only, you can use the special 
{@link ClusteringElements#BOTTOM} or
+ * {@link ClusteringElements#TOP} values to generate a proper clustering bound 
for the "unbounded"
+ * side of the restriction.
+ * </p>
+ * <h1>Example</h1>
+ * <p>
+ *
+ * Imagine we have a CQL query with multiple restrictions joined by AND:
+ * <pre>
+ * SELECT * FROM tab
+ * WHERE a IN (a1, a2)
+ *   AND b IN (b1, b2, b3)
+ *   AND c > c1
+ * </pre>
+ * <p>
+ * We need to generate a list of clustering bounds that will be used to fetch 
proper contiguous chunks of the partition.
+ *
+ * <p>
+ * The builder initial state is a single empty clustering, denoted by the 
{@code ROOT} constant,
+ * which is a natural zero element of cartesian set multiplication. This 
significantly simplifies the logic.
+ * <pre>
+ * point: ()
+ * </pre>
+ *
+ * After adding the IN restriction on column {@code a} we get 2 points:
+ * <pre>
+ * point: (a1)
+ * point: (a2)
+ * </pre>
+ *
+ * Next when we add the IN restrction on column {@code b}, we get a cartesian 
product of all values
+ * of {@code a} with all values of {@code b}:
+ * <pre>
+ * point: (a1, b1)
+ * point: (a1, b2)
+ * point: (a1, b3)
+ * point: (a2, b1)
+ * point: (a2, b2)
+ * point: (a2, b3)
+ * </pre>
+ *
+ * Finally, we add the slice of column {@code c} by specifying the lower and 
upper bound
+ * (we use {@code TOP} for the upper bound), and we get the final set of 
clustering bounds:
+ * <pre>
+ * excl start: (a1, b1, c1)
+ * incl end:   (a1, b1)
+ * excl start: (a1, b2, c1)
+ * incl end:   (a1, b2)
+ * excl start: (a1, b3, c1)
+ * incl end:   (a1, b3)
+ * excl start: (a2, b1, c1)
+ * incl end:   (a2, b1)
+ * excl start: (a2, b2, c1)
+ * incl end:   (a2, b2)
+ * excl start: (a2, b3, c1)
+ * incl end:   (a2, b3)
+ * </pre>
+ */
+public class MultiClusteringBuilder

Review Comment:
   Nit: There are a couple of mentions of `MultiCBuilder` in 
`InsertInvalidateSizedRecordsTest`.



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