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);
}
};
}
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++;
}
};
}
};
}
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);
}
}
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);
}
}
}
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);
}
}
}
Aggregations