use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.
the class MapType method compareMaps.
public static int compareMaps(AbstractType<?> keysComparator, AbstractType<?> valuesComparator, ByteBuffer o1, ByteBuffer o2) {
if (!o1.hasRemaining() || !o2.hasRemaining())
return o1.hasRemaining() ? 1 : o2.hasRemaining() ? -1 : 0;
ByteBuffer bb1 = o1.duplicate();
ByteBuffer bb2 = o2.duplicate();
ProtocolVersion protocolVersion = ProtocolVersion.V3;
int size1 = CollectionSerializer.readCollectionSize(bb1, protocolVersion);
int size2 = CollectionSerializer.readCollectionSize(bb2, protocolVersion);
for (int i = 0; i < Math.min(size1, size2); i++) {
ByteBuffer k1 = CollectionSerializer.readValue(bb1, protocolVersion);
ByteBuffer k2 = CollectionSerializer.readValue(bb2, protocolVersion);
int cmp = keysComparator.compare(k1, k2);
if (cmp != 0)
return cmp;
ByteBuffer v1 = CollectionSerializer.readValue(bb1, protocolVersion);
ByteBuffer v2 = CollectionSerializer.readValue(bb2, protocolVersion);
cmp = valuesComparator.compare(v1, v2);
if (cmp != 0)
return cmp;
}
return size1 == size2 ? 0 : (size1 < size2 ? -1 : 1);
}
use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.
the class TimeFcts method toTimestamp.
/**
* Creates a function that convert a value of the specified type into a <code>TIMESTAMP</code>.
* @param type the temporal type
* @return a function that convert a value of the specified type into a <code>TIMESTAMP</code>.
*/
public static final NativeScalarFunction toTimestamp(final TemporalType<?> type) {
return new NativeScalarFunction("totimestamp", TimestampType.instance, type) {
public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) {
ByteBuffer bb = parameters.get(0);
if (bb == null || !bb.hasRemaining())
return null;
long millis = type.toTimeInMillis(bb);
return TimestampType.instance.fromTimeInMillis(millis);
}
};
}
use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.
the class MapType method compareMaps.
public static <TL, TR> int compareMaps(AbstractType<?> keysComparator, AbstractType<?> valuesComparator, TL left, ValueAccessor<TL> accessorL, TR right, ValueAccessor<TR> accessorR) {
if (accessorL.isEmpty(left) || accessorR.isEmpty(right))
return Boolean.compare(accessorR.isEmpty(right), accessorL.isEmpty(left));
ProtocolVersion protocolVersion = ProtocolVersion.V3;
int sizeL = CollectionSerializer.readCollectionSize(left, accessorL, protocolVersion);
int sizeR = CollectionSerializer.readCollectionSize(right, accessorR, protocolVersion);
int offsetL = CollectionSerializer.sizeOfCollectionSize(sizeL, protocolVersion);
int offsetR = CollectionSerializer.sizeOfCollectionSize(sizeR, protocolVersion);
for (int i = 0; i < Math.min(sizeL, sizeR); i++) {
TL k1 = CollectionSerializer.readValue(left, accessorL, offsetL, protocolVersion);
offsetL += CollectionSerializer.sizeOfValue(k1, accessorL, protocolVersion);
TR k2 = CollectionSerializer.readValue(right, accessorR, offsetR, protocolVersion);
offsetR += CollectionSerializer.sizeOfValue(k2, accessorR, protocolVersion);
int cmp = keysComparator.compare(k1, accessorL, k2, accessorR);
if (cmp != 0)
return cmp;
TL v1 = CollectionSerializer.readValue(left, accessorL, offsetL, protocolVersion);
offsetL += CollectionSerializer.sizeOfValue(v1, accessorL, protocolVersion);
TR v2 = CollectionSerializer.readValue(right, accessorR, offsetR, protocolVersion);
offsetR += CollectionSerializer.sizeOfValue(v2, accessorR, protocolVersion);
cmp = valuesComparator.compare(v1, accessorL, v2, accessorR);
if (cmp != 0)
return cmp;
}
return sizeL == sizeR ? 0 : (sizeL < sizeR ? -1 : 1);
}
use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.
the class CQL3TypeLiteralTest method testCollectionWithNatives.
@Test
public void testCollectionWithNatives() {
for (ProtocolVersion version : ProtocolVersion.SUPPORTED) {
for (int n = 0; n < 100; n++) {
Value value = generateCollectionValue(version, randomCollectionType(0), true);
compareCqlLiteral(version, value);
}
}
}
use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.
the class CQLTester method checkProtocolVersion.
private static void checkProtocolVersion() {
// The latest versions might not be supported yet by the java driver
for (ProtocolVersion version : ProtocolVersion.SUPPORTED) {
try {
com.datastax.driver.core.ProtocolVersion.fromInt(version.asInt());
PROTOCOL_VERSIONS.add(version);
} catch (IllegalArgumentException e) {
logger.warn("Protocol Version {} not supported by java driver", version);
}
}
}
Aggregations