use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class SASICQLTest method testNonLiteralStringCompare.
/**
* Tests query condition '>' on string columns with is_literal=false.
*/
@Test
public void testNonLiteralStringCompare() throws Throwable {
for (String mode : new String[] { "PREFIX", "CONTAINS", "SPARSE" }) {
for (boolean forceFlush : new boolean[] { false, true }) {
try {
createTable("CREATE TABLE %s (pk int primary key, v text);");
createIndex(String.format("CREATE CUSTOM INDEX ON %%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'is_literal': 'false', 'mode': '%s'};", mode));
execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 0, "a");
execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 1, "abc");
execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 2, "ac");
flush(forceFlush);
Session session = sessionNet();
SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v = 'ab'");
stmt.setFetchSize(5);
List<Row> rs = session.execute(stmt).all();
Assert.assertEquals(0, rs.size());
try {
sessionNet();
stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v > 'ab'");
stmt.setFetchSize(5);
rs = session.execute(stmt).all();
Assert.assertFalse("CONTAINS mode on non-literal string type should not support RANGE operators", "CONTAINS".equals(mode));
Assert.assertEquals(2, rs.size());
Assert.assertEquals(1, rs.get(0).getInt("pk"));
} catch (InvalidQueryException ex) {
if (!"CONTAINS".equals(mode))
throw ex;
}
} catch (Throwable th) {
throw new AssertionError(String.format("Failure with mode:%s and flush:%s ", mode, forceFlush), th);
}
}
}
}
use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class SASICQLTest method testPaging.
@Test
public void testPaging() throws Throwable {
for (boolean forceFlush : new boolean[] { false, true }) {
createTable("CREATE TABLE %s (pk int primary key, v int);");
createIndex("CREATE CUSTOM INDEX ON %s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex';");
for (int i = 0; i < 10; i++) execute("INSERT INTO %s (pk, v) VALUES (?, ?);", i, 1);
flush(forceFlush);
Session session = sessionNet();
SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v = 1");
stmt.setFetchSize(5);
List<Row> rs = session.execute(stmt).all();
Assert.assertEquals(10, rs.size());
Assert.assertEquals(Sets.newHashSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), rs.stream().map((i) -> i.getInt("pk")).collect(Collectors.toSet()));
}
}
use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class JMXCompatabilityTest method setupStandardTables.
private void setupStandardTables() throws Throwable {
if (CREATED_TABLE)
return;
// force loading mbean which CassandraDaemon creates
GCInspector.register();
CassandraDaemon.registerNativeAccess();
String name = KEYSPACE + "." + createTable("CREATE TABLE %s (pk int PRIMARY KEY)");
// use net to register everything like storage proxy
executeNet(ProtocolVersion.CURRENT, new SimpleStatement("INSERT INTO " + name + " (pk) VALUES (?)", 42));
executeNet(ProtocolVersion.CURRENT, new SimpleStatement("SELECT * FROM " + name + " WHERE pk=?", 42));
String script = "tools/bin/jmxtool dump -f yaml --url service:jmx:rmi:///jndi/rmi://" + jmxHost + ":" + jmxPort + "/jmxrmi > " + TMP.getRoot().getAbsolutePath() + "/out.yaml";
ToolRunner.invoke("bash", "-c", script).assertOnCleanExit();
CREATED_TABLE = true;
}
use of com.datastax.driver.core.SimpleStatement in project gora by apache.
the class NativeSerializer method updateByQuery.
/**
* {@inheritDoc}
*
* @param query
* @return
*/
@Override
public boolean updateByQuery(Query query) {
List<Object> objectArrayList = new ArrayList<>();
String cqlQuery = CassandraQueryFactory.getUpdateByQueryForNative(mapping, query, objectArrayList);
ResultSet results;
SimpleStatement statement;
if (objectArrayList.size() == 0) {
statement = new SimpleStatement(cqlQuery);
} else {
statement = new SimpleStatement(cqlQuery, objectArrayList.toArray());
}
if (writeConsistencyLevel != null) {
statement.setConsistencyLevel(ConsistencyLevel.valueOf(writeConsistencyLevel));
}
results = client.getSession().execute(statement);
return results.wasApplied();
}
use of com.datastax.driver.core.SimpleStatement in project gora by apache.
the class NativeSerializer method get.
/**
* {@inheritDoc}
*
* @param key
* @param fields
* @return
*/
@Override
public Persistent get(Object key, String[] fields) {
if (fields == null) {
fields = getFields();
}
String cqlQuery = CassandraQueryFactory.getSelectObjectWithFieldsQuery(mapping, fields);
SimpleStatement statement = new SimpleStatement(cqlQuery, key);
if (readConsistencyLevel != null) {
statement.setConsistencyLevel(ConsistencyLevel.valueOf(readConsistencyLevel));
}
ResultSet results = client.getSession().execute(statement);
Result<T> objects = mapper.map(results);
List<T> objectList = objects.all();
if (objectList != null) {
LOG.debug("Object is found for key : {}", key);
return objectList.get(0);
}
LOG.debug("Object is not found for key : {}", key);
return null;
}
Aggregations