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;
}
use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project geowave by locationtech.
the class CassandraOperations method ensureTableExists.
private String ensureTableExists(final MetadataType metadataType) {
final String tableName = getMetadataTableName(metadataType);
// this checks for existence prior to create
synchronized (CREATE_TABLE_MUTEX) {
try {
if (!indexExists(tableName)) {
// create table
CreateTable create = addOptions(getCreateTable(tableName).withPartitionKey(CassandraMetadataWriter.PRIMARY_ID_KEY, DataTypes.BLOB));
if (MetadataType.STATISTICS.equals(metadataType) || MetadataType.STATISTIC_VALUES.equals(metadataType) || MetadataType.LEGACY_STATISTICS.equals(metadataType) || MetadataType.INTERNAL_ADAPTER.equals(metadataType) || MetadataType.INDEX_MAPPINGS.equals(metadataType)) {
create = create.withClusteringColumn(CassandraMetadataWriter.SECONDARY_ID_KEY, DataTypes.BLOB).withClusteringColumn(CassandraMetadataWriter.TIMESTAMP_ID_KEY, DataTypes.TIMEUUID);
if (MetadataType.STATISTIC_VALUES.equals(metadataType) || MetadataType.LEGACY_STATISTICS.equals(metadataType)) {
create = create.withColumn(CassandraMetadataWriter.VISIBILITY_KEY, DataTypes.BLOB);
}
}
executeCreateTable(create.withColumn(CassandraMetadataWriter.VALUE_KEY, DataTypes.BLOB), tableName);
}
} catch (final IOException e) {
LOGGER.warn("Unable to check if table exists", e);
}
}
return tableName;
}
use of com.datastax.oss.driver.api.querybuilder.schema.CreateTable in project stargate by stargate.
the class DataTypeTest 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);
if (sample.cqlType instanceof UserDefinedType) {
session.execute(((UserDefinedType) sample.cqlType).describe(false));
}
}
session.execute(createTableQuery.asCql());
}
Aggregations