Search in sources :

Example 1 with ProtocolVersion

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);
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) ByteBuffer(java.nio.ByteBuffer)

Example 2 with ProtocolVersion

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);
        }
    };
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) ByteBuffer(java.nio.ByteBuffer)

Example 3 with ProtocolVersion

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);
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion)

Example 4 with ProtocolVersion

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);
        }
    }
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Test(org.junit.Test)

Example 5 with ProtocolVersion

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);
        }
    }
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion)

Aggregations

ProtocolVersion (org.apache.cassandra.transport.ProtocolVersion)33 Test (org.junit.Test)22 ByteBuffer (java.nio.ByteBuffer)11 List (java.util.List)6 TreeMap (java.util.TreeMap)5 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)4 Row (com.datastax.driver.core.Row)3 Unpooled (io.netty.buffer.Unpooled)3 Collections (java.util.Collections)3 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)3 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)3 RollCycles (net.openhft.chronicle.queue.RollCycles)3 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)3 ValueIn (net.openhft.chronicle.wire.ValueIn)3 QueryOptions (org.apache.cassandra.cql3.QueryOptions)3 TupleType (com.datastax.driver.core.TupleType)2 TupleValue (com.datastax.driver.core.TupleValue)2 UDTValue (com.datastax.driver.core.UDTValue)2 Path (java.nio.file.Path)2