On validate table.

@param ksDef
the ks def
@param tableInfo
the table info
@throws Exception
the exception
974246
private void onValidateTable(KsDef ksDef, TableInfo tableInfo) throws Exception
    {
        boolean tablefound = false;
        for (CfDef cfDef : ksDef.getCf_defs())
        {
            if (cfDef.getName().equals(tableInfo.getTableName())/*
                                                                 * && (cfDef.
                                                                 * getColumn_type
                                                                 * ().equals(
                                                                 * ColumnFamilyType
                                                                 * .
                                                                 * getInstanceOf
                                                                 * (
                                                                 * tableInfo.getType
                                                                 * ()).name()))
                                                                 */)
            {
                if (cfDef.getColumn_type().equals(ColumnFamilyType.Standard.name()))
                {
                    for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas())
                    {
                        onValidateColumn(tableInfo, cfDef, columnInfo);
                    }
                    tablefound = true;
                    break;
                }
                else if (cfDef.getColumn_type().equals(ColumnFamilyType.Super.name()))
                {
                    tablefound = true;
                }
            }
        }
        if (!tablefound)
        {
            throw new SchemaGenerationException("Column family " + tableInfo.getTableName()
                    + " does not exist in keyspace " + databaseName + "", "Cassandra", databaseName,
                    tableInfo.getTableName());
        }
    }
569063
private void validateTable(TableDefinition tableDef) {
        for (String optName : tableDef.getOptionNames()) {
            String optValue = tableDef.getOption(optName);
            switch (optName) {
            case CommonDefs.OPT_AGING_FIELD:
                validateTableOptionAgingField(tableDef, optValue);
                break;
            case CommonDefs.OPT_RETENTION_AGE:
                validateTableOptionRetentionAge(tableDef, optValue);
                break;
            case CommonDefs.OPT_SHARDING_FIELD:
                validateTableOptionShardingField(tableDef, optValue);
                break;
            case CommonDefs.OPT_SHARDING_GRANULARITY:
                validateTableOptionShardingGranularity(tableDef, optValue);
                break;
            case CommonDefs.OPT_SHARDING_START:
                validateTableOptionShardingStart(tableDef, optValue);
                break;
            case CommonDefs.OPT_AGING_CHECK_FREQ:
                validateTableOptionAgingCheckFrequency(tableDef, optValue);
                break;
            default:
                Utils.require(false, "Unknown option for SpiderService table: " + optName);
            }
        }
        
        for (FieldDefinition fieldDef : tableDef.getFieldDefinitions()) {
            validateField(fieldDef);
        }
        
        if (tableDef.getOption(CommonDefs.OPT_AGING_FIELD) != null &&
            tableDef.getOption(CommonDefs.OPT_AGING_CHECK_FREQ) == null) {
            String agingCheckFreq = tableDef.getAppDef().getOption(CommonDefs.OPT_AGING_CHECK_FREQ);
            if (Utils.isEmpty(agingCheckFreq)) {
                agingCheckFreq = "1 DAY";
            }
            tableDef.setOption(CommonDefs.OPT_AGING_CHECK_FREQ, agingCheckFreq);
        }
    }
1342355
public void createTable(TableSpec spec) throws SQLException {
        Statement s = createStatement();
        Iterator<String> iter = m_converter.getDDL(spec).iterator();
        while (iter.hasNext()) {
            String updateSQL = iter.next();
            s.executeUpdate(updateSQL);
        }
    }
1282435
private void createColumnFamilies(List<TableInfo> tableInfos, KsDef ksDef) throws Exception
    {
        for (TableInfo tableInfo : tableInfos)
        {
            if (isCql3Enabled(tableInfo))
            {
                createOrUpdateUsingCQL3(tableInfo, ksDef);
                createIndexUsingCql(tableInfo);
            }
            else
            {
                createOrUpdateColumnFamily(tableInfo, ksDef);
            }

            // Create Inverted Indexed Table if required.
            createInvertedIndexTable(tableInfo, ksDef);
        }
    }
758972
private void addColumnToTable(TableInfo tableInfo, ColumnInfo column) throws Exception
    {
        CQLTranslator translator = new CQLTranslator();
        StringBuilder addColumnQuery = new StringBuilder("ALTER TABLE ");
        translator.ensureCase(addColumnQuery, tableInfo.getTableName(), false);
        addColumnQuery.append(" ADD ");
        translator.ensureCase(addColumnQuery, column.getColumnName(), false);
        addColumnQuery.append(" "
                + translator.getCQLType(CassandraValidationClassMapper.getValidationClass(column.getType(),
                        isCql3Enabled(tableInfo))));
        try
        {
            KunderaCoreUtils.printQuery(addColumnQuery.toString(), showQuery);
            cassandra_client.execute_cql3_query(ByteBuffer.wrap(addColumnQuery.toString().getBytes()),
                    Compression.NONE, ConsistencyLevel.ONE);
        }
        catch (InvalidRequestException ireforAddColumn)
        {
            StringBuilder ireforAddColumnbBuilder = new StringBuilder("Invalid column name ");
            ireforAddColumnbBuilder.append(column.getColumnName() + " because it conflicts with an existing column");
            if (ireforAddColumn.getWhy() != null && ireforAddColumn.getWhy().equals(ireforAddColumnbBuilder.toString()))
            {
                // alterColumnType(tableInfo, translator, column);
            }
            else
            {
                log.error("Error occurred while altering column type of  table {}, Caused by: .",
                        tableInfo.getTableName(), ireforAddColumn);
                throw new SchemaGenerationException("Error occurred while adding column into table "
                        + tableInfo.getTableName(), ireforAddColumn, "Cassandra", databaseName);
            }
        }

    }
