本文整理汇总了Java中org.apache.cassandra.cql3.statements.ParsedStatement类的典型用法代码示例。如果您正苦于以下问题:Java ParsedStatement类的具体用法?Java ParsedStatement怎么用?Java ParsedStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParsedStatement类属于org.apache.cassandra.cql3.statements包,在下文中一共展示了ParsedStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseStatement
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public static ParsedStatement parseStatement(String queryStr) throws SyntaxException
{
try
{
return CQLFragmentParser.parseAnyUnhandled(CqlParser::query, queryStr);
}
catch (CassandraException ce)
{
throw ce;
}
catch (RuntimeException re)
{
logger.error(String.format("The statement: [%s] could not be parsed.", queryStr), re);
throw new SyntaxException(String.format("Failed parsing statement: [%s] reason: %s %s",
queryStr,
re.getClass().getSimpleName(),
re.getMessage()));
}
catch (RecognitionException e)
{
throw new SyntaxException("Invalid or malformed CQL query string: " + e.getMessage());
}
}
示例2: testParsingCQLOnCompoundedTable
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的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);
}
示例3: parseSchema
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的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);
}
}
示例4: getStatement
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
private static <T extends CQLStatement> Pair<T, List<ColumnSpecification>> getStatement(String query, Class<T> klass, String type)
{
try
{
ClientState state = ClientState.forInternalCalls();
ParsedStatement.Prepared prepared = QueryProcessor.getStatement(query, state);
CQLStatement stmt = prepared.statement;
stmt.validate(state);
if (!stmt.getClass().equals(klass))
throw new IllegalArgumentException("Invalid query, must be a " + type + " statement");
return Pair.create(klass.cast(stmt), prepared.boundNames);
}
catch (RequestValidationException e)
{
throw new IllegalArgumentException(e.getMessage(), e);
}
}
示例5: schemaChange
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
protected static void schemaChange(String query)
{
try
{
ClientState state = ClientState.forInternalCalls();
state.setKeyspace(SystemKeyspace.NAME);
QueryState queryState = new QueryState(state);
ParsedStatement.Prepared prepared = QueryProcessor.parseStatement(query, queryState);
prepared.statement.validate(state);
QueryOptions options = QueryOptions.forInternalCalls(Collections.<ByteBuffer>emptyList());
lastSchemaChangeResult = prepared.statement.executeInternal(queryState, options);
}
catch (Exception e)
{
logger.info("Error performing schema change", e);
throw new RuntimeException("Error setting schema for test (query was: " + query + ")", e);
}
}
示例6: cqlStatement
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public final ParsedStatement cqlStatement() throws RecognitionException {
ParsedStatement stmt = null;
CreateTableStatement.RawStatement st9 =null;
try {
// Parser.g:209:5: (st1= selectStatement |st2= insertStatement |st3= updateStatement |st4= batchStatement |st5= deleteStatement |st6= useStatement |st7= truncateStatement |st8= createKeyspaceStatement |st9= createTableStatement |st10= createIndexStatement |st11= dropKeyspaceStatement |st12= dropTableStatement |st13= dropIndexStatement |st14= alterTableStatement |st15= alterKeyspaceStatement |st16= grantPermissionsStatement |st17= revokePermissionsStatement |st18= listPermissionsStatement |st19= createUserStatement |st20= alterUserStatement |st21= dropUserStatement |st22= listUsersStatement |st23= createTriggerStatement |st24= dropTriggerStatement |st25= createTypeStatement |st26= alterTypeStatement |st27= dropTypeStatement |st28= createFunctionStatement |st29= dropFunctionStatement |st30= createAggregateStatement |st31= dropAggregateStatement |st32= createRoleStatement |st33= alterRoleStatement |st34= dropRoleStatement |st35= listRolesStatement |st36= grantRoleStatement |st37= revokeRoleStatement |st38= createMaterializedViewStatement |st39= dropMaterializedViewStatement |st40= alterMaterializedViewStatement )
int alt1=40;
alt1 = dfa1.predict(input);
switch (alt1) {
case 9 :
// Parser.g:217:7: st9= createTableStatement
{
pushFollow(FOLLOW_createTableStatement_in_cqlStatement285);
st9=createTableStatement();
state._fsp--;
stmt = st9;
}
break;
}
}
catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
finally {
// do for sure before leaving
}
return stmt;
}
示例7: doSchema
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的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());
}
}
}
}
示例8: getExpressions
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的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()]);
}
示例9: query
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public final ParsedStatement query() throws RecognitionException {
ParsedStatement stmnt = null;
ParsedStatement st =null;
try {
// /Users/minhdo/workspace2/BDP/cassandra-3/src/antlr/Cql.g:138:5: (st= cqlStatement ( ';' )* EOF )
// /Users/minhdo/workspace2/BDP/cassandra-3/src/antlr/Cql.g:138:7: st= cqlStatement ( ';' )* EOF
{
pushFollow(FOLLOW_cqlStatement_in_query77);
st=cqlStatement();
state._fsp--;
// /Users/minhdo/workspace2/BDP/cassandra-3/src/antlr/Cql.g:138:23: ( ';' )*
loop1:
while (true) {
int alt1=2;
int LA1_0 = input.LA(1);
if ( (LA1_0==192) ) {
alt1=1;
}
switch (alt1) {
case 1 :
// /Users/minhdo/workspace2/BDP/cassandra-3/src/antlr/Cql.g:138:24: ';'
{
match(input,192,FOLLOW_192_in_query80);
}
break;
default :
break loop1;
}
}
match(input,EOF,FOLLOW_EOF_in_query84);
stmnt = st;
}
}
catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
finally {
// do for sure before leaving
}
return stmnt;
}
示例10: execute
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
QueryHandler handler = state.getClientState().getCQLQueryHandler();
ParsedStatement.Prepared prepared = handler.getPrepared(statementId);
if (prepared == null)
throw new PreparedQueryNotFoundException(statementId);
options.prepare(prepared.boundNames);
CQLStatement statement = prepared.statement;
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", builder.build());
}
Message.Response response = handler.processPrepared(statement, state, options);
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
JVMStabilityInspector.inspectThrowable(e);
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例11: Prepared
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public Prepared(MD5Digest statementId, ParsedStatement.Prepared prepared)
{
this(statementId, -1, new ResultSet.Metadata(prepared.boundNames), extractResultMetadata(prepared.statement));
}
示例12: getPrepared
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public ParsedStatement.Prepared getPrepared(MD5Digest id)
{
return queryProcessor.getPrepared(id);
}
示例13: getPreparedForThrift
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public ParsedStatement.Prepared getPreparedForThrift(Integer id)
{
return queryProcessor.getPreparedForThrift(id);
}
示例14: execute
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
QueryHandler handler = ClientState.getCQLQueryHandler();
ParsedStatement.Prepared prepared = handler.getPrepared(statementId);
if (prepared == null)
throw new PreparedQueryNotFoundException(statementId);
options.prepare(prepared.boundNames);
CQLStatement statement = prepared.statement;
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
if(options.getConsistency() != null)
builder.put("consistency_level", options.getConsistency().name());
if(options.getSerialConsistency() != null)
builder.put("serial_consistency_level", options.getSerialConsistency().name());
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", state.getClientAddress(), builder.build());
}
// Some custom QueryHandlers are interested by the bound names. We provide them this information
// by wrapping the QueryOptions.
QueryOptions queryOptions = QueryOptions.addColumnSpecifications(options, prepared.boundNames);
Message.Response response = handler.processPrepared(statement, state, queryOptions, getCustomPayload());
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
JVMStabilityInspector.inspectThrowable(e);
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例15: Prepared
import org.apache.cassandra.cql3.statements.ParsedStatement; //导入依赖的package包/类
public Prepared(MD5Digest statementId, ParsedStatement.Prepared prepared)
{
this(statementId, -1, new ResultSet.PreparedMetadata(prepared.boundNames, prepared.partitionKeyBindIndexes), extractResultMetadata(prepared.statement));
}