Jackie-Jiang commented on a change in pull request #5722:
URL: https://github.com/apache/incubator-pinot/pull/5722#discussion_r459109665
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/indexsegment/mutable/MutableSegmentImpl.java
##########
@@ -1033,13 +960,89 @@ void updateMVEntry(int numValuesInMVEntry) {
_numValues += numValuesInMVEntry;
_maxNumValuesPerMVEntry = Math.max(_maxNumValuesPerMVEntry,
numValuesInMVEntry);
}
+ }
+
+ private class IndexContainer implements Closeable {
+ final FieldSpec _fieldSpec;
+ final PartitionFunction _partitionFunction;
+ final int _partitionId;
+ final NumValuesInfo _numValuesInfo;
+ final MutableForwardIndex _forwardIndex;
+ final BaseMutableDictionary _dictionary;
+ final RealtimeInvertedIndexReader _invertedIndex;
+ final InvertedIndexReader _rangeIndex;
+ final RealtimeLuceneTextIndexReader _textIndex;
+ final BloomFilterReader _bloomFilter;
+ final MutableNullValueVector _nullValueVector;
+
+ volatile Comparable _minValue;
+ volatile Comparable _maxValue;
+
+ // Hold the dictionary id for the latest record
+ int _dictId = Integer.MIN_VALUE;
+ int[] _dictIds;
+
+ IndexContainer(FieldSpec fieldSpec, PartitionFunction partitionFunction,
int partitionId,
+ NumValuesInfo numValuesInfo, MutableForwardIndex forwardIndex,
BaseMutableDictionary dictionary,
+ RealtimeInvertedIndexReader invertedIndex, InvertedIndexReader
rangeIndex,
+ RealtimeLuceneTextIndexReader textIndex, BloomFilterReader bloomFilter,
+ MutableNullValueVector nullValueVector) {
+ _fieldSpec = fieldSpec;
+ _partitionFunction = partitionFunction;
+ _partitionId = partitionId;
+ _numValuesInfo = numValuesInfo;
+ _forwardIndex = forwardIndex;
+ _dictionary = dictionary;
+ _invertedIndex = invertedIndex;
+ _rangeIndex = rangeIndex;
+ _textIndex = textIndex;
+ _bloomFilter = bloomFilter;
+ _nullValueVector = nullValueVector;
+ }
- int getNumValues() {
- return _numValues;
+ DataSource toDataSource() {
+ return new MutableDataSource(_fieldSpec, _numDocsIndexed,
_numValuesInfo._numValues,
+ _numValuesInfo._maxNumValuesPerMVEntry, _partitionFunction,
_partitionId, _minValue, _maxValue, _forwardIndex,
+ _dictionary, _invertedIndex, _rangeIndex, _textIndex, _bloomFilter,
_nullValueVector);
}
- int getMaxNumValuesPerMVEntry() {
- return _maxNumValuesPerMVEntry;
+ @Override
+ public void close() {
+ String column = _fieldSpec.getName();
+ try {
+ _forwardIndex.close();
+ } catch (Exception e) {
+ _logger.error("Caught exception while closing forward index for
column: {}, continuing with error", column, e);
+ }
+ if (_dictionary != null) {
Review comment:
With that, the code will be like the following:
```
Optional.ofNullable(_dictionary).ifPresent(baseMutableDictionary -> {
try {
baseMutableDictionary.close();
} catch (IOException e) {
_logger.error("Caught exception while closing dictionary for
column: {}, continuing with error", column, e);
}
});
```
I prefer the explicit null check for the following reasons:
1. IMO, this is not as readable as the explicit null check
2. Internally it is doing the same null check
3. There is overhead of using functional programming APIs (we ran into
performance issues before), and it will always create unnecessary objects
----------------------------------------------------------------
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]