Search in sources :

Example 51 with TableMetadata

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();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse.GetResponse)

Example 52 with TableMetadata

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());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) KeyspaceOptions(com.datastax.driver.core.schemabuilder.KeyspaceOptions) Options(com.datastax.driver.core.schemabuilder.Create.Options) TableOptions(com.datastax.driver.core.schemabuilder.TableOptions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 53 with TableMetadata

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());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) KeyspaceOptions(com.datastax.driver.core.schemabuilder.KeyspaceOptions) Options(com.datastax.driver.core.schemabuilder.Create.Options) TableOptions(com.datastax.driver.core.schemabuilder.TableOptions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 54 with TableMetadata

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());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) KeyspaceOptions(com.datastax.driver.core.schemabuilder.KeyspaceOptions) Options(com.datastax.driver.core.schemabuilder.Create.Options) TableOptions(com.datastax.driver.core.schemabuilder.TableOptions) Test(org.junit.jupiter.api.Test)

Example 55 with TableMetadata

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());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DeregisterScalableTargetRequest(software.amazon.awssdk.services.applicationautoscaling.model.DeregisterScalableTargetRequest) ArrayList(java.util.ArrayList) DeleteScalingPolicyRequest(software.amazon.awssdk.services.applicationautoscaling.model.DeleteScalingPolicyRequest) ExecutionException(com.scalar.db.exception.storage.ExecutionException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) ObjectNotFoundException(software.amazon.awssdk.services.applicationautoscaling.model.ObjectNotFoundException) ResourceNotFoundException(software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException)

Aggregations

TableMetadata (com.scalar.db.api.TableMetadata)101 Test (org.junit.jupiter.api.Test)39 Get (com.scalar.db.api.Get)11 PreparedStatement (java.sql.PreparedStatement)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Key (com.scalar.db.io.Key)6 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)6 Mutation (com.scalar.db.api.Mutation)5 Result (com.scalar.db.api.Result)5 GetTableMetadataResponse (com.scalar.db.rpc.GetTableMetadataResponse)5 ResultSet (java.sql.ResultSet)5 Nonnull (javax.annotation.Nonnull)5 HashMap (java.util.HashMap)4 Options (com.datastax.driver.core.schemabuilder.Create.Options)3 KeyspaceOptions (com.datastax.driver.core.schemabuilder.KeyspaceOptions)3 TableOptions (com.datastax.driver.core.schemabuilder.TableOptions)3 ScanAll (com.scalar.db.api.ScanAll)3 NoMutationException (com.scalar.db.exception.storage.NoMutationException)3