org.apache.cassandra.exceptions.RequestValidationException Java Examples

The following examples show how to use org.apache.cassandra.exceptions.RequestValidationException. 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: CFMetadataUtility.java    From aegisthus with Apache License 2.0 6 votes vote down vote up
public static CFMetaData initializeCfMetaData(Configuration configuration) {
    final String cql = configuration.get(Aegisthus.Feature.CONF_CQL_SCHEMA);
    Preconditions.checkNotNull(cql, "Cannot proceed without CQL definition.");

    final CreateTableStatement statement = getCreateTableStatement(cql);

    try {
        final CFMetaData cfMetaData = statement.getCFMetaData();
        cfMetaData.rebuild();

        return cfMetaData;
    } catch (RequestValidationException e) {
        // Cannot proceed if an error occurs
        throw new RuntimeException("Error initializing CFMetadata from CQL.", e);
    }
}
 
Example #2
Source File: ListPermissionsStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public ResultMessage execute(ClientState state) throws RequestValidationException, RequestExecutionException
{
    List<PermissionDetails> details = new ArrayList<PermissionDetails>();

    if (resource != null && recursive)
    {
        for (IResource r : Resources.chain(resource))
            details.addAll(list(state, r));
    }
    else
    {
        details.addAll(list(state, resource));
    }

    Collections.sort(details);
    return resultMessage(details);
}
 
