Jackie-Jiang commented on a change in pull request #4622: Standardize the
Dictionary interface, ensure the BYTES support
URL: https://github.com/apache/incubator-pinot/pull/4622#discussion_r327867943
##########
File path:
pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOffHeapMutableDictionary.java
##########
@@ -53,102 +53,148 @@ public BytesOffHeapMutableDictionary(int
estimatedCardinality, int maxOverflowHa
}
@Override
- public int indexOf(Object rawValue) {
- byte[] bytes = BytesUtils.toBytes(rawValue);
- return getDictId(new ByteArray(bytes), bytes);
+ public int index(Object value) {
+ byte[] bytesValue = (byte[]) value;
+ updateMinMax(bytesValue);
+ return indexValue(new ByteArray(bytesValue), bytesValue);
}
@Override
- public byte[] get(int dictId) {
- return getBytesValue(dictId);
+ public int[] index(Object[] values) {
+ throw new UnsupportedOperationException();
}
@Override
- public String getStringValue(int dictId) {
- return BytesUtils.toHexString(getBytesValue(dictId));
+ public int compare(int dictId1, int dictId2) {
+ return ByteArray.compare(getBytesValue(dictId1), getBytesValue(dictId2));
}
@Override
- public byte[] getBytesValue(int dictId) {
- return _byteStore.get(dictId);
+ public IntSet getDictIdsInRange(String lower, String upper, boolean
includeLower, boolean includeUpper) {
+ int numValues = length();
+ if (numValues == 0) {
+ return IntSets.EMPTY_SET;
+ }
+ IntSet dictIds = new IntOpenHashSet();
+
+ byte[] lowerValue;
+ if (lower.equals(RangePredicate.UNBOUNDED)) {
+ lowerValue = _min;
+ } else {
+ lowerValue = BytesUtils.toBytes(lower);
+ }
+ byte[] upperValue;
+ if (upper.equals(RangePredicate.UNBOUNDED)) {
+ upperValue = _max;
+ } else {
+ upperValue = BytesUtils.toBytes(upper);
+ }
+
+ if (includeLower && includeUpper) {
+ for (int dictId = 0; dictId < numValues; dictId++) {
+ byte[] value = getBytesValue(dictId);
+ if (ByteArray.compare(value, lowerValue) >= 0 &&
ByteArray.compare(value, upperValue) <= 0) {
+ dictIds.add(dictId);
+ }
+ }
+ } else if (includeLower) {
+ for (int dictId = 0; dictId < numValues; dictId++) {
+ byte[] value = getBytesValue(dictId);
+ if (ByteArray.compare(value, lowerValue) >= 0 &&
ByteArray.compare(value, upperValue) < 0) {
+ dictIds.add(dictId);
+ }
+ }
+ } else if (includeUpper) {
+ for (int dictId = 0; dictId < numValues; dictId++) {
+ byte[] value = getBytesValue(dictId);
+ if (ByteArray.compare(value, lowerValue) > 0 &&
ByteArray.compare(value, upperValue) <= 0) {
+ dictIds.add(dictId);
+ }
+ }
+ } else {
+ for (int dictId = 0; dictId < numValues; dictId++) {
+ byte[] value = getBytesValue(dictId);
+ if (ByteArray.compare(value, lowerValue) > 0 &&
ByteArray.compare(value, upperValue) < 0) {
+ dictIds.add(dictId);
+ }
+ }
+ }
+
+ return dictIds;
}
@Override
- public void doClose()
- throws IOException {
- _byteStore.close();
+ public ByteArray getMinVal() {
+ return new ByteArray(_min);
}
@Override
- protected void setRawValueAt(int dictId, Object rawValue, byte[]
serializedValue) {
- _byteStore.add(serializedValue);
+ public ByteArray getMaxVal() {
+ return new ByteArray(_max);
}
@Override
- public void index(@Nonnull Object rawValue) {
- byte[] bytes = BytesUtils.toBytes(rawValue);
- ByteArray byteArray = new ByteArray(bytes);
- indexValue(byteArray, bytes);
- updateMinMax(byteArray);
+ public ByteArray[] getSortedValues() {
+ int numValues = length();
+ ByteArray[] sortedValues = new ByteArray[numValues];
+
+ for (int dictId = 0; dictId < numValues; dictId++) {
+ sortedValues[dictId] = new ByteArray(getBytesValue(dictId));
+ }
+
+ Arrays.sort(sortedValues);
+ return sortedValues;
}
@Override
- public boolean inRange(@Nonnull String lower, @Nonnull String upper, int
dictIdToCompare, boolean includeLower,
- boolean includeUpper) {
- return valueInRange(new ByteArray(BytesUtils.toBytes(lower)), new
ByteArray(BytesUtils.toBytes(upper)),
- includeLower, includeUpper, new
ByteArray(getBytesValue(dictIdToCompare)));
+ public int indexOf(String stringValue) {
+ byte[] bytesValue = BytesUtils.toBytes(stringValue);
+ return getDictId(new ByteArray(bytesValue), bytesValue);
Review comment:
I need both byte[] and ByteArray, so I only fetched the byte[]
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]