private HColumnDescriptor getColumnDescriptor(TableInfo tableInfo) { HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(tableInfo.getTableName()); setColumnFamilyProperties(hColumnDescriptor, tableInfo.getTableName()); return hColumnDescriptor; }
/** * Checks whether the given table is a capped collection */ protected boolean isCappedCollection(TableInfo tableInfo) { return MongoDBPropertyReader.msmd != null ? MongoDBPropertyReader.msmd.isCappedCollection(databaseName, tableInfo.getTableName()) : false; }
@Override protected void validate(List<TableInfo> tableInfos) { for (TableInfo tableInfo : tableInfos) { try { if (tableAPI.getTable(tableInfo.getTableName()) == null) { logger.error("No table found for " + tableInfo.getTableName()); throw new SchemaGenerationException("No table found for " + tableInfo.getTableName()); } } catch (FaultException e) { logger.error("Error while getting table " + tableInfo.getTableName() + ". Caused By: ", e); throw new SchemaGenerationException(e, "Error while getting table " + tableInfo.getTableName() + ". Caused By: "); } } }
@Override protected void create(List<TableInfo> tableInfos) { for (TableInfo tableInfo : tableInfos) { try { if (client.tableExists(tableInfo.getTableName())) { client.deleteTable(tableInfo.getTableName()); } } 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); } createKuduTable(tableInfo); } }
/** * Checks if is counter column type. * * @param tableInfo * the table info * @param defaultValidationClass * the default validation class * @return true, if is counter column type */ private boolean isCounterColumnType(TableInfo tableInfo, String defaultValidationClass) { return (csmd != null && csmd.isCounterColumn(databaseName, tableInfo.getTableName())) || (defaultValidationClass != null && (defaultValidationClass.equalsIgnoreCase(CounterColumnType.class.getSimpleName()) || defaultValidationClass .equalsIgnoreCase(CounterColumnType.class.getName())) || (tableInfo.getType() .equals(CounterColumnType.class.getSimpleName()))); } }
@Override public void dropSchema() { if (operation != null && ("create-drop").equalsIgnoreCase(operation)) { for (TableInfo tableInfo : tableInfos) { removeBucket(tableInfo.getTableName()); } } cluster.disconnect(); cluster = null; }
@Override protected void validate(List<TableInfo> tableInfos) { for (TableInfo tableInfo : tableInfos) { try { if (!client.tableExists(tableInfo.getTableName())) { throw new SchemaGenerationException("Table: " + tableInfo.getTableName() + " does not exist "); } } catch (Exception e) { logger.error("Error while validating tables, Caused by: " + e.getMessage()); throw new KunderaException("Error while validating tables, Caused by: " + e.getMessage()); } } }
@Override public void dropSchema() { for (TableInfo tableInfo : tableInfos) { try { client.deleteTable(tableInfo.getTableName()); } catch (Exception ex) { logger.error("Error during deleting tables in kudu, Caused by: ", ex); throw new SchemaGenerationException(ex, "Kudu"); } } }
/** * Drops table using cql3. * * @param tableInfo * the table info * @throws Exception * the exception */ private void dropTableUsingCql(TableInfo tableInfo) throws Exception { CQLTranslator translator = new CQLTranslator(); StringBuilder dropQuery = new StringBuilder("drop table "); translator.ensureCase(dropQuery, tableInfo.getTableName(), false); KunderaCoreUtils.printQuery(dropQuery.toString(), showQuery); cassandra_client.execute_cql3_query(ByteBuffer.wrap(dropQuery.toString().getBytes()), Compression.NONE, ConsistencyLevel.ONE); }
@Override protected void validate(List<TableInfo> tableInfos) { List listTables = r.db(databaseName).tableList().run(connection); for (TableInfo tableInfo : tableInfos) { try { if (!listTables.contains(tableInfo.getTableName())) { throw new SchemaGenerationException("Table: " + tableInfo.getTableName() + " does not exist "); } } catch (Exception e) { logger.error("Error while validating tables, Caused by: " + e.getMessage()); throw new KunderaException("Error while validating tables, Caused by: " + e.getMessage()); } } }
/** * Drop inverted index table. * * @param tableInfo * the table info */ private void dropInvertedIndexTable(TableInfo tableInfo) { boolean indexTableRequired = CassandraPropertyReader.csmd.isInvertedIndexingEnabled(databaseName)/* ) */ && !tableInfo.getEmbeddedColumnMetadatas().isEmpty(); if (indexTableRequired) { try { cassandra_client.system_drop_column_family(tableInfo.getTableName() + Constants.INDEX_TABLE_SUFFIX); } catch (Exception ex) { if (log.isWarnEnabled()) { log.warn("Error while dropping inverted index table, Caused by: ", ex); } } } }
@Override protected void update(List<TableInfo> tableInfos) { List listTables = r.db(databaseName).tableList().run(connection); for (TableInfo tableInfo : tableInfos) { try { if (!listTables.contains(tableInfo.getTableName())) { r.db(databaseName).tableCreate(tableInfo.getTableName()).run(connection); } } catch (Exception e) { logger.error("Error while updating tables, Caused by: " + e.getMessage()); throw new KunderaException("Error while updating tables, Caused by: " + e.getMessage()); } } }
/** * Gets the column family properties. * * @param tableInfo * the table info * @return the column family properties */ private Properties getColumnFamilyProperties(TableInfo tableInfo) { if (tables != null) { for (Table table : tables) { if (table != null && table.getName() != null && table.getName().equalsIgnoreCase(tableInfo.getTableName())) { return table.getProperties(); } } } return null; }
@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); } }
/** * Drops column family specified in table info. * * @param tableInfo * the table info * @throws Exception * the exception */ private void dropColumnFamily(TableInfo tableInfo) throws Exception { if (isCql3Enabled(tableInfo)) { dropTableUsingCql(tableInfo); } else { cassandra_client.system_drop_column_family(tableInfo.getTableName()); } }
/** * @param tableInfo * @return */ private DBObject setCollectionProperties(TableInfo tableInfo) { boolean isCappedCollection = isCappedCollection(tableInfo); DBObject options = new BasicDBObject(); if ((tableInfo.getLobColumnInfo().isEmpty() || tableInfo.getLobColumnInfo() == null) && isCappedCollection) { int collectionSize = MongoDBPropertyReader.msmd != null ? MongoDBPropertyReader.msmd.getCollectionSize( databaseName, tableInfo.getTableName()) : 100000; int max = MongoDBPropertyReader.msmd != null ? MongoDBPropertyReader.msmd.getMaxSize(databaseName, tableInfo.getTableName()) : 100; options.put(MongoDBConstants.CAPPED, isCappedCollection); options.put(MongoDBConstants.SIZE, collectionSize); options.put(MongoDBConstants.MAX, max); } return options; }
/** * showSchema Alters column type of an existing column. * * @param tableInfo * the table info * @param translator * the translator * @param column * the column * @throws Exception * the exception */ private void alterColumnType(TableInfo tableInfo, CQLTranslator translator, ColumnInfo column) throws Exception { StringBuilder alterColumnTypeQuery = new StringBuilder("ALTER TABLE "); translator.ensureCase(alterColumnTypeQuery, tableInfo.getTableName(), false); alterColumnTypeQuery.append(" ALTER "); translator.ensureCase(alterColumnTypeQuery, column.getColumnName(), false); alterColumnTypeQuery.append(" TYPE " + translator.getCQLType(CassandraValidationClassMapper.getValidationClass(column.getType(), isCql3Enabled(tableInfo)))); cassandra_client.execute_cql3_query(ByteBuffer.wrap(alterColumnTypeQuery.toString().getBytes()), Compression.NONE, ConsistencyLevel.ONE); KunderaCoreUtils.printQuery(alterColumnTypeQuery.toString(), showQuery); }
/** * Creates the index on table. * * @param tableInfo * the table info */ private void createIndexOnTable(TableInfo tableInfo) { List<IndexInfo> indexColumns = tableInfo.getColumnsToBeIndexed(); for (IndexInfo indexInfo : indexColumns) { if (indexInfo.getIndexType() != null && indexInfo.getIndexType().toLowerCase().equals(Constants.COMPOSITE)) { String[] columnNames = indexInfo.getColumnName().split(Constants.COMMA); createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), columnNames); } else { createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), indexInfo.getColumnName()); } } }
private void addColumnFamilies(List<TableInfo> tableInfos, HTableDescriptor hTableDescriptor, boolean isUpdate) throws IOException { if (admin.isTableEnabled(databaseName)) { admin.disableTable(databaseName); } for (TableInfo tableInfo : tableInfos) { HColumnDescriptor columnDescriptor = hTableDescriptor.getFamily(tableInfo.getTableName().getBytes()); if (columnDescriptor != null && !isUpdate) { admin.deleteColumn(databaseName, tableInfo.getTableName()); addColumn(tableInfo); } else if (columnDescriptor == null) { addColumn(tableInfo); } } if (admin.isTableDisabled(databaseName)) { admin.enableTable(databaseName); } }
/** * @param tableInfo * @return CfDef object */ private CfDef getTableMetadata(TableInfo tableInfo) { CfDef cfDef = new CfDef(); cfDef.setKeyspace(databaseName); cfDef.setName(tableInfo.getTableName()); cfDef.setKey_validation_class(CassandraValidationClassMapper.getValidationClass(tableInfo.getTableIdType(), isCql3Enabled(tableInfo))); Schema schema = CassandraPropertyReader.csmd.getSchema(databaseName); tables = schema != null ? schema.getTables() : null; Properties cfProperties = getColumnFamilyProperties(tableInfo); String defaultValidationClass = null; if (tableInfo.getType() != null && tableInfo.getType().equals(Type.SUPER_COLUMN_FAMILY.name())) { getSuperColumnFamilyMetadata(tableInfo, cfDef, defaultValidationClass); } else if (tableInfo.getType() != null) { getColumnFamilyMetadata(tableInfo, cfDef, cfProperties); } setColumnFamilyProperties(cfDef, cfProperties, null); return cfDef; }