Search in sources :

Example 6 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class GrpcAdminTest method createTable_IsCalledWithProperArguments_StubShouldBeCalledProperly.

@Test
public void createTable_IsCalledWithProperArguments_StubShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    String namespace = "namespace";
    String table = "table";
    TableMetadata metadata = TableMetadata.newBuilder().addColumn("col1", DataType.INT).addColumn("col2", DataType.INT).addPartitionKey("col1").build();
    boolean ifNotExists = false;
    Map<String, String> options = Collections.emptyMap();
    // Act
    admin.createTable(namespace, table, metadata, ifNotExists, options);
    // Assert
    verify(stub).createTable(any());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.Test)

Example 7 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DistributedTransactionServiceWithJdbcTransactionIntegrationTest method createTable.

private static void createTable() throws ExecutionException {
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    admin.createNamespace(NAMESPACE, true);
    admin.createTable(NAMESPACE, TABLE, tableMetadata, true);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata)

Example 8 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method createTables.

static void createTables(DistributedStorageAdmin admin, ConsensusCommitAdmin consensusCommitAdmin) throws ExecutionException {
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    admin.createNamespace(NAMESPACE, true);
    consensusCommitAdmin.createTransactionalTable(NAMESPACE, TABLE_1, tableMetadata, true);
    consensusCommitAdmin.createTransactionalTable(NAMESPACE, TABLE_2, tableMetadata, true);
    consensusCommitAdmin.createCoordinatorTable();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata)

Example 9 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class GrpcTransactionAdminTest method createTable_CalledWithProperArguments_StubShouldBeCalledProperly.

@Test
public void createTable_CalledWithProperArguments_StubShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    String namespace = "namespace";
    String table = "table";
    TableMetadata metadata = TableMetadata.newBuilder().addColumn("col1", DataType.INT).addColumn("col2", DataType.INT).addPartitionKey("col1").build();
    Map<String, String> options = Collections.emptyMap();
    // Act
    admin.createTable(namespace, table, metadata, true, options);
    // Assert
    verify(stub).createTable(CreateTableRequest.newBuilder().setNamespace(namespace).setTable(table).setTableMetadata(ProtoUtils.toTableMetadata(metadata)).setIfNotExists(true).putAllOptions(options).build());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 10 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class DistributedStorageService method mutate.

@Override
public void mutate(MutateRequest request, StreamObserver<Empty> responseObserver) {
    execute(() -> {
        List<Mutation> mutations;
        if (request.getMutationCount() > 0) {
            TableMetadata metadata = tableMetadataManager.getTableMetadata(request.getMutationList().get(0).getNamespace(), request.getMutationList().get(0).getTable());
            if (metadata == null) {
                throw new IllegalArgumentException("the specified table is not found");
            }
            mutations = new ArrayList<>(request.getMutationCount());
            for (com.scalar.db.rpc.Mutation mutation : request.getMutationList()) {
                mutations.add(ProtoUtils.toMutation(mutation, metadata));
            }
        } else {
            mutations = Collections.emptyList();
        }
        storage.mutate(mutations);
        responseObserver.onNext(Empty.getDefaultInstance());
        responseObserver.onCompleted();
    }, responseObserver, "mutate");
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DistributedStorageGrpc(com.scalar.db.rpc.DistributedStorageGrpc) Mutation(com.scalar.db.api.Mutation)

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