Example #3
Source File: CreateKeyspaceStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * The <code>CqlParser</code> only goes as far as extracting the keyword arguments
 * from these statements, so this method is responsible for processing and
 * validating.
 *
 * @throws InvalidRequestException if arguments are missing or unacceptable
 */
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateKeyspaceNotSystem(name);

    // keyspace name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace name", name));
    if (name.length() > Schema.NAME_LENGTH)
        throw new InvalidRequestException(String.format("Keyspace names shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));

    attrs.validate();

    if (attrs.getReplicationStrategyClass() == null)
        throw new ConfigurationException("Missing mandatory replication strategy class");

    // The strategy is validated through KSMetaData.validate() in announceNewKeyspace below.
    // However, for backward compatibility with thrift, this doesn't validate unexpected options yet,
    // so doing proper validation here.
    AbstractReplicationStrategy.validateReplicationStrategy(name,
                                                            AbstractReplicationStrategy.getClass(attrs.getReplicationStrategyClass()),
                                                            StorageService.instance.getTokenMetadata(),
                                                            DatabaseDescriptor.getEndpointSnitch(),
                                                            attrs.getReplicationOptions());
}
 
Example #4
Source File: MultiPartitionPager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public List<Row> fetchPage(int pageSize) throws RequestValidationException, RequestExecutionException
{
    List<Row> result = new ArrayList<Row>();

    int remainingThisQuery = Math.min(remaining, pageSize);
    while (remainingThisQuery > 0 && !isExhausted())
    {
        // isExhausted has set us on the first non-exhausted pager
        List<Row> page = pagers[current].fetchPage(remainingThisQuery);
        if (page.isEmpty())
            continue;

        Row row = page.get(0);
        int fetched = pagers[current].columnCounter().countAll(row.cf).live();
        remaining -= fetched;
        remainingThisQuery -= fetched;
        result.add(row);
    }

    return result;
}
 
Example #5
Source File: QueryPagers.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method that count (live) cells/rows for a given slice of a row, but page underneath.
 */
public static int countPaged(String keyspace,
                             String columnFamily,
                             ByteBuffer key,
                             SliceQueryFilter filter,
                             ConsistencyLevel consistencyLevel,
                             ClientState cState,
                             final int pageSize,
                             long now) throws RequestValidationException, RequestExecutionException
{
    SliceFromReadCommand command = new SliceFromReadCommand(keyspace, key, columnFamily, now, filter);
    final SliceQueryPager pager = new SliceQueryPager(command, consistencyLevel, cState, false);

    ColumnCounter counter = filter.columnCounter(Schema.instance.getCFMetaData(keyspace, columnFamily).comparator, now);
    while (!pager.isExhausted())
    {
        List<Row> next = pager.fetchPage(pageSize);
        if (!next.isEmpty())
            counter.countAll(next.get(0).cf);
    }
    return counter.live();
}
 
Example #6
Source File: SliceQueryPager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
protected List<Row> queryNextPage(int pageSize, ConsistencyLevel consistencyLevel, boolean localQuery)
throws RequestValidationException, RequestExecutionException
{
    // For some queries, such as a DISTINCT query on static columns, the limit for slice queries will be lower
    // than the page size (in the static example, it will be 1).  We use the min here to ensure we don't fetch
    // more rows than we're supposed to.  See CASSANDRA-8108 for more details.
    SliceQueryFilter filter = command.filter.withUpdatedCount(Math.min(command.filter.count, pageSize));
    if (lastReturned != null)
        filter = filter.withUpdatedStart(lastReturned, cfm.comparator);

    logger.debug("Querying next page of slice query; new filter: {}", filter);
    ReadCommand pageCmd = command.withUpdatedFilter(filter);
    return localQuery
         ? Collections.singletonList(pageCmd.getRow(Keyspace.open(command.ksName)))
         : StorageProxy.read(Collections.singletonList(pageCmd), consistencyLevel, cstate);
}
 
Example #7
Source File: UTMetaData.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static UserType fromSchema(UntypedResultSet.Row row)
{
    try
    {
        String keyspace = row.getString("keyspace_name");
        ByteBuffer name = ByteBufferUtil.bytes(row.getString("type_name"));
        List<String> rawColumns = row.getList("field_names", UTF8Type.instance);
        List<String> rawTypes = row.getList("field_types", UTF8Type.instance);

        List<ByteBuffer> columns = new ArrayList<>(rawColumns.size());
        for (String rawColumn : rawColumns)
            columns.add(ByteBufferUtil.bytes(rawColumn));

        List<AbstractType<?>> types = new ArrayList<>(rawTypes.size());
        for (String rawType : rawTypes)
            types.add(TypeParser.parse(rawType));

        return new UserType(keyspace, name, columns, types);
    }
    catch (RequestValidationException e)
    {
        // If it has been written in the schema, it should be valid
        throw new AssertionError();
    }
}
 
Example #8
Source File: CliClient.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private AbstractType<?> getFormatType(String compareWith)
{
    Function function;

    try
    {
        function = Function.valueOf(compareWith.toUpperCase());
    }
    catch (IllegalArgumentException e)
    {
        try
        {
            return TypeParser.parse(compareWith);
        }
        catch (RequestValidationException ce)
        {
            String message = String.format("Unknown comparator '%s'. Available functions: %s", compareWith, Function.getFunctionNames());
            throw new RuntimeException(message, e);
        }
    }

    return function.getValidator();
}
 
Example #9
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public ResultMessage processPrepared(CQLStatement statement, QueryState queryState, QueryOptions options)
throws RequestExecutionException, RequestValidationException
{
    List<ByteBuffer> variables = options.getValues();
    // Check to see if there are any bound variables to verify
    if (!(variables.isEmpty() && (statement.getBoundTerms() == 0)))
    {
        if (variables.size() != statement.getBoundTerms())
            throw new InvalidRequestException(String.format("there were %d markers(?) in CQL but %d bound variables",
                                                            statement.getBoundTerms(),
                                                            variables.size()));

        // at this point there is a match in count between markers and variables that is non-zero

        if (logger.isTraceEnabled())
            for (int i = 0; i < variables.size(); i++)
                logger.trace("[{}] '{}'", i+1, variables.get(i));
    }

    metrics.preparedStatementsExecuted.inc();
    return processStatement(statement, queryState, options);
}
 
Example #10
Source File: StressProfile.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static StressProfile load(URI file) throws IOError
{
    try
    {
        Constructor constructor = new Constructor(StressYaml.class);

        Yaml yaml = new Yaml(constructor);

        InputStream yamlStream = file.toURL().openStream();

        if (yamlStream.available() == 0)
            throw new IOException("Unable to load yaml file from: "+file);

        StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);

        StressProfile profile = new StressProfile();
        profile.init(profileYaml);

        return profile;
    }
    catch (YAMLException | IOException | RequestValidationException e)
    {
        throw new IOError(e);
    }
}
 
Example #11
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static UntypedResultSet executeInternalWithPaging(String query, int pageSize, Object... values)
{
    try
    {
        ParsedStatement.Prepared prepared = prepareInternal(query);
        if (!(prepared.statement instanceof SelectStatement))
            throw new IllegalArgumentException("Only SELECTs can be paged");

        SelectStatement select = (SelectStatement)prepared.statement;
        QueryPager pager = QueryPagers.localPager(select.getPageableCommand(makeInternalOptions(prepared, values)));
        return UntypedResultSet.create(select, pager, pageSize);
    }
    catch (RequestValidationException e)
    {
        throw new RuntimeException("Error validating query" + e);
    }
}
 
