List of usage examples for org.apache.cassandra.cql3 QueryProcessor parseStatement
public static CQLStatement.Raw parseStatement(String queryStr) throws SyntaxException
From source file:com.fullcontact.sstable.hadoop.mapreduce.SSTableRecordReader.java
License:Apache License
private static CreateColumnFamilyStatement getCreateColumnFamilyStatement(String cql) { CreateColumnFamilyStatement statement; try {// ww w .j a v a 2 s . c o m statement = (CreateColumnFamilyStatement) QueryProcessor.parseStatement(cql).prepare().statement; } catch (RequestValidationException e) { // Cannot proceed if an error occurs throw new RuntimeException("Error configuring SSTable reader. Cannot proceed", e); } return statement; }
From source file:com.protectwise.cassandra.retrospect.deletion.RuleBasedDeletionConvictor.java
License:Apache License
/** * Called by {{{DeletingCompactionStrategy.validateOptions}}} to allow the convictor to * read and validate convictor-specific options at the same time. * <p/>/* w w w.j a v a2 s . c om*/ * See {@link org.apache.cassandra.db.compaction.AbstractCompactionStrategy#validateOptions(Map)} * * @param options * @return */ public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException { String select = options.get(RULES_STATEMENT_KEY); if (select == null) { throw new ConfigurationException(RULES_STATEMENT_KEY + " is a required parameter"); } try { ParsedStatement stmt = QueryProcessor.parseStatement(select); if (!(stmt instanceof SelectStatement.RawStatement)) { throw new ConfigurationException(RULES_STATEMENT_KEY + " must be a SELECT statement"); } SelectStatement.RawStatement sel = (SelectStatement.RawStatement) stmt; try { sel.keyspace(); } catch (AssertionError e) { throw new ConfigurationException( RULES_STATEMENT_KEY + " must define a fully qualified keyspace.tablename"); } // This will validate that the data types of the columns in the select are correct. parseRules(select); } catch (SyntaxException e) { throw new ConfigurationException("Invalid select statement: " + e.getMessage(), e); } options.remove(RULES_STATEMENT_KEY); return options; }
From source file:com.protectwise.cassandra.retrospect.deletion.RuleBasedLateTTLConvictor.java
License:Apache License
/** * Called by {{{DeletingCompactionStrategy.validateOptions}}} to allow the convictor to * read and validate convictor-specific options at the same time. * <p/>/*from w ww . ja v a 2 s. c om*/ * See {@link org.apache.cassandra.db.compaction.AbstractCompactionStrategy#validateOptions(Map)} * * @param options * @return */ public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException { String select = options.get(RULES_STATEMENT_KEY); if (select == null) { throw new ConfigurationException(RULES_STATEMENT_KEY + " is a required parameter"); } try { ParsedStatement stmt = QueryProcessor.parseStatement(select); if (!(stmt instanceof SelectStatement.RawStatement)) { throw new ConfigurationException(RULES_STATEMENT_KEY + " must be a SELECT statement"); } SelectStatement.RawStatement sel = (SelectStatement.RawStatement) stmt; try { sel.keyspace(); } catch (AssertionError e) { throw new ConfigurationException( RULES_STATEMENT_KEY + " must define a fully qualified keyspace.tablename"); } // This will validate that the data types of the columns in the select are correct. parseRules(select); } catch (SyntaxException e) { throw new ConfigurationException("Invalid select statement: " + e.getMessage(), e); } String defaultTTL = options.get(DEFAULT_TTL_KEY); if (defaultTTL != null) { try { Long.parseLong(defaultTTL); } catch (NumberFormatException e) { throw new ConfigurationException( "Invalid value '" + options.get(DEFAULT_TTL_KEY) + "' for " + DEFAULT_TTL_KEY, e); } } options.remove(DEFAULT_TTL_KEY); options.remove(RULES_STATEMENT_KEY); return options; }