本文整理汇总了Java中org.apache.cassandra.cql3.QueryProcessor类的典型用法代码示例。如果您正苦于以下问题:Java QueryProcessor类的具体用法?Java QueryProcessor怎么用?Java QueryProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryProcessor类属于org.apache.cassandra.cql3包,在下文中一共展示了QueryProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParsingCQLOnCompoundedTable
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
@Test
public void testParsingCQLOnCompoundedTable() {
String cql = "CREATE TABLE keyspace1.compressed_bills (" +
" user text," +
" email text," +
" account_id text static," +
" balance int static," +
" expense_id int," +
" item_id int," +
" amount int," +
" name text," +
" PRIMARY KEY ((user, email), expense_id, item_id))";
ParsedStatement stmt = QueryProcessor.parseStatement(cql);
stmt.properties.properties.addProperty(CFProperties.KEYSPACE_NAME, "keyspace1");
stmt.properties.properties.addProperty(CFProperties.PARTITIONER_CLASS,
"org.apache.cassandra.dht.Murmur3Partitioner");
ParsedStatement.Prepared preparedStmt = stmt.prepare();
CFMetaData cfMetaData = ((CreateTableStatement) preparedStmt.statement).getCFMetaData();
Assert.assertEquals(cfMetaData.ksName, "keyspace1");
Assert.assertEquals(cfMetaData.partitioner, Murmur3Partitioner.instance);
}
示例2: parseSchema
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
/**
* Get the meta data (column definitions) for the target table.
*
* @param query The CREATE TABLE statement for the table the Json data should be put into.
* @return The table's meta data
*/
private static CFMetaData parseSchema(String query) {
try {
ClientState state = ClientState.forInternalCalls();
ParsedStatement.Prepared prepared = QueryProcessor.getStatement(query, state);
CQLStatement stmt = prepared.statement;
stmt.validate(state);
if (!stmt.getClass().equals(CreateTableStatement.class)) {
throw new IllegalArgumentException("Invalid query, must be a CREATE TABLE statement");
}
return CreateTableStatement.class.cast(stmt).getCFMetaData();
} catch (RequestValidationException | IllegalArgumentException e) {
throw new RuntimeException(e);
}
}
示例3: processPrepared
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
public ResultMessage processPrepared(CQLStatement statement,
QueryState state,
QueryOptions options,
Map<String, ByteBuffer> customPayload)
throws RequestExecutionException, RequestValidationException
{
if (customPayload != null)
requestPayload = customPayload;
ResultMessage result = QueryProcessor.instance.processPrepared(statement, state, options, customPayload);
if (customPayload != null)
{
result.setCustomPayload(responsePayload);
responsePayload = null;
}
return result;
}
示例4: testWriting
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
private static void testWriting() throws Exception
{
// do some writing.
for (int i = 0; i < 100; i++)
{
QueryProcessor.process(String.format("INSERT INTO %s.%s (id, name, value) VALUES ( 'key%d', 'colb', 'value%d')",
KEYSPACE,
COLUMN_FAMILY,
i,
i),
ConsistencyLevel.QUORUM);
System.out.println("wrote key" + i);
}
System.out.println("Done writing.");
}
示例5: processBatch
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
public ResultMessage processBatch(BatchStatement statement,
QueryState state,
BatchQueryOptions options,
Map<String, ByteBuffer> customPayload)
throws RequestExecutionException, RequestValidationException
{
if (customPayload != null)
requestPayload = customPayload;
ResultMessage result = QueryProcessor.instance.processBatch(statement, state, options, customPayload);
if (customPayload != null)
{
result.setCustomPayload(responsePayload);
responsePayload = null;
}
return result;
}
示例6: setupDefaultSuperuser
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
private static void setupDefaultSuperuser()
{
try
{
// insert a default superuser if AUTH_KS.USERS_CF is empty.
if (!hasExistingUsers())
{
QueryProcessor.process(String.format("INSERT INTO %s.%s (name, super) VALUES ('%s', %s) USING TIMESTAMP 0",
AUTH_KS,
USERS_CF,
DEFAULT_SUPERUSER_NAME,
true),
ConsistencyLevel.ONE);
logger.info("Created default superuser '{}'", DEFAULT_SUPERUSER_NAME);
}
}
catch (RequestExecutionException e)
{
logger.warn("Skipped default superuser setup: some nodes were not ready");
}
}
示例7: fromSchema
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
/**
* Deserialize only Keyspace attributes without nested ColumnFamilies
*
* @param row Keyspace attributes in serialized form
*
* @return deserialized keyspace without cf_defs
*/
public static KSMetaData fromSchema(Row row, Iterable<CFMetaData> cfms, UTMetaData userTypes)
{
UntypedResultSet.Row result = QueryProcessor.resultify("SELECT * FROM system.schema_keyspaces", row).one();
try
{
return new KSMetaData(result.getString("keyspace_name"),
AbstractReplicationStrategy.getClass(result.getString("strategy_class")),
fromJsonMap(result.getString("strategy_options")),
result.getBoolean("durable_writes"),
cfms,
userTypes);
}
catch (ConfigurationException e)
{
throw new RuntimeException(e);
}
}
示例8: compile
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
@VisibleForTesting
public static CFMetaData compile(String cql, String keyspace)
{
try
{
CFStatement parsed = (CFStatement)QueryProcessor.parseStatement(cql);
parsed.prepareKeyspace(keyspace);
CreateTableStatement statement = (CreateTableStatement) parsed.prepare().statement;
CFMetaData cfm = newSystemMetadata(keyspace, statement.columnFamily(), "", statement.comparator);
statement.applyPropertiesTo(cfm);
return cfm.rebuild();
}
catch (RequestValidationException e)
{
throw new RuntimeException(e);
}
}
示例9: testInvalidSearch
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
@Test
public void testInvalidSearch() throws IOException
{
Mutation rm;
rm = new Mutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k4"));
rm.add("Indexed1", Util.cellname("indexed"), ByteBufferUtil.bytes("foo"), 1);
rm.apply();
// test we can search:
UntypedResultSet result = QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'foo'");
assertEquals(1, result.size());
// test we can't search if the searcher doesn't validate the expression:
try
{
QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'invalid'");
fail("Query should have been invalid!");
}
catch (Exception e)
{
assertTrue(e instanceof InvalidRequestException || (e.getCause() != null && (e.getCause() instanceof InvalidRequestException)));
}
}
示例10: shouldImportCqlTable
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
@Test
/*
* The schema is
* CREATE TABLE cql_keyspace.table1 (k int PRIMARY KEY, v1 text, v2 int)
* */
public void shouldImportCqlTable() throws IOException, URISyntaxException
{
String cql_keyspace = "cql_keyspace";
String cql_table = "table1";
String jsonUrl = resourcePath("CQLTable.json");
File tempSS = tempSSTableFile(cql_keyspace, cql_table);
new SSTableImport(true).importJson(jsonUrl, cql_keyspace, cql_table, tempSS.getPath());
SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
Keyspace.open(cql_keyspace).getColumnFamilyStore(cql_table).addSSTable(reader);
UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s", cql_keyspace, cql_table));
assertThat(result.size(), is(2));
assertThat(result, hasItem(withElements(1, "NY", 1980)));
assertThat(result, hasItem(withElements(2, "CA", 2014)));
reader.selfRef().release();
}
示例11: testValidationCompactStorage
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
/**
* For CASSANDRA-6892 too, check that for a compact table with one cluster column, we can insert whatever
* we want as value for the clustering column, including something that would conflict with a CQL column definition.
*/
@Test
public void testValidationCompactStorage() throws Exception
{
QueryProcessor.process(String.format("CREATE TABLE \"%s\".test_compact_dynamic_columns (a int, b text, c text, PRIMARY KEY (a, b)) WITH COMPACT STORAGE", KEYSPACE), ConsistencyLevel.ONE);
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("test_compact_dynamic_columns");
QueryProcessor.executeInternal(String.format("INSERT INTO \"%s\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'a', 'foo')", KEYSPACE));
QueryProcessor.executeInternal(String.format("INSERT INTO \"%s\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'b', 'bar')", KEYSPACE));
QueryProcessor.executeInternal(String.format("INSERT INTO \"%s\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'c', 'boo')", KEYSPACE));
cfs.forceBlockingFlush();
CompactionManager.instance.performScrub(cfs, true, true, 2);
// Scrub is silent, but it will remove broken records. So reading everything back to make sure nothing to "scrubbed away"
UntypedResultSet rs = QueryProcessor.executeInternal(String.format("SELECT * FROM \"%s\".test_compact_dynamic_columns", KEYSPACE));
assertEquals(3, rs.size());
Iterator<UntypedResultSet.Row> iter = rs.iterator();
assertEquals("foo", iter.next().getString("c"));
assertEquals("bar", iter.next().getString("c"));
assertEquals("boo", iter.next().getString("c"));
}
示例12: testScrubColumnValidation
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
@Test
public void testScrubColumnValidation() throws InterruptedException, RequestExecutionException, ExecutionException
{
QueryProcessor.process(String.format("CREATE TABLE \"%s\".test_compact_static_columns (a bigint, b timeuuid, c boolean static, d text, PRIMARY KEY (a, b))", KEYSPACE), ConsistencyLevel.ONE);
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("test_compact_static_columns");
QueryProcessor.executeInternal(String.format("INSERT INTO \"%s\".test_compact_static_columns (a, b, c, d) VALUES (123, c3db07e8-b602-11e3-bc6b-e0b9a54a6d93, true, 'foobar')", KEYSPACE));
cfs.forceBlockingFlush();
CompactionManager.instance.performScrub(cfs, false, true, 2);
QueryProcessor.process("CREATE TABLE \"Keyspace1\".test_scrub_validation (a text primary key, b int)", ConsistencyLevel.ONE);
ColumnFamilyStore cfs2 = keyspace.getColumnFamilyStore("test_scrub_validation");
new Mutation(UpdateBuilder.create(cfs2.metadata, "key").newRow().add("b", LongType.instance.decompose(1L)).build()).apply();
cfs2.forceBlockingFlush();
CompactionManager.instance.performScrub(cfs2, false, false, 2);
}
示例13: execute
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
List<String> cqlVersions = new ArrayList<String>();
cqlVersions.add(QueryProcessor.CQL_VERSION.toString());
List<String> compressions = new ArrayList<String>();
if (FrameCompressor.SnappyCompressor.instance != null)
compressions.add("snappy");
// LZ4 is always available since worst case scenario it default to a pure JAVA implem.
compressions.add("lz4");
Map<String, List<String>> supported = new HashMap<String, List<String>>();
supported.put(StartupMessage.CQL_VERSION, cqlVersions);
supported.put(StartupMessage.COMPRESSION, compressions);
return new SupportedMessage(supported);
}
示例14: fromSchema
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
/**
* Deserialize only Keyspace attributes without nested ColumnFamilies
*
* @param row Keyspace attributes in serialized form
*
* @return deserialized keyspace without cf_defs
*/
public static KSMetaData fromSchema(Row row, Iterable<CFMetaData> cfms)
{
UntypedResultSet.Row result = QueryProcessor.resultify("SELECT * FROM system.schema_keyspaces", row).one();
try
{
return new KSMetaData(result.getString("keyspace_name"),
AbstractReplicationStrategy.getClass(result.getString("strategy_class")),
fromJsonMap(result.getString("strategy_options")),
result.getBoolean("durable_writes"),
cfms);
}
catch (ConfigurationException e)
{
throw new RuntimeException(e);
}
}
示例15: migrateLegacyHints
import org.apache.cassandra.cql3.QueryProcessor; //导入依赖的package包/类
private void migrateLegacyHints(UUID hostId, ByteBuffer buffer)
{
String query = String.format("SELECT target_id, hint_id, message_version, mutation, ttl(mutation) AS ttl, writeTime(mutation) AS write_time " +
"FROM %s.%s " +
"WHERE target_id = ?",
SystemKeyspace.NAME,
SystemKeyspace.LEGACY_HINTS);
// read all the old hints (paged iterator), write them in the new format
UntypedResultSet rows = QueryProcessor.executeInternalWithPaging(query, pageSize, hostId);
migrateLegacyHints(hostId, rows, buffer);
// delete the whole partition in the legacy table; we would truncate the whole table afterwards, but this allows
// to not lose progress in case of a terminated conversion
deleteLegacyHintsPartition(hostId);
}