Jackie-Jiang commented on a change in pull request #5853:
URL: https://github.com/apache/incubator-pinot/pull/5853#discussion_r476000914
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/inv/RangeIndexCreator.java
##########
@@ -165,26 +166,63 @@ public RangeIndexCreator(File indexDir, FieldSpec
fieldSpec, FieldSpec.DataType
}
@Override
- public void add(int dictId) {
- _numberValueBuffer.put(_nextDocId, dictId);
- _docIdBuffer.put(_nextDocId, _nextDocId);
- _nextDocId = _nextDocId + 1;
+ public void add(int value) {
+ addValueToBuffer(value);
+ nextDoc();
}
@Override
- public void add(int[] dictIds, int length) {
+ public void add(int[] values, int length) {
for (int i = 0; i < length; i++) {
- int dictId = dictIds[i];
- _numberValueBuffer.put(_nextValueId, dictId);
- _docIdBuffer.put(_nextValueId, _nextDocId);
- _nextValueId = _nextValueId + 1;
+ addValueToBuffer(values[i]);
+ nextDoc();
Review comment:
(CRITICAL) This is not correct. Here you should add to `_nextValueId`
instead of `_nextDocId`
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/segment/creator/DictionaryBasedInvertedIndexCreator.java
##########
@@ -0,0 +1,85 @@
+/**
+ * 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.pinot.core.segment.creator;
+
+import java.io.Closeable;
Review comment:
(nit) unused import
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/inv/RangeIndexCreator.java
##########
@@ -65,7 +66,7 @@
* </li>
* </ul>
*/
-public final class RangeIndexCreator implements InvertedIndexCreator {
+public final class RangeIndexCreator implements
RawValueBasedInvertedIndexCreator {
Review comment:
This should implement both `RawValueBasedInvertedIndexCreator` and
`DictionaryBasedInvertedIndexCreator`?
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/inv/RangeIndexCreator.java
##########
@@ -165,26 +166,63 @@ public RangeIndexCreator(File indexDir, FieldSpec
fieldSpec, FieldSpec.DataType
}
@Override
- public void add(int dictId) {
- _numberValueBuffer.put(_nextDocId, dictId);
- _docIdBuffer.put(_nextDocId, _nextDocId);
- _nextDocId = _nextDocId + 1;
+ public void add(int value) {
+ addValueToBuffer(value);
Review comment:
Recommend inline these 2 methods for readability (as the existing code).
Current way is not as readable
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/segment/index/loader/invertedindex/RangeIndexHandler.java
##########
@@ -140,17 +145,70 @@ private void handleDictionaryBasedColumn(ColumnMetadata
columnMetadata)
}
}
+ private void handleNonDictionaryBasedColumn(ColumnMetadata columnMetadata)
+ throws IOException {
+ int numDocs = columnMetadata.getTotalDocs();
+ try (RangeIndexCreator creator = new RangeIndexCreator(_indexDir,
columnMetadata.getFieldSpec(),
+ columnMetadata.getDataType(), -1, -1, numDocs,
columnMetadata.getTotalNumberOfEntries())) {
+ try (ForwardIndexReader forwardIndexReader =
getForwardIndexReader(columnMetadata, _segmentWriter);
+ ForwardIndexReaderContext readerContext =
forwardIndexReader.createContext()) {
+ if (columnMetadata.isSingleValue()) {
+ // Single-value column.
+ switch (columnMetadata.getDataType()) {
+ case INT: {
+ for (int i = 0; i < numDocs; i++) {
+ creator.add(forwardIndexReader.getInt(i, readerContext));
+ }
+ break;
+ }
+ case LONG: {
+ for (int i = 0; i < numDocs; i++) {
+ creator.add(forwardIndexReader.getLong(i, readerContext));
+ }
+ break;
+ }
+ case FLOAT: {
+ for (int i = 0; i < numDocs; i++) {
+ creator.add(forwardIndexReader.getFloat(i, readerContext));
+ }
+ break;
+ }
+ case DOUBLE: {
+ for (int i = 0; i < numDocs; i++) {
+ creator.add(forwardIndexReader.getDouble(i, readerContext));
+ }
+ break;
+ }
+ default: {
+ throw new RuntimeException("Range indexing is not supported");
+ }
+ }
+ }
+ creator.seal();
+ }
+ }
+ }
+
private ForwardIndexReader<?> getForwardIndexReader(ColumnMetadata
columnMetadata,
SegmentDirectory.Writer segmentWriter)
throws IOException {
PinotDataBuffer buffer =
segmentWriter.getIndexFor(columnMetadata.getColumnName(),
ColumnIndexType.FORWARD_INDEX);
int numRows = columnMetadata.getTotalDocs();
int numBitsPerValue = columnMetadata.getBitsPerElement();
if (columnMetadata.isSingleValue()) {
- return new FixedBitSVForwardIndexReader(buffer, numRows,
numBitsPerValue);
+ if (columnMetadata.hasDictionary()) {
+ return new FixedBitSVForwardIndexReader(buffer, numRows,
numBitsPerValue);
+ } else {
+ return new FixedByteChunkSVForwardIndexReader(buffer,
columnMetadata.getDataType());
+ }
} else {
- return new FixedBitMVForwardIndexReader(buffer, numRows,
columnMetadata.getTotalNumberOfEntries(),
- numBitsPerValue);
+ if (columnMetadata.hasDictionary()) {
+ return new FixedBitMVForwardIndexReader(buffer, numRows,
columnMetadata.getTotalNumberOfEntries(),
+ numBitsPerValue);
+ } else {
+ throw new RuntimeException("Range indexing is not supported for multi
value non-dictionary columns");
Review comment:
```suggestion
throw new RuntimeException("Raw index on multi-value column is not
supported");
```
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]