use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method get.
public Optional<Result> get(Get get) throws CrudException {
throwIfTransactionFinished();
ResponseOrError responseOrError = sendRequest(TwoPhaseCommitTransactionRequest.newBuilder().setGetRequest(GetRequest.newBuilder().setGet(ProtoUtils.toGet(get))).build());
throwIfErrorForCrud(responseOrError);
GetResponse getResponse = responseOrError.getResponse().getGetResponse();
if (getResponse.hasResult()) {
TableMetadata tableMetadata = getTableMetadata(get);
return Optional.of(ProtoUtils.toResult(getResponse.getResult(), tableMetadata));
}
return Optional.empty();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class CassandraAdminTest method createTableInternal_ReservedKeywords_ShouldExecuteCreateTableStatementProperly.
@Test
public void createTableInternal_ReservedKeywords_ShouldExecuteCreateTableStatementProperly() throws ExecutionException {
// Arrange
String namespace = "keyspace";
String table = "table";
TableMetadata tableMetadata = TableMetadata.newBuilder().addPartitionKey("from").addPartitionKey("c7").addClusteringKey("two").addClusteringKey("c6", Order.DESC).addColumn("from", DataType.INT).addColumn("to", DataType.TEXT).addColumn("one", DataType.BLOB).addColumn("two", DataType.DOUBLE).addColumn("password", DataType.BIGINT).addColumn("c6", DataType.BOOLEAN).addColumn("c7", DataType.TEXT).addSecondaryIndex("to").addSecondaryIndex("two").build();
HashMap<String, String> options = new HashMap<>();
options.put(CassandraAdmin.COMPACTION_STRATEGY, CompactionStrategy.LCS.toString());
// Act
cassandraAdmin.createTableInternal(namespace, table, tableMetadata, options);
// Assert
TableOptions<Options> createTableStatement = SchemaBuilder.createTable(quote(namespace), quote(table)).addPartitionKey("\"from\"", com.datastax.driver.core.DataType.cint()).addPartitionKey("c7", com.datastax.driver.core.DataType.text()).addClusteringColumn("\"two\"", com.datastax.driver.core.DataType.cdouble()).addClusteringColumn("c6", com.datastax.driver.core.DataType.cboolean()).addColumn("\"to\"", com.datastax.driver.core.DataType.text()).addColumn("\"one\"", com.datastax.driver.core.DataType.blob()).addColumn("\"password\"", com.datastax.driver.core.DataType.bigint()).withOptions().clusteringOrder("\"two\"", Direction.ASC).clusteringOrder("c6", Direction.DESC).compactionOptions(SchemaBuilder.leveledStrategy());
verify(cassandraSession).execute(createTableStatement.getQueryString());
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class CassandraAdminTest method createTableInternal_WithLcsCompaction_ShouldExecuteCreateTableStatementWithLcsCompaction.
@Test
public void createTableInternal_WithLcsCompaction_ShouldExecuteCreateTableStatementWithLcsCompaction() throws ExecutionException {
// Arrange
String namespace = "sample_ns";
String table = "sample_table";
TableMetadata tableMetadata = TableMetadata.newBuilder().addPartitionKey("c1").addPartitionKey("c7").addClusteringKey("c4").addClusteringKey("c6", Order.DESC).addColumn("c1", DataType.INT).addColumn("c2", DataType.TEXT).addColumn("c3", DataType.BLOB).addColumn("c4", DataType.DOUBLE).addColumn("c5", DataType.BIGINT).addColumn("c6", DataType.BOOLEAN).addColumn("c7", DataType.TEXT).addSecondaryIndex("c2").addSecondaryIndex("c4").build();
HashMap<String, String> options = new HashMap<>();
options.put(CassandraAdmin.COMPACTION_STRATEGY, CompactionStrategy.LCS.toString());
// Act
cassandraAdmin.createTableInternal(namespace, table, tableMetadata, options);
// Assert
TableOptions<Options> createTableStatement = SchemaBuilder.createTable(namespace, table).addPartitionKey("c1", com.datastax.driver.core.DataType.cint()).addPartitionKey("c7", com.datastax.driver.core.DataType.text()).addClusteringColumn("c4", com.datastax.driver.core.DataType.cdouble()).addClusteringColumn("c6", com.datastax.driver.core.DataType.cboolean()).addColumn("c2", com.datastax.driver.core.DataType.text()).addColumn("c3", com.datastax.driver.core.DataType.blob()).addColumn("c5", com.datastax.driver.core.DataType.bigint()).withOptions().clusteringOrder("c4", Direction.ASC).clusteringOrder("c6", Direction.DESC).compactionOptions(SchemaBuilder.leveledStrategy());
verify(cassandraSession).execute(createTableStatement.getQueryString());
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class CassandraAdminTest method createTableInternal_WithoutSettingCompactionStrategy_ShouldExecuteCreateTableStatementWithStcs.
@Test
public void createTableInternal_WithoutSettingCompactionStrategy_ShouldExecuteCreateTableStatementWithStcs() throws ExecutionException {
// Arrange
String namespace = "sample_ns";
String table = "sample_table";
TableMetadata tableMetadata = TableMetadata.newBuilder().addPartitionKey("c1").addClusteringKey("c4").addColumn("c1", DataType.INT).addColumn("c2", DataType.TEXT).addColumn("c3", DataType.BLOB).addColumn("c4", DataType.INT).addColumn("c5", DataType.BOOLEAN).addSecondaryIndex("c2").addSecondaryIndex("c4").build();
// Act
cassandraAdmin.createTableInternal(namespace, table, tableMetadata, new HashMap<>());
// Assert
TableOptions<Options> createTableStatement = SchemaBuilder.createTable(namespace, table).addPartitionKey("c1", com.datastax.driver.core.DataType.cint()).addClusteringColumn("c4", com.datastax.driver.core.DataType.cint()).addColumn("c2", com.datastax.driver.core.DataType.text()).addColumn("c3", com.datastax.driver.core.DataType.blob()).addColumn("c5", com.datastax.driver.core.DataType.cboolean()).withOptions().clusteringOrder("c4", Direction.ASC).compactionOptions(SchemaBuilder.sizedTieredStategy());
verify(cassandraSession).execute(createTableStatement.getQueryString());
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class DynamoAdmin method dropIndex.
@Override
public void dropIndex(String namespace, String table, String columnName) throws ExecutionException {
try {
client.updateTable(UpdateTableRequest.builder().tableName(getFullTableName(namespace, table)).globalSecondaryIndexUpdates(GlobalSecondaryIndexUpdate.builder().delete(DeleteGlobalSecondaryIndexAction.builder().indexName(getGlobalIndexName(namespace, table, columnName)).build()).build()).build());
} catch (Exception e) {
throw new ExecutionException("dropping the secondary index failed", e);
}
waitForIndexDeletion(namespace, table, columnName);
// disable auto scaling
List<DeleteScalingPolicyRequest> deleteScalingPolicyRequestList = new ArrayList<>();
List<DeregisterScalableTargetRequest> deregisterScalableTargetRequestList = new ArrayList<>();
for (String scalingType : SECONDARY_INDEX_SCALING_TYPE_SET) {
deleteScalingPolicyRequestList.add(buildDeleteScalingPolicyRequest(getGlobalIndexResourceID(namespace, table, columnName), scalingType));
deregisterScalableTargetRequestList.add(buildDeregisterScalableTargetRequest(getGlobalIndexResourceID(namespace, table, columnName), scalingType));
}
deleteScalingPolicy(deleteScalingPolicyRequestList);
deregisterScalableTarget(deregisterScalableTargetRequestList);
// update metadata
TableMetadata tableMetadata = getTableMetadata(namespace, table);
putTableMetadata(namespace, table, TableMetadata.newBuilder(tableMetadata).removeSecondaryIndex(columnName).build());
}
Aggregations