Search in sources :

Example 91 with TableMetadata

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

Example 92 with TableMetadata

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

Example 93 with TableMetadata

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

Example 94 with TableMetadata

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;
    }
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Selection(com.scalar.db.api.Selection) Get(com.scalar.db.api.Get) CosmosException(com.azure.cosmos.CosmosException) Nonnull(javax.annotation.Nonnull)

Example 95 with TableMetadata

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();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.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