/** * 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(); }
/** * Get the catalog of the truncate statement. * * @return com.stratio.crossdata.common.data.CatalogName */ public CatalogName getCatalog() { return tableName.getCatalogName(); }
/** * 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); } }
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(); }
/** * 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; }
/** * 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); }
/** * Drop table that was created previously. * * @param targetCluster The target cluster. * @param name The TableName of the Table. * @throws ConnectorException */ @Override public void dropTable(ClusterName targetCluster, TableName name) throws ConnectorException { session = sessions.get(targetCluster.getName()); DropTableStatement tableStatement = new DropTableStatement(name.getQualifiedName(), false); CassandraExecutor.execute(tableStatement.toString(), session); }
/** * 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); }
private String getFromClause() { StringBuilder sb = new StringBuilder(); sb.append(" FROM "); if (catalogInc) { sb.append(Utils.toCaseSensitive(catalog)).append("."); } sb.append(Utils.toCaseSensitive(tableName.getName())); return sb.toString(); }
throws ConnectorException { checkIndexMetadata(indexMetadata); session = sessions.get(targetCluster.getName()); CreateIndexStatement indexStatement; try { if(indexMetadata.getType() == IndexType.FULL_TEXT){ String tableName = Utils.toCaseSensitive(indexMetadata.getName().getTableName().getName()); String catalog = Utils.toCaseSensitive(indexMetadata.getName().getTableName().getCatalogName().getName()); String remove = "ALTER TABLE " + catalog + "." + tableName + " DROP " + indexMetadata .getName().getName(); CassandraExecutor.execute(remove, session);
/** * 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; }
@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); } }
@Override public String toString() { StringBuilder sb = new StringBuilder("TRUNCATE "); if (catalogInc) { sb.append(Utils.toCaseSensitive(catalog)).append("."); } sb.append(Utils.toCaseSensitive(tableName.getName())); return sb.toString(); }
/** * Close the session of the cluster name specified. * * @param name Name of the cluster. * @throws ConnectionException */ @Override public void close(ClusterName name) throws ConnectionException { LOG.info("Closing cassandra session"); sessions.get(name.getName()).close(); sessions.remove(name.getName()); }
/** * Controls if there is a session started for a cluster name. * * @param name cluster name. * @return if the connector is connected to the cluster. */ @Override public boolean isConnected(ClusterName name) { boolean connected; if (sessions.get(name.getName()) != null) { if (sessions.get(name.getName()).getCluster() != null) { connected = true; } else { connected = false; } } else { connected = false; } return connected; }
@Override public void update(ClusterName targetCluster, TableName tableName, Collection<Relation> assignments, Collection<Filter> whereClauses) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); UpdateTableStatement updateStatement = new UpdateTableStatement(tableName, assignments, whereClauses); String query = updateStatement.toString(); CassandraExecutor.execute(query, session); }
@Override public void truncate(ClusterName targetCluster, TableName tableName) throws ConnectorException { Session session = sessions.get(targetCluster.getName()); TruncateStatement truncateStatement = new TruncateStatement(tableName); String query = truncateStatement.toString(); CassandraExecutor.execute(query, session); }