org.apache.cassandra.cql3.statements.ParsedStatement Java Examples

The following examples show how to use org.apache.cassandra.cql3.statements.ParsedStatement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Cqlsh.java    From sstable-tools with Apache License 2.0 5 votes vote down vote up
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());
            }
        }
    }

}
 
Example #2
Source File: SSTableAttachedSecondaryIndexTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
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()]);
}
 
Example #3
Source File: ExecuteMessage.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
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();
    }
}
 
Example #4
Source File: ResultMessage.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Prepared(MD5Digest statementId, ParsedStatement.Prepared prepared)
{
    this(statementId, -1, new ResultSet.Metadata(prepared.boundNames), extractResultMetadata(prepared.statement));
}
 
Example #5
Source File: QueryHandler.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public ParsedStatement.Prepared getPrepared(MD5Digest id); 
Example #6
Source File: QueryHandler.java    From stratio-cassandra with Apache License 2.0 votes vote down vote up
public ParsedStatement.Prepared getPreparedForThrift(Integer id);