Search in sources :

Example 1 with CassandraField

use of org.locationtech.geowave.datastore.cassandra.CassandraRow.CassandraField 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 2 with CassandraField

use of org.locationtech.geowave.datastore.cassandra.CassandraRow.CassandraField in project geowave by locationtech.

the class CassandraOperations method getBatchedWrite.

public BatchedWrite getBatchedWrite(final String tableName) {
    PreparedStatement preparedWrite;
    final String safeTableName = getCassandraSafeName(tableName);
    final boolean isDataIndex = DataIndexUtils.isDataIndex(tableName);
    synchronized (state.preparedWritesPerTable) {
        preparedWrite = state.preparedWritesPerTable.get(safeTableName);
        if (preparedWrite == null) {
            final InsertInto insert = getInsert(safeTableName);
            CassandraField[] fields = CassandraField.values();
            if (isDataIndex) {
                fields = Arrays.stream(fields).filter(f -> f.isDataIndexColumn()).toArray(i -> new CassandraField[i]);
            }
            RegularInsert regInsert = null;
            for (final CassandraField f : fields) {
                regInsert = (regInsert != null ? regInsert : insert).value(f.getFieldName(), QueryBuilder.bindMarker(f.getBindMarkerName()));
            }
            preparedWrite = session.prepare(regInsert.build());
            state.preparedWritesPerTable.put(safeTableName, preparedWrite);
        }
    }
    return new BatchedWrite(session, preparedWrite, isDataIndex ? 1 : options.getBatchWriteSize(), isDataIndex, options.isVisibilityEnabled());
}
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) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) InsertInto(com.datastax.oss.driver.api.querybuilder.insert.InsertInto) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)

Aggregations

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 CreateTable (com.datastax.oss.driver.api.querybuilder.schema.CreateTable)2 CreateTableStart (com.datastax.oss.driver.api.querybuilder.schema.CreateTableStart)2 Drop (com.datastax.oss.driver.api.querybuilder.schema.Drop)2 Select (com.datastax.oss.driver.api.querybuilder.select.Select)2