private String getCreateKeyspaceStatement() { return SchemaBuilder.createKeyspace(config.getCassandraKeyspace()) .ifNotExists() .with() .replication(ImmutableMap.of("class", config.getReplicationStrategy(), config.getReplicationFactorKey(), config.getReplicationFactorValue())) .durableWrites(true) .getQueryString(); }
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 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(); }
private CompactionOptions<?> getCompaction(boolean appendHeavyReadLight) { return appendHeavyReadLight ? SchemaBuilder.sizedTieredStategy().minThreshold(4).maxThreshold(32) : SchemaBuilder.leveledStrategy(); }
/** * Define the new type of the altered column, when that type contains a UDT. * * @param udtType the UDT type. Use {@link SchemaBuilder#frozen(String)} or {@link * SchemaBuilder#udtLiteral(String)}. * @return the final statement. */ public SchemaStatement udtType(UDTType udtType) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ALTER " + columnName + " TYPE " + udtType.asCQLString()); } }
static UDTType literal(String literal) { SchemaStatement.validateNotEmpty(literal, "UDT type literal"); return new UDTType(literal); } }
private CompressionOptions getCompression(int blockSize) { int chunkLength = blockSize != 0 ? blockSize : AtlasDbConstants.MINIMUM_COMPRESSION_BLOCK_SIZE_KB; return SchemaBuilder.lz4().withChunkLengthInKb(chunkLength); }
/** * Add options for this CREATE KEYSPACE statement. * * @return the options of this CREATE KEYSPACE statement. */ public KeyspaceOptions with() { return new KeyspaceOptions(buildCommand(), keyspaceName); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The altered column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_altered_column_is_a_reserved_keyword() throws Exception { alterTable("test").alterColumn("add").type(DataType.ascii()).getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_added_column_is_a_reserved_keyword() throws Exception { alterTable("test").addColumn("add").type(DataType.ascii()).getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The dropped column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_drop_column_is_a_reserved_keyword() throws Exception { alterTable("test").dropColumn("add").getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_new_renamed_column_is_a_reserved_keyword() throws Exception { alterTable("test").renameColumn("col").to("add"); }
/** * Create options for the LZ4 compression strategy, to use in a CREATE or ALTER TABLE statement. * * @return the options. */ public static TableOptions.CompressionOptions lz4() { return new TableOptions.CompressionOptions(TableOptions.CompressionOptions.Algorithm.LZ4); }
/** * Start building a new CREATE TABLE statement. * * @param keyspaceName the name of the keyspace to be used. * @param tableName the name of the table to create. * @return an in-construction CREATE TABLE statement. */ public static Create createTable(String keyspaceName, String tableName) { return new Create(keyspaceName, tableName); }
/** * Start building a new ALTER TABLE statement. * * @param keyspaceName the name of the keyspace to be used. * @param tableName the name of the table to be altered. * @return an in-construction ALTER TABLE statement. */ public static Alter alterTable(String keyspaceName, String tableName) { return new Alter(keyspaceName, tableName); }
/** * Start building a new CREATE INDEX statement. * * @param indexName the name of the table to create. * @return an in-construction CREATE INDEX statement. */ public static CreateIndex createIndex(String indexName) { return new CreateIndex(indexName); }
/** * Add options for this CREATE TABLE statement. * * @return the options of this CREATE TABLE statement. */ public Options withOptions() { return new Options(this); }
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); } }); }
static UDTType frozen(String udtName) { SchemaStatement.validateNotEmpty(udtName, "UDT name"); return new UDTType("frozen<" + udtName + ">"); }
/** * Create options for the Deflate compression strategy, to use in a CREATE or ALTER TABLE * statement. * * @return the options. */ public static TableOptions.CompressionOptions deflate() { return new TableOptions.CompressionOptions(TableOptions.CompressionOptions.Algorithm.DEFLATE); }