use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project automatiko-engine by automatiko-io.
the class CassandraProcessInstances method createTable.
protected void createTable() {
if (config.createKeyspace().orElse(true)) {
CreateKeyspace createKs = createKeyspace(config.keyspace().orElse("automatiko")).ifNotExists().withSimpleStrategy(1);
cqlSession.execute(createKs.build());
}
CreateTable createTable = SchemaBuilder.createTable(config.keyspace().orElse("automatiko"), tableName).ifNotExists().withPartitionKey(INSTANCE_ID_FIELD, DataTypes.TEXT).withColumn(STATUS_FIELD, DataTypes.INT).withColumn(CONTENT_FIELD, DataTypes.BLOB).withColumn(TAGS_FIELD, DataTypes.setOf(DataTypes.TEXT)).withColumn(VERSION_FIELD, DataTypes.BIGINT);
cqlSession.execute(createTable.build());
CreateIndex index = SchemaBuilder.createIndex(tableName + "_STATUS_IDX").ifNotExists().onTable(config.keyspace().orElse("automatiko"), tableName).andColumn(STATUS_FIELD);
cqlSession.execute(index.build());
}
use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project automatiko-engine by automatiko-io.
the class CassandraJobService method createTable.
protected void createTable() {
if (config.createKeyspace().orElse(true)) {
CreateKeyspace createKs = createKeyspace(config.keyspace().orElse("automatiko")).ifNotExists().withSimpleStrategy(1);
cqlSession.execute(createKs.build());
}
CreateTable createTable = SchemaBuilder.createTable(config.keyspace().orElse("automatiko"), tableName).ifNotExists().withPartitionKey(INSTANCE_ID_FIELD, DataTypes.TEXT).withColumn(FIRE_AT_FIELD, DataTypes.BIGINT).withColumn(OWNER_INSTANCE_ID_FIELD, DataTypes.TEXT).withColumn(OWNER_DEF_ID_FIELD, DataTypes.TEXT).withColumn(TRIGGER_TYPE_FIELD, DataTypes.TEXT).withColumn(STATUS_FIELD, DataTypes.TEXT).withColumn(FIRE_LIMIT_FIELD, DataTypes.INT).withColumn(REPEAT_INTERVAL_FIELD, DataTypes.BIGINT).withColumn(EXPRESSION_FIELD, DataTypes.TEXT);
cqlSession.execute(createTable.build());
CreateIndex index = SchemaBuilder.createIndex(tableName + "_IDX").ifNotExists().onTable(config.keyspace().orElse("automatiko"), tableName).andColumn(FIRE_AT_FIELD);
cqlSession.execute(index.build());
}
use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project geowave by locationtech.
the class CassandraOperations method addOptions.
private CreateTable addOptions(final CreateTable create) {
final Iterator<String[]> validOptions = options.getTableOptions().entrySet().stream().map(e -> new String[] { e.getKey(), e.getValue() }).iterator();
CreateTable retVal = create;
boolean addCompaction = true;
boolean addGcGraceSeconds = true;
while (validOptions.hasNext()) {
final String[] option = validOptions.next();
final String key = option[0].trim();
final String valueStr = option[1].trim();
Object value;
if (valueStr.startsWith("{")) {
try {
value = new ObjectMapper().readValue(valueStr, HashMap.class);
} catch (final IOException e) {
LOGGER.warn("Unable to convert '" + valueStr + "' to a JSON map for cassandra table creation", e);
value = valueStr;
}
} else {
value = valueStr;
}
if ("compaction".equals(key)) {
addCompaction = false;
LOGGER.info("Found compaction in general table options, ignoring --compactionStrategy option.");
} else if ("gc_grace_seconds".equals(key)) {
addGcGraceSeconds = false;
LOGGER.info("Found gc_grace_seconds in general table options, ignoring --gcGraceSeconds option.");
}
retVal = (CreateTable) retVal.withOption(key, value);
}
if (addCompaction) {
retVal = (CreateTable) retVal.withCompaction(options.getCompactionStrategy());
}
if (addGcGraceSeconds) {
retVal = (CreateTable) retVal.withGcGraceSeconds(options.getGcGraceSeconds());
}
return retVal;
}
use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project stargate by stargate.
the class GeoTypeTest method createSchema.
@BeforeAll
public static void createSchema(CqlSession session, @TestKeyspace CqlIdentifier keyspaceId) {
allTypes = generateAllTypes(keyspaceId);
// Creating a new table for each type is too slow, use a single table with all possible types:
CreateTable createTableQuery = createTable("test").withPartitionKey("k", DataTypes.INT);
for (TypeSample<?> sample : allTypes) {
createTableQuery = createTableQuery.withColumn(sample.columnName, sample.cqlType);
}
session.execute(createTableQuery.asCql());
}
use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project geowave by locationtech.
the class CassandraOperations method createTable.
private boolean createTable(final String indexName) {
synchronized (CREATE_TABLE_MUTEX) {
try {
if (!indexExists(indexName)) {
final String tableName = getCassandraSafeName(indexName);
CreateTable create = addOptions(CassandraField.GW_PARTITION_ID_KEY.addPartitionKey(getCreateTable(tableName)));
CassandraField[] fields = CassandraField.values();
if (DataIndexUtils.isDataIndex(tableName)) {
fields = Arrays.stream(fields).filter(f -> f.isDataIndexColumn()).filter(f -> !f.isPartitionKey()).toArray(i -> new CassandraField[i]);
}
for (final CassandraField f : fields) {
create = f.addColumn(create);
}
executeCreateTable(create, tableName);
return true;
}
} catch (final IOException e) {
LOGGER.error("Unable to create table '" + indexName + "'", e);
}
}
return false;
}
Aggregations