本文整理汇总了Java中org.apache.cassandra.cql3.QueryProcessor.parseStatement方法的典型用法代码示例。如果您正苦于以下问题:Java QueryProcessor.parseStatement方法的具体用法?Java QueryProcessor.parseStatement怎么用?Java QueryProcessor.parseStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.cql3.QueryProcessor
的用法示例。
在下文中一共展示了QueryProcessor.parseStatement方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getQuery
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public Query getQuery(String command) throws Exception {
SelectStatement.RawStatement statement = (SelectStatement.RawStatement) QueryProcessor.parseStatement(command);
if (statement.columnFamily().matches("sstables?")) {
if (sstables.isEmpty()) {
return null;
}
metadata = CassandraUtils.tableFromBestSource(sstables.iterator().next());
return new Query(command, sstables, metadata);
} else {
File path = new File(statement.columnFamily());
if (!path.exists()) {
throw new FileNotFoundException(path.getAbsolutePath());
}
metadata = CassandraUtils.tableFromBestSource(path);
return new Query(command, Collections.singleton(path), metadata);
}
}
示例3: 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);
}
}
示例4: compile
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public static CFMetaData compile(String cql, String keyspace, IPartitioner partitioner)
{
CFStatement parsed = (CFStatement) QueryProcessor.parseStatement(cql);
parsed.properties.properties.addProperty(CFProperties.KEYSPACE_NAME, keyspace);
CreateTableStatement statement = (CreateTableStatement) parsed.prepare().statement;
return statement.metadataBuilder()
.withId(generateLegacyCfId(keyspace, statement.columnFamily()))
.withPartitioner(partitioner)
.build()
.params(statement.params());
}
示例5: tableFromCQL
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public static CFMetaData tableFromCQL(InputStream source, UUID cfid) throws IOException {
String schema = CharStreams.toString(new InputStreamReader(source, "UTF-8"));
logger.trace("Loading Schema" + schema);
CFStatement statement = (CFStatement) QueryProcessor.parseStatement(schema);
String keyspace = "";
try {
keyspace = statement.keyspace() == null ? "turtles" : statement.keyspace();
} catch (AssertionError e) { // if -ea added we should provide lots of warnings that things probably wont work
logger.warn("Remove '-ea' JVM option when using sstable-tools library");
keyspace = "turtles";
}
statement.prepareKeyspace(keyspace);
if(Schema.instance.getKSMetaData(keyspace) == null) {
Schema.instance.setKeyspaceMetadata(KeyspaceMetadata.create(keyspace, KeyspaceParams.local(), Tables.none(),
Views.none(), getTypes(), Functions.none()));
}
CFMetaData cfm;
if(cfid != null) {
cfm = ((CreateTableStatement) statement.prepare().statement).metadataBuilder().withId(cfid).build();
KeyspaceMetadata prev = Schema.instance.getKSMetaData(keyspace);
List<CFMetaData> tables = Lists.newArrayList(prev.tablesAndViews());
tables.add(cfm);
Schema.instance.setKeyspaceMetadata(prev.withSwapped(Tables.of(tables)));
Schema.instance.load(cfm);
} else {
cfm = ((CreateTableStatement) statement.prepare().statement).getCFMetaData();
}
return cfm;
}
示例6: doSchema
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public void doSchema(String command) throws Exception {
String path = command.substring(6).trim().replaceAll("\"", "");
if (path.equalsIgnoreCase("off")) {
System.out.println(DISABLING_SCHEMA);
CassandraUtils.cqlOverride = null;
} else if (Strings.isNullOrEmpty(path)) {
if (!Strings.isNullOrEmpty(CassandraUtils.cqlOverride)) {
System.out.printf(USER_DEFINED_SCHEMA, CassandraUtils.cqlOverride);
} else {
System.out.println(NO_USER_DEFINED_SCHEMA);
}
} else {
File schemaFile = new File(path);
if (!schemaFile.exists()) {
System.err.printf(CANNOT_FIND_FILE, schemaFile.getAbsolutePath());
} else {
String cql = new String(Files.readAllBytes(schemaFile.toPath()));
try {
ParsedStatement statement = QueryProcessor.parseStatement(cql);
if (statement instanceof CreateTableStatement.RawStatement) {
CassandraUtils.cqlOverride = cql;
System.out.printf(IMPORTED_SCHEMA, schemaFile.getAbsolutePath());
} else {
System.err.printf(FAILED_TO_IMPORT_SCHEMA, schemaFile.getAbsoluteFile(), "Wrong type of statement, " + statement.getClass());
}
} catch (SyntaxException se) {
System.err.printf(FAILED_TO_IMPORT_SCHEMA, schemaFile.getAbsoluteFile(), se.getMessage());
}
}
}
}
示例7: getExpressions
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
private static IndexExpression[] getExpressions(String cqlQuery) throws Exception
{
ParsedStatement parsedStatement = QueryProcessor.parseStatement(String.format(cqlQuery, KS_NAME, CF_NAME));
SelectStatement selectStatement = (SelectStatement) parsedStatement.prepare().statement;
List<IndexExpression> expressions = selectStatement.getIndexExpressions(Collections.<ByteBuffer>emptyList());
return expressions.toArray(new IndexExpression[expressions.size()]);
}
示例8: compile
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public static CFMetaData compile(String cql, String keyspace)
{
CFStatement parsed = (CFStatement)QueryProcessor.parseStatement(cql);
parsed.prepareKeyspace(keyspace);
CreateTableStatement statement = (CreateTableStatement) ((CreateTableStatement.RawStatement) parsed).prepare(Types.none()).statement;
return statement.metadataBuilder()
.withId(generateLegacyCfId(keyspace, statement.columnFamily()))
.build()
.params(statement.params())
.readRepairChance(0.0)
.dcLocalReadRepairChance(0.0)
.gcGraceSeconds(0)
.memtableFlushPeriod((int) TimeUnit.HOURS.toMillis(1));
}
示例9: Query
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public Query(String query, Collection<File> path, CFMetaData cfm) throws IllegalAccessException, NoSuchFieldException, IOException {
SelectStatement.RawStatement statement = (SelectStatement.RawStatement) QueryProcessor.parseStatement(query);
if (!statement.parameters.orderings.isEmpty()) {
throw new UnsupportedOperationException("ORDER BY not supported");
}
if (statement.parameters.isDistinct) {
throw new UnsupportedOperationException("DISTINCT not supported");
}
this.path = path;
VariableSpecifications boundNames = statement.getBoundVariables();
Selection selection = statement.selectClause.isEmpty()
? Selection.wildcard(cfm)
: Selection.fromSelectors(cfm, statement.selectClause, VariableSpecifications.empty(), !statement.parameters.groups.isEmpty());
// yes its unfortunate, im sorry
StatementType type = mock(StatementType.class);
when(type.allowClusteringColumnSlices()).thenReturn(true);
when(type.allowNonPrimaryKeyInWhereClause()).thenReturn(true);
when(type.allowPartitionKeyRanges()).thenReturn(true);
when(type.allowUseOfSecondaryIndices()).thenReturn(false);
this.restrictions = new StatementRestrictions(
type,
cfm,
statement.whereClause,
boundNames,
selection.containsOnlyStaticColumns(),
selection.containsAComplexColumn(),
true, true);
this.statement = statement;
this.cfm = cfm;
this.selection = selection;
ColumnFilter filter;
if (selection.isWildcard()) {
filter = ColumnFilter.all(cfm);
} else {
ColumnFilter.Builder builder = ColumnFilter.selectionBuilder();
selection.getColumns().stream().filter(def -> !def.isPrimaryKeyColumn()).forEach(builder::add);
filter = builder.build();
}
this.queriedColumns = filter;
try {
// Make getAggregationSpecification public and invoke it..
Method getAggregationSpecification = SelectStatement.RawStatement.class.getDeclaredMethod("getAggregationSpecification", CFMetaData.class, Selection.class, StatementRestrictions.class, boolean.class);
getAggregationSpecification.setAccessible(true);
this.aggregationSpec = (AggregationSpecification) getAggregationSpecification.invoke(statement, cfm, selection, restrictions, statement.parameters.isDistinct);
} catch (Exception e) {
logger.error("Unable to get aggregationSpecification", e);
this.aggregationSpec = null;
}
}
示例10: execute
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute batch of CQL3 queries", Collections.<String, String>emptyMap());
}
List<ModificationStatement> statements = new ArrayList<ModificationStatement>(queryOrIdList.size());
for (int i = 0; i < queryOrIdList.size(); i++)
{
Object query = queryOrIdList.get(i);
CQLStatement statement;
if (query instanceof String)
{
statement = QueryProcessor.parseStatement((String)query, state);
}
else
{
statement = QueryProcessor.getPrepared((MD5Digest)query);
if (statement == null)
throw new PreparedQueryNotFoundException((MD5Digest)query);
}
List<ByteBuffer> queryValues = values.get(i);
if (queryValues.size() != statement.getBoundsTerms())
throw new InvalidRequestException(String.format("There were %d markers(?) in CQL but %d bound variables",
statement.getBoundsTerms(),
queryValues.size()));
if (!(statement instanceof ModificationStatement))
throw new InvalidRequestException("Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed.");
ModificationStatement mst = (ModificationStatement)statement;
if (mst.isCounter())
{
if (type != BatchStatement.Type.COUNTER)
throw new InvalidRequestException("Cannot include counter statement in a non-counter batch");
}
else
{
if (type == BatchStatement.Type.COUNTER)
throw new InvalidRequestException("Cannot include non-counter statement in a counter batch");
}
statements.add(mst);
}
// Note: It's ok at this point to pass a bogus value for the number of bound terms in the BatchState ctor
// (and no value would be really correct, so we prefer passing a clearly wrong one).
BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none());
Message.Response response = QueryProcessor.processBatch(batch, consistency, state, values);
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例11: getCFMetaData
import org.apache.cassandra.cql3.QueryProcessor; //导入方法依赖的package包/类
@SuppressWarnings("serial")
@Override
public CFMetaData getCFMetaData(String keyspace, String cfName) {
Pair<String, String> key = Pair.create(keyspace, cfName);
CFMetaData cfm = cfMetaDatas.get(key);
if (cfm == null) {
KeyspaceMetadata ks = metadata.getKeyspace(keyspace);
TableMetadata cf = ks.getTable(cfName);
CFStatement parsed = (CFStatement) QueryProcessor.parseStatement(cf.asCQLQuery());
org.apache.cassandra.schema.KeyspaceMetadata ksm = Schema.instance.getKSMetaData(keyspace);
CreateTableStatement statement = (CreateTableStatement) ((CreateTableStatement.RawStatement) parsed)
.prepare(ksm != null ? ksm.types : Types.none()).statement;
statement.validate(ClientState.forInternalCalls());
cfm = statement.getCFMetaData();
final Map<ByteBuffer, DroppedColumn> map = new HashMap<>();
Map<ByteBuffer, DroppedColumn> droppedColumns = map;
try {
ResultSet r = session.execute(SELECT_DROPPED_COLUMNS + " WHERE keyspace_name = '" + keyspace
+ "' AND table_name = '" + cfName + '\'');
for (Row row : r) {
String name = row.getString("column_name");
long droppedTime = row.getTimestamp("dropped_time").getTime();
AbstractType<?> type = parse(keyspace, row.getString("type"),
org.apache.cassandra.schema.Types.none());
droppedColumns.put(UTF8Type.instance.decompose(name),
new CFMetaData.DroppedColumn(name, type, droppedTime * 1000));
}
} catch (DriverException e) {
// ignore. Assume we're asking a v2 schema source.
}
if (!ignoreColumns.isEmpty()) {
droppedColumns = new HashMap<ByteBuffer, DroppedColumn>(droppedColumns) {
@Override
public DroppedColumn get(Object key) {
DroppedColumn c = super.get(key);
if (c == null) {
String name = UTF8Type.instance.compose((ByteBuffer) key);
if (ignoreColumns.contains(name)) {
c = new DroppedColumn(name, BytesType.instance, FBUtilities.timestampMicros());
put((ByteBuffer) key, c);
}
}
return c;
}
};
}
cfm.droppedColumns(droppedColumns);
cfMetaDatas.put(key, cfm);
}
return cfm;
}