54229
public static void createTables(Connection connection) throws Exception {
        StringBuilder sB = new StringBuilder();
        sB.append("CREATE TABLE ");
        sB.append(TABLE_LOG);
        sB.append(" (");
        sB.append(COLUMN_ID);
        sB.append(" INTEGER PRIMARY KEY AUTOINCREMENT, ");
        sB.append(COLUMN_DATAORA).append(" INTEGER NOT NULL, ");
        sB.append(COLUMN_LOGMSG).append(" TEXT ");
        sB.append(");");
        String CREATE_TABLE = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX " + TABLE_LOG + "_" + COLUMN_ID + " ON ");
        sB.append(TABLE_LOG);
        sB.append(" ( ");
        sB.append(COLUMN_ID);
        sB.append(" );");
        String CREATE_INDEX = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX " + TABLE_LOG + "_" + COLUMN_DATAORA + " ON ");
        sB.append(TABLE_LOG);
        sB.append(" ( ");
        sB.append(COLUMN_DATAORA);
        sB.append(" );");
        String CREATE_INDEX_DATE = sB.toString();


        try (Statement statement = connection.createStatement()) {
            statement.setQueryTimeout(30); // set timeout to 30 sec.

            statement.executeUpdate(CREATE_TABLE);
            statement.executeUpdate(CREATE_INDEX);
            statement.executeUpdate(CREATE_INDEX_DATE);
        } catch (Exception e) {
            throw new IOException(e.getLocalizedMessage());
        }
    }
992151
private void createOrUpdateColumnFamily(TableInfo tableInfo, KsDef ksDef) throws Exception
    {
        MetaDataHandler handler = new MetaDataHandler();

        if (containsCompositeKey(tableInfo))
        {
            validateCompoundKey(tableInfo);
            createOrUpdateUsingCQL3(tableInfo, ksDef);

            // After successful schema operation, perform index creation.
            createIndexUsingCql(tableInfo);
        }
        else if (containsCollectionColumns(tableInfo) || isCql3Enabled(tableInfo))
        {
            createOrUpdateUsingCQL3(tableInfo, ksDef);
            createIndexUsingCql(tableInfo);
        }
        else
        {

            CfDef cf_def = handler.getTableMetadata(tableInfo);
            try
            {
                cassandra_client.system_add_column_family(cf_def);
            }
            catch (InvalidRequestException irex)
            {
                updateExistingColumnFamily(tableInfo, ksDef, irex);
            }
        }
    }
1317459
private void createIndexUsingThrift(TableInfo tableInfo, CfDef cfDef) throws Exception
    {
        for (IndexInfo indexInfo : tableInfo.getColumnsToBeIndexed())
        {
            for (ColumnDef columnDef : cfDef.getColumn_metadata())
            {
                if (new String(columnDef.getName(), Constants.ENCODING).equals(indexInfo.getColumnName()))
                {
                    columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
                    // columnDef.setIndex_name(indexInfo.getIndexName());
                }
            }
        }
        cassandra_client.system_update_column_family(cfDef);
    }
189925
function validateTableDefinition(tableDefinition) {
    // Do basic table name validation and leave the rest to the store
    Validate.notNull(tableDefinition, 'tableDefinition');
    Validate.isObject(tableDefinition, 'tableDefinition');

    Validate.isString(tableDefinition.name, 'tableDefinition.name');
    Validate.notNullOrEmpty(tableDefinition.name, 'tableDefinition.name');

    // Validate the specified column types and check for duplicate columns
    var columnDefinitions = tableDefinition.columnDefinitions,
        definedColumns = {};
    
    Validate.isObject(columnDefinitions);
    Validate.notNull(columnDefinitions);

    for (var columnName in columnDefinitions) {

        Validate.isString(columnDefinitions[columnName], 'columnType');
        Validate.notNullOrEmpty(columnDefinitions[columnName], 'columnType');

        if (definedColumns[columnName.toLowerCase()]) {
            throw new Error('Duplicate definition for column ' + columnName + '" in table "' + tableDefinition.name + '"');
        }

        definedColumns[columnName.toLowerCase()] = true;
    }
}
295191
@Override
    protected void create(List<TableInfo> tableInfos)
    {
        List dbList = r.dbList().run(connection);
        
        if(!dbList.contains(databaseName)){
            r.dbCreate(databaseName).run(connection);
        }
        
        List listTables = r.db(databaseName).tableList().run(connection);

        for (TableInfo tableInfo : tableInfos)
        {
            try
            {
                if (listTables.contains(tableInfo.getTableName()))
                {
                    r.db(databaseName).tableDrop(tableInfo.getTableName()).run(connection);
                }
            }
            catch (Exception e)
            {
                logger.error("Cannot check table existence for table " + tableInfo.getTableName() + ". Caused By: " + e);
                throw new KunderaException("Cannot check table existence for table " + tableInfo.getTableName()
                        + ". Caused By: " + e);
            }
            r.db(databaseName).tableCreate(tableInfo.getTableName()).run(connection);
        }

    }
