You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2019/03/30 01:39:33 UTC
[incubator-pinot] 01/01: Use hex string as the representation of
byte array for queries
This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch hex_string_for_byte_array
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit 0a7f4bf17662a7d801c07c88b05b00d31cf04be5
Author: Xiang Fu <fx...@gmail.com>
AuthorDate: Fri Mar 29 18:39:17 2019 -0700
Use hex string as the representation of byte array for queries
---
.../dictionary/BytesOffHeapMutableDictionary.java | 17 +++++++++++++++--
.../dictionary/BytesOnHeapMutableDictionary.java | 21 +++++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOffHeapMutableDictionary.java b/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOffHeapMutableDictionary.java
index 816e0de..fd0964e 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOffHeapMutableDictionary.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOffHeapMutableDictionary.java
@@ -21,6 +21,7 @@ package org.apache.pinot.core.realtime.impl.dictionary;
import java.io.IOException;
import java.util.Arrays;
import javax.annotation.Nonnull;
+import javax.xml.bind.DatatypeConverter;
import org.apache.pinot.common.utils.primitive.ByteArray;
import org.apache.pinot.core.io.readerwriter.PinotDataBufferMemoryManager;
import org.apache.pinot.core.io.writer.impl.MutableOffHeapByteArrayStore;
@@ -53,7 +54,13 @@ public class BytesOffHeapMutableDictionary extends BaseOffHeapMutableDictionary
@Override
public int indexOf(Object rawValue) {
assert rawValue instanceof byte[];
- byte[] bytes = (byte[]) rawValue;
+ byte[] bytes;
+ // Convert hex string to byte[].
+ if (rawValue instanceof String) {
+ bytes = DatatypeConverter.parseHexBinary((String) rawValue);
+ } else {
+ bytes = (byte[]) rawValue;
+ }
return getDictId(new ByteArray(bytes), bytes);
}
@@ -81,7 +88,13 @@ public class BytesOffHeapMutableDictionary extends BaseOffHeapMutableDictionary
@Override
public void index(@Nonnull Object rawValue) {
assert rawValue instanceof byte[];
- byte[] bytes = (byte[]) rawValue;
+ byte[] bytes;
+ // Convert hex string to byte[].
+ if (rawValue instanceof String) {
+ bytes = DatatypeConverter.parseHexBinary((String) rawValue);
+ } else {
+ bytes = (byte[]) rawValue;
+ }
ByteArray byteArray = new ByteArray(bytes);
indexValue(byteArray, bytes);
updateMinMax(byteArray);
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOnHeapMutableDictionary.java b/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOnHeapMutableDictionary.java
index df36098..9dbee55 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOnHeapMutableDictionary.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/realtime/impl/dictionary/BytesOnHeapMutableDictionary.java
@@ -18,8 +18,10 @@
*/
package org.apache.pinot.core.realtime.impl.dictionary;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import javax.annotation.Nonnull;
+import javax.xml.bind.DatatypeConverter;
import org.apache.pinot.common.utils.primitive.ByteArray;
@@ -27,13 +29,21 @@ import org.apache.pinot.common.utils.primitive.ByteArray;
* OnHeap mutable dictionary of Bytes type.
*/
public class BytesOnHeapMutableDictionary extends BaseOnHeapMutableDictionary {
+
private ByteArray _min = null;
private ByteArray _max = null;
@Override
public int indexOf(Object rawValue) {
assert rawValue instanceof byte[];
- return getDictId(new ByteArray((byte[]) rawValue));
+ byte[] bytes;
+ // Convert hex string to byte[].
+ if (rawValue instanceof String) {
+ bytes = DatatypeConverter.parseHexBinary((String) rawValue);
+ } else {
+ bytes = (byte[]) rawValue;
+ }
+ return getDictId(new ByteArray(bytes));
}
@Override
@@ -49,7 +59,14 @@ public class BytesOnHeapMutableDictionary extends BaseOnHeapMutableDictionary {
@Override
public void index(@Nonnull Object rawValue) {
assert rawValue instanceof byte[];
- ByteArray byteArray = new ByteArray((byte[]) rawValue);
+ byte[] bytes;
+ // Convert hex string to byte[].
+ if (rawValue instanceof String) {
+ bytes = DatatypeConverter.parseHexBinary((String) rawValue);
+ } else {
+ bytes = (byte[]) rawValue;
+ }
+ ByteArray byteArray = new ByteArray(bytes);
indexValue(byteArray);
updateMinMax(byteArray);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org