/** * Get the specified Catalog from the cassandra keyspace. * * @param session The cassandra session. * @param catalogName The catalog name of the cassandra keyspace. * @return A {@link com.stratio.crossdata.common.metadata.CatalogMetadata} . */ public static CatalogMetadata getKeyspacesByName(Session session, CatalogName catalogName, String cluster) { KeyspaceMetadata keyspace = session.getCluster().getMetadata().getKeyspace(Utils.toCaseSensitive(catalogName .getName())); CatalogName name = new CatalogName(keyspace.getName()); Map<Selector, Selector> options = new HashMap<>(); Map<String, String> replicationOptions = new HashMap<>(); for (Map.Entry<String, String> entry : replicationOptions.entrySet()) { options.put(new StringSelector(entry.getKey()), new StringSelector(entry.getValue())); } Map<TableName, TableMetadata> tables = getTablesFromKeyspace(session, keyspace, cluster); CatalogMetadata catalogMetadata = new CatalogMetadata(name, options, tables); return catalogMetadata; }
/** * Constructor Class. * @param tableName The table Name * @param whereClauses A list with the conditions */ public DeleteStatement(TableName tableName, List<Filter> whereClauses) { this.tableName = tableName; if (tableName.isCompletedName()) { catalogInc = true; catalog = tableName.getCatalogName().getName(); } this.whereClauses = whereClauses; }
/** * Obtain the existing keyspaces in cassandra. * * @param session The cassandra session. * @return A list of {@link com.stratio.crossdata.common.metadata.CatalogMetadata} . */ public static List<CatalogMetadata> getKeyspaces(Session session, String cluster) { List<CatalogMetadata> catalogMetadataList = new ArrayList<>(); List<KeyspaceMetadata> keyspaceMetadataList = session.getCluster().getMetadata().getKeyspaces(); for (KeyspaceMetadata keyspaceMetadata : keyspaceMetadataList) { //Catalogs CatalogName name = new CatalogName(keyspaceMetadata.getName()); Map<Selector, Selector> options = new HashMap<>(); Map<String, String> replicationOptions = new HashMap<>(); for (Map.Entry<String, String> entry : replicationOptions.entrySet()) { options.put(new StringSelector(entry.getKey()), new StringSelector(entry.getValue())); } //Tables Map<TableName, TableMetadata> tables = getTablesFromKeyspace(session, keyspaceMetadata, cluster); CatalogMetadata catalogMetadata = new CatalogMetadata(name, options, tables); catalogMetadataList.add(catalogMetadata); } return catalogMetadataList; }
/** * Create Catalog for Cassandra Connector. * * @param targetCluster The target cluster. * @param catalogMetadata The metadata of the catalog that will be created. * @throws ConnectorException */ @Override public void createCatalog(ClusterName targetCluster, CatalogMetadata catalogMetadata) throws ConnectorException { session = sessions.get(targetCluster.getName()); String catalogName = catalogMetadata.getName().getQualifiedName(); Map<Selector, Selector> options = catalogMetadata.getOptions(); String stringOptions = stringKeyspaceOptions(options); CreateCatalogStatement catalogStatement = new CreateCatalogStatement(catalogName, false, stringOptions); CassandraExecutor.execute(catalogStatement.toString(), session); }
/** * Class Constructor. * * @param tableName The table name of the truncate statement. */ public TruncateStatement(TableName tableName) { this.tableName = tableName; this.catalogInc= tableName.isCompletedName(); this.catalog= tableName.getCatalogName().getName(); }
@Override public String toString() { StringBuilder sb = new StringBuilder("ALTER TABLE "); sb.append(Utils.toCaseSensitive(tableName.getCatalogName().getName())).append('.').append(Utils.toCaseSensitive (tableName.getName())); switch (option) {
@Override public void alterCatalog(ClusterName targetCluster, CatalogName catalogName, Map<Selector, Selector> options) throws ConnectorException { session = sessions.get(targetCluster.getName()); String stringOptions = stringKeyspaceOptions(options); if(!stringOptions.isEmpty()){ AlterCatalogStatement alterCatalogStatement = new AlterCatalogStatement(catalogName.getName(), stringOptions); CassandraExecutor.execute(alterCatalogStatement.toString(), session); } }
/** * Drop Catalog that was created previously. * * @param targetCluster The target cluster. * @param name The CatalogName of the Catalog. * @throws ConnectorException */ @Override public void dropCatalog(ClusterName targetCluster, CatalogName name) throws ConnectorException { session = sessions.get(targetCluster.getName()); DropCatalogStatement catalogStatement = new DropCatalogStatement(name.getName(), false); CassandraExecutor.execute(catalogStatement.toString(), session); }
@Override public String toString() { StringBuilder sb = new StringBuilder("UPDATE "); sb.append(Utils.toCaseSensitive(tableName.getCatalogName().getName())).append('.') .append(Utils.toCaseSensitive(tableName .getName()));
if (catalogInc) { CatalogName catalogName = tableName.getCatalogName(); catalog = catalogName.getName();
int primaryKeyType, String properties, boolean ifNotExists) throws ExecutionException { this.tableName = tableMetadata.getName().getName(); this.catalog = tableMetadata.getName().getCatalogName().getName(); this.catalogInc = true; this.tableColumns = tableMetadata.getColumns();
/** * Class constructor. * * @param index The name of the index. * @param ifExists Whether it should be removed only if exists. */ public DropIndexStatement(IndexMetadata index, boolean ifExists) { if (index.getColumns() != null && !index.getColumns().isEmpty()) { this.catalogInc = true; this.catalog = index.getName().getTableName().getCatalogName().getName(); } else { String[] indexQ = index.getName().getQualifiedName().split("\\."); if (indexQ.length > 1) { this.catalog = indexQ[0]; catalogInc = true; } else { catalogInc = false; } } this.indexName = index.getName().getName(); this.ifExists = ifExists; }
private String insertBlock(Row row, TableMetadata targetTable, boolean ifNotExists) throws ExecutionException { Set<String> keys = row.getCells().keySet(); Map<ColumnName, ColumnMetadata> columnsWithMetadata = targetTable.getColumns(); Map<String, ColumnInsertCassandra> columnsMetadata = new HashMap<>(); try { for (String key : keys) { ColumnName col = new ColumnName(targetTable.getName().getCatalogName().getName(), targetTable.getName().getName(), key); columnsMetadata.put(key, new ColumnInsertCassandra(columnsWithMetadata.get(col).getColumnType(), row.getCell(key).toString(), key)); } } catch (Exception e) { throw new ExecutionException("Trying insert data in a not existing column", e); } InsertIntoStatement insertStatement = new InsertIntoStatement(targetTable, columnsMetadata, ifNotExists); return insertStatement.toString(); }
this.type = indexMetadata.getType(); this.tableName = indexMetadata.getName().getTableName().getName(); this.keyspace = indexMetadata.getName().getTableName().getCatalogName().getName(); if (keyspace != null) { this.keyspaceIncluded = true; columnForIndex = indexMetadata.getName().getName(); String catalog= Utils.toCaseSensitive(indexMetadata.getName().getTableName().getCatalogName() .getName()); String table=Utils.toCaseSensitive(indexMetadata.getName().getTableName().getName()); session.execute(
String catalog = Utils.toCaseSensitive(indexMetadata.getName().getTableName().getCatalogName().getName()); String remove = "ALTER TABLE " + catalog + "." + tableName + " DROP " + indexMetadata .getName().getName();
/** * Get the Crossdata TableMetadata from a tableName that is search into cassandra table metadata. * * @param session The cassandra session. * @param tableName The table name to search. * @return A {@link com.stratio.crossdata.common.metadata.TableMetadata} . */ public static TableMetadata getTablesByTableName(Session session, TableName tableName, String cluster) throws ConnectorException { Metadata clusterMetadata = session.getCluster().getMetadata(); String ks = Utils.toCaseSensitive(tableName.getCatalogName().getName()); KeyspaceMetadata ksMetadata = clusterMetadata.getKeyspace(ks); if(clusterMetadata.getKeyspace(ks) == null){ throw new ConnectorException("Catalog " + ks + " not found"); } String tn = Utils.toCaseSensitive(tableName.getName()); com.datastax.driver.core.TableMetadata cassandraTableMetadata = ksMetadata.getTable(tn); if(ksMetadata.getTable(tn) == null){ throw new ConnectorException("Table " + ks + "." + tn + " not found"); } return getXDTableMetadata(session, cassandraTableMetadata, cluster); }
/** * Drop Index that was created previously. * * @param targetCluster The target cluster. * @param indexMetadata The IndexName of the index. * @throws ConnectorException */ @Override public void dropIndex(ClusterName targetCluster, IndexMetadata indexMetadata) throws ConnectorException { String remove; session = sessions.get(targetCluster.getName()); DropIndexStatement indexStatement = new DropIndexStatement(indexMetadata, false); //remove de column create for the index and automatically delete the index too String tableName = Utils.toCaseSensitive(indexMetadata.getName().getTableName().getName()); String catalog = Utils.toCaseSensitive(indexMetadata.getName().getTableName().getCatalogName().getName()); if (indexMetadata.getType() == IndexType.FULL_TEXT) { remove = "ALTER TABLE " + catalog + "." + tableName + " DROP " + Utils.toCaseSensitive(indexMetadata.getName().getName()); CassandraExecutor.execute(remove, session); } else { remove = "DROP INDEX " + catalog + "." + Utils.toCaseSensitive(indexMetadata.getName().getName()); /* String removeColumn = "ALTER TABLE " + catalog + "." + tableName + " DROP " + Utils.toCaseSensitive (indexMetadata .getName().getName());*/ CassandraExecutor.execute(remove, session); //CassandraExecutor.execute(removeColumn, session); } }
public static String getFormatType(ColumnSelector left, Selector right, Session session) { .getCatalogName().getName())).getTable( Utils.toCaseSensitive(left.getColumnName().getTableName().getName())).getColumn (Utils.toCaseSensitive(left.getColumnName().getName())).getType().getName()) {