713304
@Then("^a Cassandra keyspace '(.+?)' contains a table '(.+?)'$")
    public void assertTableExistsOnCassandraKeyspace(String keyspace, String tableName) {
        assertThat(commonspec.getCassandraClient().getTables(keyspace)).as("The table " + tableName + "exists on cassandra").contains(tableName);
    }
1254867
@Override
    protected void update(List<TableInfo> tableInfos)
    {
        StatementResult result = null;
        String statement = null;
        for (TableInfo tableInfo : tableInfos)
        {
            try
            {
                Table table = tableAPI.getTable(tableInfo.getTableName());
                if (table == null)
                {
                    statement = buildCreateDDLQuery(tableInfo);
                    result = tableAPI.executeSync(statement);
                    if (!result.isSuccessful())
                    {
                        throw new SchemaGenerationException("Unable to CREATE TABLE " + tableInfo.getTableName());
                    }
                }
                else
                {
                    List<ColumnInfo> columnInfos = tableInfo.getColumnMetadatas();
                    Map<String, String> newColumns = new HashMap<String, String>();
                    for (ColumnInfo column : columnInfos)
                    {
                        if (table.getField(column.getColumnName()) == null)
                        {
                            newColumns.put(column.getColumnName(), column.getType().getSimpleName());
                        }
                    }

                    List<EmbeddedColumnInfo> embeddedColumnInfos = tableInfo.getEmbeddedColumnMetadatas();
                    for (EmbeddedColumnInfo embeddedColumnInfo : embeddedColumnInfos)
                    {
                        for (ColumnInfo column : embeddedColumnInfo.getColumns())
                        {
                            if (table.getField(column.getColumnName()) == null)
                            {
                                newColumns.put(column.getColumnName(), column.getType().getSimpleName());
                            }
                        }
                    }
                    if (!newColumns.isEmpty())
                    {
                        statement = buildAlterDDLQuery(tableInfo, newColumns);
                        result = tableAPI.executeSync(statement);

                        if (!result.isSuccessful())
                        {
                            throw new SchemaGenerationException("Unable to ALTER TABLE " + tableInfo.getTableName());
                        }
                    }
                }
                createIndexOnTable(tableInfo);
            }
            catch (IllegalArgumentException e)
            {
                logger.error("Invalid Statement. Caused By: ", e);
                throw new SchemaGenerationException(e, "Invalid Statement. Caused By: ");
            }
            catch (FaultException e)
            {
                logger.error("Statement couldn't be executed. Caused By: ", e);
                throw new SchemaGenerationException(e, "Statement couldn't be executed. Caused By: ");
            }
        }
    }
893627
private void validate() {

        if (host.isEmpty()) {
            throw new IllegalArgumentException("host cannot be null");
        }
        if (catalog == null) {
            throw new IllegalArgumentException("database cannot be null");
        }
        if (table == null) {
            throw new IllegalArgumentException("collection cannot be null");
        }

        concantHostPort();
    }
1019314
private void addTable(TableDef table)
    {
        table.setOwner(this);
        _tableDefs.put(table.getName(), table);
    }
138389
private void handleOperations(List<TableInfo> tableInfos)
    {
        SchemaOperationType operationType = SchemaOperationType.getInstance(operation);

        switch (operationType)
        {
        case createdrop:
            create_drop(tableInfos);
            break;
        case create:
            create(tableInfos);
            break;
        case update:
            update(tableInfos);
            break;
        case validate:
            validate(tableInfos);
            break;
        }
    }
211582
private void updateTable(KsDef ksDef, TableInfo tableInfo) throws Exception
    {
        for (CfDef cfDef : ksDef.getCf_defs())
        {
            if (cfDef.getName().equals(tableInfo.getTableName())
                    && cfDef.getColumn_type().equals(ColumnFamilyType.getInstanceOf(tableInfo.getType()).name()))
            {
                boolean toUpdate = false;
                if (cfDef.getColumn_type().equals(STANDARDCOLUMNFAMILY))
                {
                    for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas())
                    {
                        toUpdate = isCfDefUpdated(columnInfo, cfDef, isCql3Enabled(tableInfo),
                                isCounterColumnType(tableInfo, null), tableInfo) ? true : toUpdate;
                    }
                }
                if (toUpdate)
                {
                    cassandra_client.system_update_column_family(cfDef);
                }
                createIndexUsingThrift(tableInfo, cfDef);
                break;
            }
        }
    }
918040
private void createOrUpdateKeyspace(List<TableInfo> tableInfos) throws Exception
    {
        KsDef ksDef = onCreateKeyspace(); // create keyspace event.
        createColumnFamilies(tableInfos, ksDef); // create column family event.
    }