public class ZOrderByteUtils extends Object
All types except for String are stored within an 8 Byte Buffer
Most of these techniques are derived from https://aws.amazon.com/blogs/database/z-order-indexing-for-multifaceted-queries-in-amazon-dynamodb-part-2/
Modifier and Type | Field and Description |
---|---|
static byte[] |
NULL_BYTES |
static int |
PRIMITIVE_BUFFER_SIZE |
Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
byteTruncateOrFill(byte[] val,
int length,
ByteBuffer reuse)
Return a bytebuffer with the given bytes truncated to length, or filled with 0's to length
depending on whether the given bytes are larger or smaller than the given length.
|
static ByteBuffer |
doubleToOrderedBytes(double val,
ByteBuffer reuse)
Doubles are treated the same as floats in
floatToOrderedBytes(float, ByteBuffer) . |
static ByteBuffer |
floatToOrderedBytes(float val,
ByteBuffer reuse)
IEEE 754 : “If two floating-point numbers in the same format are ordered (say, x <
y), they are ordered the same way when their bits are reinterpreted as sign-magnitude
integers.”
|
static byte[] |
interleaveBits(byte[][] columnsBinary,
int interleavedSize) |
static byte[] |
interleaveBits(byte[][] columnsBinary,
int interleavedSize,
ByteBuffer reuse)
Interleave bits using a naive loop.
|
static ByteBuffer |
intToOrderedBytes(int val,
ByteBuffer reuse)
Signed ints do not have their bytes in magnitude order because of the sign bit.
|
static ByteBuffer |
longToOrderedBytes(long val,
ByteBuffer reuse)
Signed longs are treated the same as the signed ints in
intToOrderedBytes(int,
ByteBuffer) . |
static ByteBuffer |
reuse(ByteBuffer reuse,
int length) |
static ByteBuffer |
shortToOrderedBytes(short val,
ByteBuffer reuse)
Signed shorts are treated the same as the signed ints in
intToOrderedBytes(int,
ByteBuffer) . |
static ByteBuffer |
stringToOrderedBytes(String val,
int length,
ByteBuffer reuse)
Strings are lexicographically sortable BUT if different byte array lengths will ruin the
Z-Ordering.
|
static ByteBuffer |
tinyintToOrderedBytes(byte val,
ByteBuffer reuse)
Signed tiny ints are treated the same as the signed ints in
intToOrderedBytes(int,
ByteBuffer) . |
public static final int PRIMITIVE_BUFFER_SIZE
public static final byte[] NULL_BYTES
public static ByteBuffer intToOrderedBytes(int val, ByteBuffer reuse)
public static ByteBuffer longToOrderedBytes(long val, ByteBuffer reuse)
intToOrderedBytes(int,
ByteBuffer)
.public static ByteBuffer shortToOrderedBytes(short val, ByteBuffer reuse)
intToOrderedBytes(int,
ByteBuffer)
.public static ByteBuffer tinyintToOrderedBytes(byte val, ByteBuffer reuse)
intToOrderedBytes(int,
ByteBuffer)
.public static ByteBuffer floatToOrderedBytes(float val, ByteBuffer reuse)
Which means floats can be treated as sign magnitude integers which can then be converted into lexicographically comparable bytes.
public static ByteBuffer doubleToOrderedBytes(double val, ByteBuffer reuse)
floatToOrderedBytes(float, ByteBuffer)
.public static ByteBuffer stringToOrderedBytes(String val, int length, ByteBuffer reuse)
public static ByteBuffer byteTruncateOrFill(byte[] val, int length, ByteBuffer reuse)
public static byte[] interleaveBits(byte[][] columnsBinary, int interleavedSize)
public static byte[] interleaveBits(byte[][] columnsBinary, int interleavedSize, ByteBuffer reuse)
columnsBinary
- an array of ordered byte representations of the columns being ZOrderedinterleavedSize
- the number of bytes to use in the outputpublic static ByteBuffer reuse(ByteBuffer reuse, int length)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.