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");
}
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);
}
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();
}
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();
}
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();
}
Aggregations