Example #12
Source File: SimpleExampleMapper.java    From hadoop-sstable with Apache License 2.0 6 votes vote down vote up
@Override
protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);

    String cql = context.getConfiguration().get(HADOOP_SSTABLE_CQL);

    if (cql == null || cql.trim().isEmpty()) {
        throw new RuntimeException("Failed CQL create statement empty");
    }

    try {
        final CFMetaData cfm = CQLUtil.parseCreateStatement(cql);

        keyType = cfm.getKeyValidator();
        this.jsonColumnParser = new JsonColumnParser(cfm);
    } catch (RequestValidationException e) {
        throw new RuntimeException("Failed to parse CQL statement: " + cql, e);
    }

}
 
Example #13
Source File: SSTableRecordReader.java    From hadoop-sstable with Apache License 2.0 6 votes vote down vote up
private static CFMetaData initializeCfMetaData(TaskAttemptContext context) {
    final String cql = context.getConfiguration().get(HadoopSSTableConstants.HADOOP_SSTABLE_CQL);
    Preconditions.checkNotNull(cql, "Cannot proceed without CQL definition.");

    final CreateColumnFamilyStatement statement = getCreateColumnFamilyStatement(cql);

    final String keyspace = context.getConfiguration().get(HadoopSSTableConstants.HADOOP_SSTABLE_KEYSPACE, "default");
    final String columnFamily = context.getConfiguration().get(HadoopSSTableConstants.HADOOP_SSTABLE_COLUMN_FAMILY_NAME, "default");
    final CFMetaData cfMetaData = new CFMetaData(keyspace, columnFamily, ColumnFamilyType.Standard, statement.comparator, null);

    try {
        statement.applyPropertiesTo(cfMetaData);
    } catch (RequestValidationException e) {
        // Cannot proceed if an error occurs
        throw new RuntimeException("Error configuring SSTable reader. Cannot proceed", e);
    }

    return cfMetaData;
}
 
Example #14
Source File: CQLSSTableWriter.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #15
Source File: CreateUserStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ResultMessage execute(ClientState state) throws RequestValidationException, RequestExecutionException
{
    // not rejected in validate()
    if (ifNotExists && Auth.isExistingUser(username))
        return null;

    DatabaseDescriptor.getAuthenticator().create(username, opts.getOptions());
    Auth.insertUser(username, superuser);
    return null;
}
 
