maedhroz commented on code in PR #2409:
URL: https://github.com/apache/cassandra/pull/2409#discussion_r1227304071
##########
src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java:
##########
@@ -186,9 +204,38 @@ public static ByteSource asComparableBytes(ByteBuffer
value, AbstractType<?> typ
{
if (type instanceof InetAddressType || type instanceof IntegerType ||
type instanceof DecimalType)
return ByteSource.optionalFixedLength(ByteBufferAccessor.instance,
value);
+ // The LongType.asComparableBytes uses variableLengthInteger which
doesn't play well with
+ // the KDTree because it is expecting fixed length data. So for SAI we
use a optionalSignedFixedLengthNumber
+ // to keep all comparable values the same length
+ else if (type instanceof LongType)
+ return
ByteSource.optionalSignedFixedLengthNumber(ByteBufferAccessor.instance, value);
return type.asComparableBytes(value, version);
}
+ /**
+ * Fills a byte array with the comparable bytes for a type.
+ * <p>
+ * This method expects a {@code value} parameter generated by calling
{@link #asIndexBytes(ByteBuffer, AbstractType)}.
+ * It is not generally safe to pass the output of other serialization
methods to this method. For instance, it is
+ * not generally safe to pass the output of {@link
AbstractType#decompose(Object)} as the {@code value} parameter
+ * (there are certain types for which this is technically OK, but that
doesn't hold for all types).
+ *
+ * @param value a value buffer returned by {@link
#asIndexBytes(ByteBuffer, AbstractType)}
+ * @param type the type associated with the encoded {@code value} parameter
+ * @param bytes this method's output
+ */
+ public static void toComparableBytes(ByteBuffer value, AbstractType<?>
type, byte[] bytes)
+ {
+ if (isInetAddress(type))
+ ByteBufferUtil.copyBytes(value, value.hasArray() ?
value.arrayOffset() + value.position() : value.position(), bytes, 0, 16);
+ else if (isBigInteger(type))
+ ByteBufferUtil.copyBytes(value, value.hasArray() ?
value.arrayOffset() + value.position() : value.position(), bytes, 0, 20);
Review Comment:
nit: Replace the magic 20 and 16 w/ named constants like
`DECIMAL_APPROXIMATION_BYTES`
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]