abhishekagarwal87 commented on code in PR #13268: URL: https://github.com/apache/druid/pull/13268#discussion_r1036197406
########## processing/src/main/java/org/apache/druid/segment/DimensionUnnestCursor.java: ########## @@ -0,0 +1,394 @@ +/* + * 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.druid.segment; + +import com.google.common.base.Predicate; +import org.apache.druid.query.BaseQuery; +import org.apache.druid.query.dimension.DefaultDimensionSpec; +import org.apache.druid.query.dimension.DimensionSpec; +import org.apache.druid.query.filter.ValueMatcher; +import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector; +import org.apache.druid.segment.column.ColumnCapabilities; +import org.apache.druid.segment.data.IndexedInts; +import org.joda.time.DateTime; + +import javax.annotation.Nullable; +import java.util.BitSet; +import java.util.LinkedHashSet; + +/** + * The cursor to help unnest MVDs with dictionary encoding. + * Consider a segment has 2 rows + * ['a', 'b', 'c'] + * ['d', 'c'] + * + * Considering dictionary encoding, these are represented as + * + * 'a' -> 0 + * 'b' -> 1 + * 'c' -> 2 + * 'd' -> 3 + * + * The baseCursor points to the row of IndexedInts [0, 1, 2] + * while the unnestCursor with each call of advance() moves over individual elements. + * + * advance() -> 0 -> 'a' + * advance() -> 1 -> 'b' + * advance() -> 2 -> 'c' + * advance() -> 3 -> 'd' (advances base cursor first) + * advance() -> 2 -> 'c' + * + * Total 5 advance calls above + * + * The allowSet if available helps skip over elements which are not in the allowList by moving the cursor to + * the next available match. The hashSet is converted into a bitset (during initialization) for efficiency. + * If allowSet is ['c', 'd'] then the advance moves over to the next available match + * + * advance() -> 2 -> 'c' + * advance() -> 3 -> 'd' (advances base cursor first) + * advance() -> 2 -> 'c' + * + * Total 3 advance calls in this case + * + * The index reference points to the index of each row that the unnest cursor is accessing + * The indexedInts for each row are held in the indexedIntsForCurrentRow object + * + * The needInitialization flag sets up the initial values of indexedIntsForCurrentRow at the beginning of the segment + * + */ Review Comment: Awesome. 👍 -- 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]
