Search in sources :

Example 6 with CreateTable

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;
}
Also used : CassandraRow(org.locationtech.geowave.datastore.cassandra.CassandraRow) QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) Arrays(java.util.Arrays) CassandraOptions(org.locationtech.geowave.datastore.cassandra.config.CassandraOptions) RecordReaderParams(org.locationtech.geowave.mapreduce.splits.RecordReaderParams) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) LoggerFactory(org.slf4j.LoggerFactory) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) DeleteSelection(com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection) ByteBuffer(java.nio.ByteBuffer) KeyspaceStatePool(org.locationtech.geowave.datastore.cassandra.util.KeyspaceStatePool) CreateTable(com.datastax.oss.driver.api.querybuilder.schema.CreateTable) SessionPool(org.locationtech.geowave.datastore.cassandra.util.SessionPool) Drop(com.datastax.oss.driver.api.querybuilder.schema.Drop) Duration(java.time.Duration) Map(java.util.Map) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) InsertInto(com.datastax.oss.driver.api.querybuilder.insert.InsertInto) Select(com.datastax.oss.driver.api.querybuilder.select.Select) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) SelectFrom(com.datastax.oss.driver.api.querybuilder.select.SelectFrom) RowReader(org.locationtech.geowave.core.store.operations.RowReader) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) KeyspaceState(org.locationtech.geowave.datastore.cassandra.util.KeyspaceStatePool.KeyspaceState) Sets(com.google.common.collect.Sets) SchemaBuilder(com.datastax.oss.driver.api.querybuilder.SchemaBuilder) List(java.util.List) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) Stream(java.util.stream.Stream) Optional(java.util.Optional) CassandraField(org.locationtech.geowave.datastore.cassandra.CassandraRow.CassandraField) ByteArray(org.locationtech.geowave.core.index.ByteArray) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) StringUtils(org.locationtech.geowave.core.index.StringUtils) DataIndexUtils(org.locationtech.geowave.core.store.base.dataidx.DataIndexUtils) GeoWaveRowIteratorTransformer(org.locationtech.geowave.core.store.entities.GeoWaveRowIteratorTransformer) HashMap(java.util.HashMap) RowDeleter(org.locationtech.geowave.core.store.operations.RowDeleter) Function(java.util.function.Function) RowReaderWrapper(org.locationtech.geowave.core.store.operations.RowReaderWrapper) BaseDataStoreOptions(org.locationtech.geowave.core.store.BaseDataStoreOptions) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) MapReduceDataStoreOperations(org.locationtech.geowave.mapreduce.MapReduceDataStoreOperations) AbstractGeoWavePersistence(org.locationtech.geowave.core.store.metadata.AbstractGeoWavePersistence) CqlSession(com.datastax.oss.driver.api.core.CqlSession) ReaderParams(org.locationtech.geowave.core.store.operations.ReaderParams) CreateTableStart(com.datastax.oss.driver.api.querybuilder.schema.CreateTableStart) ClientVisibilityFilter(org.locationtech.geowave.core.store.query.filter.ClientVisibilityFilter) Index(org.locationtech.geowave.core.store.api.Index) Row(com.datastax.oss.driver.api.core.cql.Row) ExecutorService(java.util.concurrent.ExecutorService) CassandraRequiredOptions(org.locationtech.geowave.datastore.cassandra.config.CassandraRequiredOptions) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) MetadataDeleter(org.locationtech.geowave.core.store.operations.MetadataDeleter) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) Literal(com.datastax.oss.driver.api.querybuilder.Literal) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DataIndexReaderParams(org.locationtech.geowave.core.store.operations.DataIndexReaderParams) BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) IOException(java.io.IOException) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) TypeCodecs(com.datastax.oss.driver.api.core.type.codec.TypeCodecs) CassandraUtils(org.locationtech.geowave.datastore.cassandra.util.CassandraUtils) ChronoUnit(java.time.temporal.ChronoUnit) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) ByteArrayUtils(org.locationtech.geowave.core.index.ByteArrayUtils) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Statement(com.datastax.oss.driver.api.core.cql.Statement) CassandraField(org.locationtech.geowave.datastore.cassandra.CassandraRow.CassandraField) CreateTable(com.datastax.oss.driver.api.querybuilder.schema.CreateTable) IOException(java.io.IOException)

Example 7 with CreateTable

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;
}
Also used : CreateTable(com.datastax.oss.driver.api.querybuilder.schema.CreateTable) IOException(java.io.IOException)

Example 8 with CreateTable

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());
}
Also used : CreateTable(com.datastax.oss.driver.api.querybuilder.schema.CreateTable) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

CreateTable (com.datastax.oss.driver.api.querybuilder.schema.CreateTable)8 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 BoundStatementBuilder (com.datastax.oss.driver.api.core.cql.BoundStatementBuilder)2 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)2 Row (com.datastax.oss.driver.api.core.cql.Row)2 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 Statement (com.datastax.oss.driver.api.core.cql.Statement)2 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)2 DataTypes (com.datastax.oss.driver.api.core.type.DataTypes)2 TypeCodecs (com.datastax.oss.driver.api.core.type.codec.TypeCodecs)2 Literal (com.datastax.oss.driver.api.querybuilder.Literal)2 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)2 SchemaBuilder (com.datastax.oss.driver.api.querybuilder.SchemaBuilder)2 DeleteSelection (com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection)2 InsertInto (com.datastax.oss.driver.api.querybuilder.insert.InsertInto)2 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)2