private String getCreateTaskLookupTableStatement() { return SchemaBuilder.createTable(config.getCassandraKeyspace(), TABLE_TASK_LOOKUP) .ifNotExists() .addPartitionKey(TASK_ID_KEY, DataType.uuid()) .addColumn(WORKFLOW_ID_KEY, DataType.uuid()) .getQueryString(); }
private static void createTableIfNotExists(final com.datastax.driver.core.Session session, final String table, final Logger log) { Create createTable = SchemaBuilder.createTable(table) .addPartitionKey(ID, DataType.varchar()) .addColumn(CREATED_AT, DataType.timestamp()) .addColumn(ACCESSED_AT, DataType.timestamp()) .addColumn(SAVED_AT, DataType.timestamp()) .addColumn(ATTRIBUTES, DataType.map(DataType.varchar(), DataType.varchar())) .ifNotExists(); Futures.addCallback(session.executeAsync(createTable), new FutureCallback<ResultSet>() { @Override public void onSuccess(final ResultSet result) { log.debug("Session table successfully created"); } @Override public void onFailure(final Throwable x) { log.error("Create session table resulted in exception", x); } }); }
private String getCreateWorkflowsTableStatement() { return SchemaBuilder.createTable(config.getCassandraKeyspace(), TABLE_WORKFLOWS) .ifNotExists() .addPartitionKey(WORKFLOW_ID_KEY, DataType.uuid()) .addPartitionKey(SHARD_ID_KEY, DataType.cint()) .addClusteringColumn(ENTITY_KEY, DataType.text()) .addClusteringColumn(TASK_ID_KEY, DataType.text()) .addColumn(PAYLOAD_KEY, DataType.text()) .addStaticColumn(TOTAL_TASKS_KEY, DataType.cint()) .addStaticColumn(TOTAL_PARTITIONS_KEY, DataType.cint()) .getQueryString(); }
protected void createTable(CassandraSessionPool.Session session, ImmutableMap<HugeKeys, DataType> partitionKeys, ImmutableMap<HugeKeys, DataType> clusteringKeys, ImmutableMap<HugeKeys, DataType> columns) { Create table = SchemaBuilder.createTable(this.table()).ifNotExists(); for (Map.Entry<HugeKeys, DataType> entry : partitionKeys.entrySet()) { table.addPartitionKey(formatKey(entry.getKey()), entry.getValue()); } for (Map.Entry<HugeKeys, DataType> entry : clusteringKeys.entrySet()) { table.addClusteringColumn(formatKey(entry.getKey()), entry.getValue()); } for (Map.Entry<HugeKeys, DataType> entry : columns.entrySet()) { table.addColumn(formatKey(entry.getKey()), entry.getValue()); } LOG.debug("Create table: {}", table); session.execute(table); }
public void createIndex(CassandraSessionPool.Session session) { Create create = SchemaBuilder.createTable(this.table) .ifNotExists(); create.addPartitionKey(NAME, DataType.text()); create.addColumn(ELEMENT_IDS, DataType.set(DataType.cint())); session.execute(create); }
/** * Create index label table for vertex/edge * @param session DB session * @param table index table name */ private static void createIndexTable(CassandraSessionPool.Session session, String table) { Create tableBuilder = SchemaBuilder.createTable(table).ifNotExists(); tableBuilder.addPartitionKey(LABEL, DataType.cint()); tableBuilder.addColumn(ELEMENT_IDS, DataType.set(DataType.text())); session.execute(tableBuilder); }
@Test(groups = "unit") public void should_create_simple_table_if_not_exists() throws Exception { // When SchemaStatement statement = createTable("test") .ifNotExists() .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE IF NOT EXISTS test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))"); }
@Test(groups = "short") public void should_add_and_drop_a_column() { // Create a table, add a column to it with an alter table statement and delete that column session() .execute( SchemaBuilder.createTable("ks", "DropColumn") .ifNotExists() .addPartitionKey("a", DataType.cint())); // Add and then drop a column session() .execute(SchemaBuilder.alterTable("ks", "DropColumn").addColumn("b").type(DataType.cint())); session().execute(SchemaBuilder.alterTable("ks", "DropColumn").dropColumn("b")); // Check that only column a exist ResultSet rows = session() .execute( "SELECT column_name, type, validator " + "FROM system.schema_columns " + "WHERE keyspace_name='ks' AND columnfamily_name='dropcolumn'"); Iterator<Row> iterator = rows.iterator(); verifyNextColumnDefinition( iterator, "a", "partition_key", "org.apache.cassandra.db.marshal.Int32Type"); assertThat(iterator.hasNext()).isFalse(); }
private Create getCreateTable(final String safeTableName) { return SchemaBuilder.createTable(gwNamespace, safeTableName).ifNotExists(); }
public Builder statement(Function<Create, Create> toCreateStatement) { Preconditions.checkState(comment.isPresent(), "`comment` is compulsory"); Create createStatement = toCreateStatement.apply( SchemaBuilder.createTable(tableName) .ifNotExists()); return originalBuilderReference.addTable( new CassandraTable(tableName, options.orElse(Function.identity()) .apply(createStatement.withOptions().comment(comment.get())))); } }
public Builder statement(Function<Create, Create> toCreateStatement) { Preconditions.checkState(comment.isPresent(), "`comment` is compulsory"); Create createStatement = toCreateStatement.apply( SchemaBuilder.createTable(tableName) .ifNotExists()); return originalBuilderReference.addTable( new CassandraTable(tableName, options.orElse(Function.identity()) .apply(createStatement.withOptions().comment(comment.get())))); } }
protected void createTable(CassandraSessionPool.Session session, ImmutableMap<HugeKeys, DataType> partitionKeys, ImmutableMap<HugeKeys, DataType> clusteringKeys, ImmutableMap<HugeKeys, DataType> columns) { Create table = SchemaBuilder.createTable(this.table()).ifNotExists(); for (Map.Entry<HugeKeys, DataType> entry : partitionKeys.entrySet()) { table.addPartitionKey(formatKey(entry.getKey()), entry.getValue()); } for (Map.Entry<HugeKeys, DataType> entry : clusteringKeys.entrySet()) { table.addClusteringColumn(formatKey(entry.getKey()), entry.getValue()); } for (Map.Entry<HugeKeys, DataType> entry : columns.entrySet()) { table.addColumn(formatKey(entry.getKey()), entry.getValue()); } LOG.debug("Create table: {}", table); session.execute(table); }
.execute( SchemaBuilder.createTable("ks", "CreateTable") .ifNotExists() .addPartitionKey("a", DataType.cint()) .addUDTPartitionKey("b", myUDT)
.ifNotExists() .addPartitionKey(ROW, DataType.blob()) .addClusteringColumn(COLUMN, DataType.blob())
public void createIndex(CassandraSessionPool.Session session) { Create create = SchemaBuilder.createTable(this.table) .ifNotExists(); create.addPartitionKey(NAME, DataType.text()); create.addColumn(ELEMENT_IDS, DataType.set(DataType.cint())); session.execute(create); }
/** * Create index label table for vertex/edge * @param session DB session * @param table index table name */ private static void createIndexTable(CassandraSessionPool.Session session, String table) { Create tableBuilder = SchemaBuilder.createTable(table).ifNotExists(); tableBuilder.addPartitionKey(LABEL, DataType.cint()); tableBuilder.addColumn(ELEMENT_IDS, DataType.set(DataType.text())); session.execute(tableBuilder); }
@Test(groups = "unit") public void should_create_simple_table_if_not_exists() throws Exception { // When SchemaStatement statement = createTable("test") .ifNotExists() .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE IF NOT EXISTS test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))"); }
private static void initializeTable(final Session session, final String keyspaceName, final String tableName, final Configuration configuration, final boolean allowCompactStorage) { final Options createTable = createTable(keyspaceName, tableName) .ifNotExists() .addPartitionKey(KEY_COLUMN_NAME, DataType.blob()) .addClusteringColumn(COLUMN_COLUMN_NAME, DataType.blob()) .addColumn(VALUE_COLUMN_NAME, DataType.blob()) .withOptions() .compressionOptions(compressionOptions(configuration)) .compactionOptions(compactionOptions(configuration)); // COMPACT STORAGE is allowed on Cassandra 2 or earlier // when COMPACT STORAGE is allowed, the default is to enable it final boolean useCompactStorage = (allowCompactStorage && configuration.has(CF_COMPACT_STORAGE)) ? configuration.get(CF_COMPACT_STORAGE) : allowCompactStorage; session.execute(useCompactStorage ? createTable.compactStorage() : createTable); }
private static void createTableIfNotExists(final com.datastax.driver.core.Session session, final String table, final Logger log) { Create createTable = SchemaBuilder.createTable(table) .addPartitionKey(ID, DataType.varchar()) .addColumn(CREATED_AT, DataType.timestamp()) .addColumn(ACCESSED_AT, DataType.timestamp()) .addColumn(SAVED_AT, DataType.timestamp()) .addColumn(ATTRIBUTES, DataType.map(DataType.varchar(), DataType.varchar())) .ifNotExists(); Futures.addCallback(session.executeAsync(createTable), new FutureCallback<ResultSet>() { @Override public void onSuccess(final ResultSet result) { log.debug("Session table successfully created"); } @Override public void onFailure(final Throwable x) { log.error("Create session table resulted in exception", x); } }); }
.ifNotExists() .addPartitionKey(ROW, DataType.blob()) .addClusteringColumn(COLUMN, DataType.blob())