use of org.apache.cassandra.cql3.statements.BatchStatement.Type in project cassandra by apache.
the class UFJavaTest method testJavaFunction.
@Test
public void testJavaFunction() throws Throwable {
createTable("CREATE TABLE %s (key int primary key, val double)");
String functionBody = '\n' + " // parameter val is of type java.lang.Double\n" + " /* return type is of type java.lang.Double */\n" + " if (val == null) {\n" + " return null;\n" + " }\n" + " return Math.sin(val);\n";
String fName = createFunction(KEYSPACE, "double", "CREATE OR REPLACE FUNCTION %s(val double) " + "CALLED ON NULL INPUT " + "RETURNS double " + "LANGUAGE JAVA " + "AS '" + functionBody + "';");
FunctionName fNameName = parseFunctionName(fName);
assertRows(execute("SELECT language, body FROM system_schema.functions WHERE keyspace_name=? AND function_name=?", fNameName.keyspace, fNameName.name), row("java", functionBody));
execute("INSERT INTO %s (key, val) VALUES (?, ?)", 1, 1d);
execute("INSERT INTO %s (key, val) VALUES (?, ?)", 2, 2d);
execute("INSERT INTO %s (key, val) VALUES (?, ?)", 3, 3d);
assertRows(execute("SELECT key, val, " + fName + "(val) FROM %s"), row(1, 1d, Math.sin(1d)), row(2, 2d, Math.sin(2d)), row(3, 3d, Math.sin(3d)));
}
use of org.apache.cassandra.cql3.statements.BatchStatement.Type in project cassandra by apache.
the class SecondaryIndexTest method assertColumnValue.
private static void assertColumnValue(int expected, String name, Row row, TableMetadata cfm) {
ColumnMetadata col = cfm.getColumn(new ColumnIdentifier(name, true));
AbstractType<?> type = col.type;
assertEquals(expected, type.compose(row.getCell(col).buffer()));
}
use of org.apache.cassandra.cql3.statements.BatchStatement.Type in project cassandra by apache.
the class FullQueryLoggerTest method assertRoundTripQuery.
private void assertRoundTripQuery(@Nullable String keyspace) {
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.readDocument(wire -> {
assertEquals(0, wire.read(VERSION).int16());
assertEquals(SINGLE_QUERY, wire.read(TYPE).text());
assertEquals(1L, wire.read(QUERY_START_TIME).int64());
ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32(), true);
assertEquals(ProtocolVersion.CURRENT, protocolVersion);
QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wire.read(QUERY_OPTIONS).bytes()), protocolVersion);
compareQueryOptions(QueryOptions.DEFAULT, queryOptions);
String wireKeyspace = wire.read(FullQueryLogger.KEYSPACE).text();
assertEquals(keyspace, wireKeyspace);
assertEquals("foo", wire.read(QUERY).text());
}));
}
}
use of org.apache.cassandra.cql3.statements.BatchStatement.Type in project cassandra by apache.
the class FullQueryLoggerTest method assertRoundTripBatch.
private void assertRoundTripBatch(@Nullable String keyspace) {
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.readDocument(wire -> {
assertEquals(0, wire.read(VERSION).int16());
assertEquals(BATCH, wire.read(TYPE).text());
assertEquals(1L, wire.read(QUERY_START_TIME).int64());
ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32(), true);
assertEquals(ProtocolVersion.CURRENT, protocolVersion);
QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wire.read(QUERY_OPTIONS).bytes()), protocolVersion);
compareQueryOptions(QueryOptions.DEFAULT, queryOptions);
assertEquals(Long.MIN_VALUE, wire.read(GENERATED_TIMESTAMP).int64());
assertEquals(Integer.MIN_VALUE, wire.read(GENERATED_NOW_IN_SECONDS).int32());
assertEquals(keyspace, wire.read(FullQueryLogger.KEYSPACE).text());
assertEquals("UNLOGGED", wire.read(BATCH_TYPE).text());
ValueIn in = wire.read(QUERIES);
assertEquals(2, in.int32());
assertEquals("foo1", in.text());
assertEquals("foo2", in.text());
in = wire.read(VALUES);
assertEquals(2, in.int32());
assertEquals(2, in.int32());
assertTrue(Arrays.equals(new byte[1], in.bytes()));
assertTrue(Arrays.equals(new byte[2], in.bytes()));
assertEquals(0, in.int32());
}));
}
}
use of org.apache.cassandra.cql3.statements.BatchStatement.Type in project cassandra by apache.
the class CollectionTypesTest method testSerializationDeserialization.
static <CT extends CollectionType, T> void testSerializationDeserialization(TypeFactory<CT> typeFactory, ValueFactory<T> valueFactory, ValueGenerator keyType) {
for (ValueGenerator valueType : ValueGenerator.GENERATORS) {
CT type = typeFactory.createType(keyType != null ? keyType.getType() : null, valueType.getType());
CQL3Type.Collection cql3Type = new CQL3Type.Collection(type);
for (int i = 0; i < 500; i++) {
Random random = new Random(i);
int size = random.nextInt(1000);
T expected = valueFactory.createValue(keyType, valueType, size, random);
for (ValueAccessor<Object> srcAccessor : ACCESSORS) {
ByteBuffer srcBuffer = type.decompose(expected);
Object srcBytes = srcAccessor.convert(srcBuffer, ByteBufferAccessor.instance);
String srcString = type.getString(srcBytes, srcAccessor);
for (ValueAccessor<Object> dstAccessor : ACCESSORS) {
Object dstBytes = dstAccessor.convert(srcBytes, srcAccessor);
String dstString = type.getString(dstBytes, dstAccessor);
T composed = (T) type.compose(dstBytes, dstAccessor);
Assert.assertEquals(expected, composed);
ValueAccessors.assertDataEquals(srcBytes, srcAccessor, dstBytes, dstAccessor);
Assert.assertEquals(srcString, dstString);
}
}
}
}
}
Aggregations