use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class OperationChecker method check.
public void check(Scan scan) throws ExecutionException {
TableMetadata metadata = getMetadata(scan);
checkProjections(scan, metadata);
if (ScalarDbUtils.isSecondaryIndexSpecified(scan, metadata)) {
if (!new ColumnChecker(metadata, true, false, false, false).check(scan.getPartitionKey().getColumns().get(0))) {
throw new IllegalArgumentException("The partition key is not properly specified. Operation: " + scan);
}
if (scan.getStartClusteringKey().isPresent() || scan.getEndClusteringKey().isPresent()) {
throw new IllegalArgumentException("Clustering keys cannot be specified when using an index. Operation: " + scan);
}
if (!scan.getOrderings().isEmpty()) {
throw new IllegalArgumentException("Orderings cannot be specified when using an index. Operation: " + scan);
}
return;
}
checkPartitionKey(scan, metadata);
checkClusteringKeys(scan, metadata);
if (scan.getLimit() < 0) {
throw new IllegalArgumentException("The limit cannot be negative. Operation: " + scan);
}
checkOrderings(scan, metadata);
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class OperationChecker method check.
public void check(Delete delete) throws ExecutionException {
TableMetadata metadata = getMetadata(delete);
checkPrimaryKey(delete, metadata);
checkCondition(delete, metadata);
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class PutStatementHandler method execute.
@Override
protected List<Record> execute(Operation operation) throws CosmosException, ExecutionException {
Mutation mutation = (Mutation) operation;
TableMetadata tableMetadata = metadataManager.getTableMetadata(mutation);
executeStoredProcedure(mutation, tableMetadata);
return Collections.emptyList();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class SelectStatementHandler method execute.
@Override
@Nonnull
protected List<Record> execute(Operation operation) throws CosmosException, ExecutionException {
assert operation instanceof Selection;
Selection selection = (Selection) operation;
TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
try {
if (selection instanceof Get) {
return executeRead((Get) selection, tableMetadata);
} else {
return executeQuery((Scan) selection, tableMetadata);
}
} catch (CosmosException e) {
if (e.getStatusCode() == CosmosErrorCode.NOT_FOUND.get()) {
return Collections.emptyList();
}
throw e;
}
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class AdminIntegrationTestBase method getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata.
@Test
public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() throws ExecutionException {
// Arrange
// Act
TableMetadata tableMetadata = admin.getTableMetadata(namespace1, TABLE1);
// Assert
assertThat(tableMetadata).isNotNull();
assertThat(tableMetadata.getPartitionKeyNames().size()).isEqualTo(2);
Iterator<String> iterator = tableMetadata.getPartitionKeyNames().iterator();
assertThat(iterator.next()).isEqualTo(COL_NAME2);
assertThat(iterator.next()).isEqualTo(COL_NAME1);
assertThat(tableMetadata.getClusteringKeyNames().size()).isEqualTo(2);
iterator = tableMetadata.getClusteringKeyNames().iterator();
assertThat(iterator.next()).isEqualTo(COL_NAME4);
assertThat(iterator.next()).isEqualTo(COL_NAME3);
assertThat(tableMetadata.getColumnNames().size()).isEqualTo(11);
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.getColumnNames().contains(COL_NAME6)).isTrue();
assertThat(tableMetadata.getColumnNames().contains(COL_NAME7)).isTrue();
assertThat(tableMetadata.getColumnNames().contains(COL_NAME8)).isTrue();
assertThat(tableMetadata.getColumnNames().contains(COL_NAME9)).isTrue();
assertThat(tableMetadata.getColumnNames().contains(COL_NAME10)).isTrue();
assertThat(tableMetadata.getColumnNames().contains(COL_NAME11)).isTrue();
assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT);
assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT);
assertThat(tableMetadata.getColumnDataType(COL_NAME3)).isEqualTo(DataType.TEXT);
assertThat(tableMetadata.getColumnDataType(COL_NAME4)).isEqualTo(DataType.INT);
assertThat(tableMetadata.getColumnDataType(COL_NAME5)).isEqualTo(DataType.INT);
assertThat(tableMetadata.getColumnDataType(COL_NAME6)).isEqualTo(DataType.TEXT);
assertThat(tableMetadata.getColumnDataType(COL_NAME7)).isEqualTo(DataType.BIGINT);
assertThat(tableMetadata.getColumnDataType(COL_NAME8)).isEqualTo(DataType.FLOAT);
assertThat(tableMetadata.getColumnDataType(COL_NAME9)).isEqualTo(DataType.DOUBLE);
assertThat(tableMetadata.getColumnDataType(COL_NAME10)).isEqualTo(DataType.BOOLEAN);
assertThat(tableMetadata.getColumnDataType(COL_NAME11)).isEqualTo(DataType.BLOB);
assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME3)).isEqualTo(Scan.Ordering.Order.DESC);
assertThat(tableMetadata.getClusteringOrder(COL_NAME4)).isEqualTo(Scan.Ordering.Order.ASC);
assertThat(tableMetadata.getClusteringOrder(COL_NAME5)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME6)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME7)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME8)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME9)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME10)).isNull();
assertThat(tableMetadata.getClusteringOrder(COL_NAME11)).isNull();
assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2);
assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue();
assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME6)).isTrue();
}
Aggregations