Search in sources :

Example 81 with TableMetadata

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

the class DistributedStorageAdminService method getTableMetadata.

@Override
public void getTableMetadata(GetTableMetadataRequest request, StreamObserver<GetTableMetadataResponse> responseObserver) {
    execute(() -> {
        TableMetadata tableMetadata = admin.getTableMetadata(request.getNamespace(), request.getTable());
        GetTableMetadataResponse.Builder builder = GetTableMetadataResponse.newBuilder();
        if (tableMetadata != null) {
            builder.setTableMetadata(ProtoUtils.toTableMetadata(tableMetadata));
        }
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }, responseObserver, "get_table_metadata");
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) GetTableMetadataResponse(com.scalar.db.rpc.GetTableMetadataResponse)

Example 82 with TableMetadata

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

the class ConsensusCommitSpecificIntegrationTestBase method createTables.

private void createTables() throws ExecutionException {
    Map<String, String> options = getCreateOptions();
    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();
    consensusCommitAdmin.createNamespace(namespace1, true, options);
    consensusCommitAdmin.createTable(namespace1, TABLE_1, tableMetadata, true, options);
    consensusCommitAdmin.createNamespace(namespace2, true, options);
    consensusCommitAdmin.createTable(namespace2, TABLE_2, tableMetadata, true, options);
    consensusCommitAdmin.createCoordinatorTables(true, options);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata)

Example 83 with TableMetadata

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

the class CassandraAdmin method createTableMetadata.

private TableMetadata createTableMetadata(com.datastax.driver.core.TableMetadata metadata) throws ExecutionException {
    TableMetadata.Builder builder = TableMetadata.newBuilder();
    for (ColumnMetadata column : metadata.getColumns()) {
        builder.addColumn(column.getName(), fromCassandraDataType(column.getType().getName()));
    }
    metadata.getPartitionKey().forEach(c -> builder.addPartitionKey(c.getName()));
    for (int i = 0; i < metadata.getClusteringColumns().size(); i++) {
        String clusteringColumnName = metadata.getClusteringColumns().get(i).getName();
        ClusteringOrder clusteringOrder = metadata.getClusteringOrder().get(i);
        builder.addClusteringKey(clusteringColumnName, convertOrder(clusteringOrder));
    }
    metadata.getIndexes().forEach(i -> builder.addSecondaryIndex(i.getTarget()));
    return builder.build();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) ClusteringOrder(com.datastax.driver.core.ClusteringOrder)

Example 84 with TableMetadata

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

the class MultiStorageAdminIntegrationTest method getTableMetadata_ForTable3InNamespace1_ShouldReturnMetadataFromDefaultAdmin.

@Test
public void getTableMetadata_ForTable3InNamespace1_ShouldReturnMetadataFromDefaultAdmin() throws ExecutionException {
    // Arrange
    String namespace = NAMESPACE1;
    String table = TABLE3;
    // Act
    TableMetadata tableMetadata = multiStorageAdmin.getTableMetadata(namespace, table);
    // Assert
    assertThat(tableMetadata).isNotNull();
    assertThat(tableMetadata.getPartitionKeyNames().size()).isEqualTo(1);
    assertThat(tableMetadata.getPartitionKeyNames().iterator().next()).isEqualTo(COL_NAME1);
    assertThat(tableMetadata.getClusteringKeyNames().size()).isEqualTo(1);
    assertThat(tableMetadata.getClusteringKeyNames().iterator().next()).isEqualTo(COL_NAME4);
    assertThat(tableMetadata.getColumnNames().size()).isEqualTo(5);
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME4)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME5)).isTrue();
    assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME3)).isEqualTo(DataType.INT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME4)).isEqualTo(DataType.INT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME5)).isEqualTo(DataType.BOOLEAN);
    assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull();
    assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull();
    assertThat(tableMetadata.getClusteringOrder(COL_NAME3)).isNull();
    assertThat(tableMetadata.getClusteringOrder(COL_NAME4)).isEqualTo(Scan.Ordering.Order.ASC);
    assertThat(tableMetadata.getClusteringOrder(COL_NAME5)).isNull();
    assertThat(tableMetadata.getSecondaryIndexNames()).isEmpty();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 85 with TableMetadata

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

the class MultiStorageAdminIntegrationTest method getTableMetadata_ForTable1InNamespace1_ShouldReturnMetadataFromStorage1.

@Test
public void getTableMetadata_ForTable1InNamespace1_ShouldReturnMetadataFromStorage1() throws ExecutionException {
    // Arrange
    String namespace = NAMESPACE1;
    String table = TABLE1;
    // Act
    TableMetadata tableMetadata = multiStorageAdmin.getTableMetadata(namespace, table);
    // Assert
    assertThat(tableMetadata).isNotNull();
    assertThat(tableMetadata.getPartitionKeyNames().size()).isEqualTo(1);
    assertThat(tableMetadata.getPartitionKeyNames().iterator().next()).isEqualTo(COL_NAME1);
    assertThat(tableMetadata.getClusteringKeyNames().size()).isEqualTo(1);
    assertThat(tableMetadata.getClusteringKeyNames().iterator().next()).isEqualTo(COL_NAME4);
    assertThat(tableMetadata.getColumnNames().size()).isEqualTo(5);
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME4)).isTrue();
    assertThat(tableMetadata.getColumnNames().contains(COL_NAME5)).isTrue();
    assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME3)).isEqualTo(DataType.INT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME4)).isEqualTo(DataType.INT);
    assertThat(tableMetadata.getColumnDataType(COL_NAME5)).isEqualTo(DataType.BOOLEAN);
    assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull();
    assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull();
    assertThat(tableMetadata.getClusteringOrder(COL_NAME3)).isNull();
    assertThat(tableMetadata.getClusteringOrder(COL_NAME4)).isEqualTo(Scan.Ordering.Order.ASC);
    assertThat(tableMetadata.getClusteringOrder(COL_NAME5)).isNull();
    assertThat(tableMetadata.getSecondaryIndexNames()).isEmpty();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

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