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(); }
@Test(groups = "unit") public void should_create_table_with_udt_partition_key() throws Exception { // When SchemaStatement statement = createTable("test").addUDTPartitionKey("u", frozen("user")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE TABLE test(\n\t\t" + "u frozen<user>,\n\t\t" + "PRIMARY KEY(u))"); }
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); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The table 'test' cannot declare static columns '\\[stat\\]' without clustering columns") public void should_fail_if_static_column_in_non_clustered_table() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addStaticColumn("stat", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The keyspace name 'ADD' is not allowed because it is a reserved keyword") public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { createTable("ADD", "test") .addPartitionKey("pk", DataType.bigint()) .addColumn("col", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The table name 'ADD' is not allowed because it is a reserved keyword") public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { createTable("ADD") .addPartitionKey("pk", DataType.bigint()) .addColumn("col", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and clustering keys at the same time") public void should_fail_if_same_partition_and_clustering_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("pk", DataType.bigint()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and simple columns at the same time") public void should_fail_if_same_partition_and_simple_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addColumn("pk", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and static columns at the same time") public void should_fail_if_same_partition_and_static_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addStaticColumn("pk", DataType.text()) .getQueryString(); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_read_repair_chance_negative() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .readRepairChance(-1.3); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_read_repair_chance_out_of_bound() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .readRepairChance(1.3); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_negative_rows_per_partition() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(KeyCaching.ALL, rows(-3)); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and simple columns at the same time") public void should_fail_if_same_clustering_and_simple_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("cluster", DataType.bigint()) .addColumn("cluster", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The clustering column name 'ADD' is not allowed because it is a reserved keyword") public void should_fail_if_clustering_key_is_a_reserved_keyword() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("ADD", DataType.uuid()) .addColumn("col", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and static columns at the same time") public void should_fail_if_same_clustering_and_static_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("cluster", DataType.bigint()) .addStaticColumn("cluster", DataType.text()) .getQueryString(); }
@Test(groups = "unit", expectedExceptions = IllegalStateException.class) public void should_fail_when_both_caching_versions() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(Caching.KEYS_ONLY) .caching(KeyCaching.ALL, allRows()) .getQueryString(); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_blank_clustering_order_column_provided() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("", Direction.DESC); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_clustering_order_column_does_not_match_declared_clustering_keys() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col3", Direction.ASC); }