Example #16
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static UntypedResultSet process(String query, ConsistencyLevel cl) throws RequestExecutionException
{
    try
    {
        ResultMessage result = instance.process(query, QueryState.forInternalCalls(), QueryOptions.forInternalCalls(cl, Collections.<ByteBuffer>emptyList()));
        if (result instanceof ResultMessage.Rows)
            return UntypedResultSet.create(((ResultMessage.Rows)result).result);
        else
            return null;
    }
    catch (RequestValidationException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source File: CreateTriggerStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void validate(ClientState state) throws RequestValidationException
{
    ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
    try
    {
        TriggerExecutor.instance.loadTriggerInstance(triggerClass);
    }
    catch (Exception e)
    {
        throw new ConfigurationException(String.format("Trigger class '%s' doesn't exist", triggerClass));
    }
}
 
Example #18
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static ResultMessage.Prepared prepare(String queryString, ClientState clientState, boolean forThrift)
throws RequestValidationException
{
    ResultMessage.Prepared existing = getStoredPreparedStatement(queryString, clientState.getRawKeyspace(), forThrift);
    if (existing != null)
        return existing;

    ParsedStatement.Prepared prepared = getStatement(queryString, clientState);
    int boundTerms = prepared.statement.getBoundTerms();
    if (boundTerms > FBUtilities.MAX_UNSIGNED_SHORT)
        throw new InvalidRequestException(String.format("Too many markers(?). %d markers exceed the allowed maximum of %d", boundTerms, FBUtilities.MAX_UNSIGNED_SHORT));
    assert boundTerms == prepared.boundNames.size();

    return storePreparedStatement(queryString, clientState.getRawKeyspace(), prepared, forThrift);
}
 
Example #19
Source File: QueryProcessor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static ParsedStatement.Prepared prepareInternal(String query) throws RequestValidationException
{
    ParsedStatement.Prepared prepared = internalStatements.get(query);
    if (prepared != null)
        return prepared;

    // Note: if 2 threads prepare the same query, we'll live so don't bother synchronizing
    prepared = parseStatement(query, internalQueryState());
    prepared.statement.validate(internalQueryState().getClientState());
    internalStatements.putIfAbsent(query, prepared);
    return prepared;
}
 
Example #20
Source File: CreateUserStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void validate(ClientState state) throws RequestValidationException
{
    if (username.isEmpty())
        throw new InvalidRequestException("Username can't be an empty string");

    opts.validate();

    // validate login here before checkAccess to avoid leaking user existence to anonymous users.
    state.ensureNotAnonymous();

    if (!ifNotExists && Auth.isExistingUser(username))
        throw new InvalidRequestException(String.format("User %s already exists", username));
}
 
Example #21
Source File: CQLUtil.java    From hadoop-sstable with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a CQL CREATE statement into its CFMetaData object
 *
 * @param cql
 * @return CFMetaData
 * @throws RequestValidationException if CQL is invalid
 */
public static CFMetaData parseCreateStatement(String cql) throws RequestValidationException {
    final CreateColumnFamilyStatement statement =
            (CreateColumnFamilyStatement) QueryProcessor.parseStatement(cql).prepare().statement;

    final CFMetaData cfm =
            new CFMetaData("assess", "kvs_strict", ColumnFamilyType.Standard, statement.comparator, null);

    statement.applyPropertiesTo(cfm);
    return cfm;
}
 
Example #22
Source File: CreateKeyspaceStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public boolean announceMigration(boolean isLocalOnly) throws RequestValidationException
{
    try
    {
        MigrationManager.announceNewKeyspace(attrs.asKSMetadata(name), isLocalOnly);
        return true;
    }
    catch (AlreadyExistsException e)
    {
        if (ifNotExists)
            return false;
        throw e;
    }
}
 
Example #23
Source File: DropUserStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void validate(ClientState state) throws RequestValidationException
{
    // validate login here before checkAccess to avoid leaking user existence to anonymous users.
    state.ensureNotAnonymous();

    if (!ifExists && !Auth.isExistingUser(username))
        throw new InvalidRequestException(String.format("User %s doesn't exist", username));

    AuthenticatedUser user = state.getUser();
    if (user != null && user.getName().equals(username))
        throw new InvalidRequestException("Users aren't allowed to DROP themselves");
}
 
Example #24
Source File: DropUserStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ResultMessage execute(ClientState state) throws RequestValidationException, RequestExecutionException
{
    // not rejected in validate()
    if (ifExists && !Auth.isExistingUser(username))
        return null;

    // clean up permissions after the dropped user.
    DatabaseDescriptor.getAuthorizer().revokeAll(username);
    Auth.deleteUser(username);
    DatabaseDescriptor.getAuthenticator().drop(username);
    return null;
}
 
Example #25
Source File: ClientOnlyExample.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static void setupKeyspace() throws RequestExecutionException, RequestValidationException, InterruptedException
{
    QueryProcessor.process("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}",
                           ConsistencyLevel.ANY);
    QueryProcessor.process("CREATE TABLE IF NOT EXISTS " + KEYSPACE + "." + COLUMN_FAMILY + " (id ascii PRIMARY KEY, name ascii, value ascii )",
                           ConsistencyLevel.ANY);
    TimeUnit.MILLISECONDS.sleep(1000);
}
 
Example #26
Source File: Auth.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up Authenticator and Authorizer.
 */
public static void setup()
{
    if (DatabaseDescriptor.getAuthenticator() instanceof AllowAllAuthenticator)
        return;

    setupAuthKeyspace();
    setupTable(USERS_CF, USERS_CF_SCHEMA);

    DatabaseDescriptor.getAuthenticator().setup();
    DatabaseDescriptor.getAuthorizer().setup();

    // register a custom MigrationListener for permissions cleanup after dropped keyspaces/cfs.
    MigrationManager.instance.register(new AuthMigrationListener());

    // the delay is here to give the node some time to see its peers - to reduce
    // "Skipped default superuser setup: some nodes were not ready" log spam.
    // It's the only reason for the delay.
    ScheduledExecutors.nonPeriodicTasks.schedule(new Runnable()
    {
        public void run()
        {
            setupDefaultSuperuser();
        }
    }, SUPERUSER_SETUP_DELAY, TimeUnit.MILLISECONDS);

    try
    {
        String query = String.format("SELECT * FROM %s.%s WHERE name = ?", AUTH_KS, USERS_CF);
        selectUserStatement = (SelectStatement) QueryProcessor.parseStatement(query).prepare().statement;
    }
    catch (RequestValidationException e)
    {
        throw new AssertionError(e); // not supposed to happen
    }
}
 
Example #27
Source File: SSTableRecordReader.java    From hadoop-sstable with Apache License 2.0 5 votes vote down vote up
private static CreateColumnFamilyStatement getCreateColumnFamilyStatement(String cql) {
    CreateColumnFamilyStatement statement;
    try {
        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;
}
 
Example #28
Source File: NamesQueryPager.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public List<Row> fetchPage(int pageSize) throws RequestValidationException, RequestExecutionException
{
    assert command.filter.countCQL3Rows() || command.filter.columns.size() <= pageSize;

    if (isExhausted())
        return Collections.<Row>emptyList();

    queried = true;
    return localQuery
         ? Collections.singletonList(command.getRow(Keyspace.open(command.ksName)))
         : StorageProxy.read(Collections.<ReadCommand>singletonList(command), consistencyLevel, state);
}
 
Example #29
Source File: NonNativeTimestampTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void setServerTimestampForNonCqlNativeStatements() throws RequestValidationException, RequestExecutionException, CharacterCodingException, UnsupportedEncodingException
{
    String createKsCQL = "CREATE KEYSPACE non_native_ts_test" +
                         " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };";
    String createTableCQL = "CREATE TABLE non_native_ts_test.table_0 (k int PRIMARY KEY, v int)";
    String insertCQL = "INSERT INTO non_native_ts_test.table_0 (k, v) values (1, ?)";
    String selectCQL = "SELECT v, writetime(v) AS wt FROM non_native_ts_test.table_0 WHERE k = 1";

    QueryProcessor.instance.process(createKsCQL,
                                    QueryState.forInternalCalls(),
                                    QueryOptions.forInternalCalls(Collections.<ByteBuffer>emptyList()));
    QueryProcessor.instance.process(createTableCQL,
                                    QueryState.forInternalCalls(),
                                    QueryOptions.forInternalCalls(Collections.<ByteBuffer>emptyList()));
    QueryProcessor.instance.process(insertCQL,
                                    QueryState.forInternalCalls(),
                                    QueryOptions.forInternalCalls(ConsistencyLevel.ONE,
                                                                  Arrays.asList(ByteBufferUtil.bytes(2))));
    UntypedResultSet.Row row = QueryProcessor.instance.executeInternal(selectCQL).one();
    assertEquals(2, row.getInt("v"));
    long timestamp1 = row.getLong("wt");
    assertFalse(timestamp1 == -1l);

    // per CASSANDRA-8246 the two updates will have the same (incorrect)
    // timestamp, so reconcilliation is by value and the "older" update wins
    QueryProcessor.instance.process(insertCQL,
                                    QueryState.forInternalCalls(),
                                    QueryOptions.forInternalCalls(ConsistencyLevel.ONE,
                                                                  Arrays.asList(ByteBufferUtil.bytes(1))));
    row = QueryProcessor.executeInternal(selectCQL).one();
    assertEquals(1, row.getInt("v"));
    assertTrue(row.getLong("wt") > timestamp1);
}
 
Example #30
Source File: CQLSSTableWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * The schema (CREATE TABLE statement) for the table for which sstable are to be created.
 * <p>
 * Please note that the provided CREATE TABLE statement <b>must</b> use a fully-qualified
 * table name, one that include the keyspace name.
 * <p>
 * This is a mandatory option.
 *
 * @param schema the schema of the table for which sstables are to be created.
 * @return this builder.
 *
 * @throws IllegalArgumentException if {@code schema} is not a valid CREATE TABLE statement
 * or does not have a fully-qualified table name.
 */
public Builder forTable(String schema)
{
    try
    {
        synchronized (CQLSSTableWriter.class)
        {
            this.schema = getStatement(schema, CreateTableStatement.class, "CREATE TABLE").left.getCFMetaData().rebuild();

            // We need to register the keyspace/table metadata through Schema, otherwise we won't be able to properly
            // build the insert statement in using().
            KSMetaData ksm = Schema.instance.getKSMetaData(this.schema.ksName);
            if (ksm == null)
            {
                createKeyspaceWithTable(this.schema);
            }
            else if (Schema.instance.getCFMetaData(this.schema.ksName, this.schema.cfName) == null)
            {
                addTableToKeyspace(ksm, this.schema);
            }
            return this;
        }
    }
    catch (RequestValidationException e)
    {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}