Search in sources :

Example 11 with ProtocolVersion

use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.

the class TimeFcts method toDate.

/**
    * Creates a function that convert a value of the specified type into a <code>DATE</code>.
    * @param type the temporal type
    * @return a function that convert a value of the specified type into a <code>DATE</code>.
    */
public static final NativeScalarFunction toDate(final TemporalType<?> type) {
    return new NativeScalarFunction("todate", SimpleDateType.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 SimpleDateType.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 12 with ProtocolVersion

use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.

the class AggregateFcts method makeCountFunction.

/**
     * Creates a COUNT function for the specified type.
     *
     * @param inputType the function input type
     * @return a COUNT function for the specified type.
     */
public static AggregateFunction makeCountFunction(AbstractType<?> inputType) {
    return new NativeAggregateFunction("count", LongType.instance, inputType) {

        public Aggregate newAggregate() {
            return new Aggregate() {

                private long count;

                public void reset() {
                    count = 0;
                }

                public ByteBuffer compute(ProtocolVersion protocolVersion) {
                    return ((LongType) returnType()).decompose(count);
                }

                public void addInput(ProtocolVersion protocolVersion, List<ByteBuffer> values) {
                    ByteBuffer value = values.get(0);
                    if (value == null)
                        return;
                    count++;
                }
            };
        }
    };
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) ByteBuffer(java.nio.ByteBuffer)

Example 13 with ProtocolVersion

use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.

the class CQLTester method requireNetwork.

// lazy initialization for all tests that require Java Driver
protected static void requireNetwork() throws ConfigurationException {
    if (server != null)
        return;
    SystemKeyspace.finishStartup();
    StorageService.instance.initServer();
    SchemaLoader.startGossiper();
    server = new Server.Builder().withHost(nativeAddr).withPort(nativePort).build();
    server.start();
    for (ProtocolVersion version : PROTOCOL_VERSIONS) {
        if (clusters.containsKey(version))
            continue;
        Cluster cluster = Cluster.builder().addContactPoints(nativeAddr).withClusterName("Test Cluster").withPort(nativePort).withProtocolVersion(com.datastax.driver.core.ProtocolVersion.fromInt(version.asInt())).build();
        clusters.put(version, cluster);
        sessions.put(version, cluster.connect());
        logger.info("Started Java Driver instance for protocol version {}", version);
    }
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion)

Example 14 with ProtocolVersion

use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.

the class CQL3TypeLiteralTest method testNested.

@Test
public void testNested() {
    for (ProtocolVersion version : ProtocolVersion.SUPPORTED) {
        for (int n = 0; n < 100; n++) {
            Value value = randomNested(version);
            compareCqlLiteral(version, value);
        }
    }
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Test(org.junit.Test)

Example 15 with ProtocolVersion

use of org.apache.cassandra.transport.ProtocolVersion in project cassandra by apache.

the class CQL3TypeLiteralTest method testUserDefinedWithNatives.

@Test
public void testUserDefinedWithNatives() {
    for (ProtocolVersion version : ProtocolVersion.SUPPORTED) {
        for (int n = 0; n < 100; n++) {
            Value value = generateUserDefinedValue(version, randomUserType(0), true);
            compareCqlLiteral(version, value);
        }
    }
}
Also used : ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Test(org.junit.Test)

Aggregations

ProtocolVersion (org.apache.cassandra.transport.ProtocolVersion)22 Test (org.junit.Test)15 ByteBuffer (java.nio.ByteBuffer)7 TreeMap (java.util.TreeMap)5 TreeSet (java.util.TreeSet)5 Row (com.datastax.driver.core.Row)3 List (java.util.List)3 TupleType (com.datastax.driver.core.TupleType)2 TupleValue (com.datastax.driver.core.TupleValue)2 UDTValue (com.datastax.driver.core.UDTValue)2 ImmutableList (com.google.common.collect.ImmutableList)2 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)1 BigInteger (java.math.BigInteger)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 MultiItemTerminal (org.apache.cassandra.cql3.Term.MultiItemTerminal)1 Terminal (org.apache.cassandra.cql3.Term.Terminal)1 Function (org.apache.cassandra.cql3.functions.Function)1 org.apache.cassandra.db.marshal (org.apache.cassandra.db.marshal)1