From 4fe9471832155dd8a3c75a37d6b36bef85e0f152 Mon Sep 17 00:00:00 2001 From: Hiroyuki Yamada Date: Wed, 13 Nov 2024 13:32:52 +0900 Subject: [PATCH] Backport to branch(3) : Refactor operations and their builders (#2332) Co-authored-by: Toshihiro Suzuki --- .../main/java/com/scalar/db/api/Delete.java | 13 +- .../java/com/scalar/db/api/DeleteBuilder.java | 12 +- core/src/main/java/com/scalar/db/api/Get.java | 22 +- .../java/com/scalar/db/api/GetBuilder.java | 75 +- .../java/com/scalar/db/api/GetWithIndex.java | 13 + .../main/java/com/scalar/db/api/Insert.java | 10 +- .../java/com/scalar/db/api/InsertBuilder.java | 4 +- .../main/java/com/scalar/db/api/Mutation.java | 23 +- .../java/com/scalar/db/api/Operation.java | 92 +- .../com/scalar/db/api/OperationBuilder.java | 2 +- core/src/main/java/com/scalar/db/api/Put.java | 18 +- .../java/com/scalar/db/api/PutBuilder.java | 23 +- .../src/main/java/com/scalar/db/api/Scan.java | 55 +- .../main/java/com/scalar/db/api/ScanAll.java | 31 +- .../java/com/scalar/db/api/ScanBuilder.java | 128 +- .../java/com/scalar/db/api/ScanWithIndex.java | 27 + .../java/com/scalar/db/api/Selection.java | 28 +- .../com/scalar/db/api/SelectionBuilder.java | 25 +- .../main/java/com/scalar/db/api/Update.java | 10 +- .../java/com/scalar/db/api/UpdateBuilder.java | 9 +- .../main/java/com/scalar/db/api/Upsert.java | 10 +- .../java/com/scalar/db/api/UpsertBuilder.java | 4 +- .../com/scalar/db/util/ScalarDbUtils.java | 12 +- .../com/scalar/db/api/GetBuilderTest.java | 720 +++++----- .../com/scalar/db/api/ScanBuilderTest.java | 1157 +++++++++-------- .../com/scalar/db/util/ScalarDbUtilsTest.java | 54 +- ...DistributedStorageIntegrationTestBase.java | 744 ++++++++--- ...ithReservedKeywordIntegrationTestBase.java | 148 ++- 28 files changed, 2056 insertions(+), 1413 deletions(-) diff --git a/core/src/main/java/com/scalar/db/api/Delete.java b/core/src/main/java/com/scalar/db/api/Delete.java index 119d6f0ae2..93d8eed600 100644 --- a/core/src/main/java/com/scalar/db/api/Delete.java +++ b/core/src/main/java/com/scalar/db/api/Delete.java @@ -8,6 +8,7 @@ import com.scalar.db.io.Key; import java.util.Optional; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; /** @@ -18,6 +19,16 @@ @NotThreadSafe public class Delete extends Mutation { + Delete( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Key clusteringKey, + @Nullable Consistency consistency, + @Nullable MutationCondition condition) { + super(namespace, tableName, partitionKey, clusteringKey, consistency, condition); + } + /** * Constructs a {@code Delete} with the specified partition {@code Key}. * @@ -69,7 +80,7 @@ public static Namespace newBuilder() { /** * Build a {@code Delete} operation from an existing {@code Delete} object using a builder. The - * builder will be parametrized by default with all the existing {@code Delete} attributes + * builder will be parametrized by default with all the existing {@code Delete} parameters. * * @param delete an existing {@code Delete} operation * @return a {@code Delete} operation builder diff --git a/core/src/main/java/com/scalar/db/api/DeleteBuilder.java b/core/src/main/java/com/scalar/db/api/DeleteBuilder.java index 8f5351c4dd..539b2e64f9 100644 --- a/core/src/main/java/com/scalar/db/api/DeleteBuilder.java +++ b/core/src/main/java/com/scalar/db/api/DeleteBuilder.java @@ -92,16 +92,8 @@ public Buildable consistency(com.scalar.db.api.Consistency consistency) { @Override public Delete build() { - Delete delete = new Delete(partitionKey, clusteringKey); - delete.forNamespace(namespaceName).forTable(tableName); - if (condition != null) { - delete.withCondition(condition); - } - if (consistency != null) { - delete.withConsistency(consistency); - } - - return delete; + return new Delete( + namespaceName, tableName, partitionKey, clusteringKey, consistency, condition); } } diff --git a/core/src/main/java/com/scalar/db/api/Get.java b/core/src/main/java/com/scalar/db/api/Get.java index 0b6c3264f8..f6202734fa 100644 --- a/core/src/main/java/com/scalar/db/api/Get.java +++ b/core/src/main/java/com/scalar/db/api/Get.java @@ -3,10 +3,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; import com.scalar.db.api.GetBuilder.BuildableGetOrGetWithIndexFromExisting; import com.scalar.db.api.GetBuilder.Namespace; import com.scalar.db.io.Key; import java.util.Collection; +import java.util.List; +import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; /** @@ -17,6 +20,18 @@ @NotThreadSafe public class Get extends Selection { + Get( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Key clusteringKey, + @Nullable Consistency consistency, + List projections, + ImmutableSet conjunctions) { + super( + namespace, tableName, partitionKey, clusteringKey, consistency, projections, conjunctions); + } + /** * Constructs a {@code Get} with the specified partition {@code Key}. * @@ -68,7 +83,7 @@ public static Namespace newBuilder() { /** * Build a {@code Get} operation from an existing {@code Get} object using a builder. The builder - * will be parametrized by default with all the existing {@code Get} attributes + * will be parametrized by default with all the existing {@code Get} parameters. * * @param get an existing {@code Get} operation * @return a {@code Get} operation builder @@ -133,11 +148,6 @@ public Get withProjections(Collection projections) { return (Get) super.withProjections(projections); } - @Override - Get withConjunctions(Collection conjunctions) { - return (Get) super.withConjunctions(conjunctions); - } - /** * Indicates whether some other object is "equal to" this object. The other object is considered * equal if: diff --git a/core/src/main/java/com/scalar/db/api/GetBuilder.java b/core/src/main/java/com/scalar/db/api/GetBuilder.java index a6ba26c45d..3b92cfa499 100644 --- a/core/src/main/java/com/scalar/db/api/GetBuilder.java +++ b/core/src/main/java/com/scalar/db/api/GetBuilder.java @@ -2,6 +2,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableSet; import com.scalar.db.api.OperationBuilder.And; import com.scalar.db.api.OperationBuilder.Buildable; import com.scalar.db.api.OperationBuilder.ClearClusteringKey; @@ -135,15 +136,18 @@ public BuildableGet consistency(com.scalar.db.api.Consistency consistency) { @Override public Get build() { - Get get = new Get(partitionKey, clusteringKey); - get.forNamespace(namespaceName).forTable(tableName); - if (!projections.isEmpty()) { - get.withProjections(projections); - } - if (consistency != null) { - get.withConsistency(consistency); - } - return get; + return build(ImmutableSet.of()); + } + + private Get build(ImmutableSet conjunctions) { + return new Get( + namespaceName, + tableName, + partitionKey, + clusteringKey, + consistency, + projections, + conjunctions); } } @@ -341,7 +345,7 @@ private BuildableGetWithWhere(BuildableGetWithOngoingWhere buildable) { @Override public Get build() { - return (Get) addConjunctionsTo(super.build(), where); + return super.build(getConjunctions(where)); } } @@ -420,15 +424,12 @@ public BuildableGetWithIndexOngoingWhereOr whereOr(Set andCondi } public Get build() { - GetWithIndex getWithIndex = new GetWithIndex(indexKey); - getWithIndex.forNamespace(namespaceName).forTable(tableName); - if (!projections.isEmpty()) { - getWithIndex.withProjections(projections); - } - if (consistency != null) { - getWithIndex.withConsistency(consistency); - } - return getWithIndex; + return build(ImmutableSet.of()); + } + + private Get build(ImmutableSet conjunctions) { + return new GetWithIndex( + namespaceName, tableName, indexKey, consistency, projections, conjunctions); } } @@ -583,7 +584,7 @@ public BuildableGetWithIndexWhere consistency(com.scalar.db.api.Consistency cons } public Get build() { - return (Get) addConjunctionsTo(buildableGetWithIndex.build(), where); + return buildableGetWithIndex.build(getConjunctions(where)); } } @@ -771,28 +772,24 @@ private void checkConditionsEmpty() { @Override public Get build() { - Get get; + return build( + conjunctions.stream().map(Conjunction::of).collect(ImmutableSet.toImmutableSet())); + } + private Get build(ImmutableSet conjunctions) { if (isGetWithIndex) { - get = new GetWithIndex(indexKey); + return new GetWithIndex( + namespaceName, tableName, indexKey, consistency, projections, conjunctions); } else { - get = new Get(partitionKey, clusteringKey); - } - - if (!conjunctions.isEmpty()) { - get.withConjunctions( - conjunctions.stream().map(Conjunction::of).collect(Collectors.toSet())); + return new Get( + namespaceName, + tableName, + partitionKey, + clusteringKey, + consistency, + projections, + conjunctions); } - - get.forNamespace(namespaceName).forTable(tableName); - if (!projections.isEmpty()) { - get.withProjections(projections); - } - if (consistency != null) { - get.withConsistency(consistency); - } - - return get; } } @@ -893,7 +890,7 @@ public BuildableGetFromExistingWithWhere clearNamespace() { } public Get build() { - return (Get) addConjunctionsTo(BuildableGetFromExisting.build(), where); + return BuildableGetFromExisting.build(getConjunctions(where)); } } diff --git a/core/src/main/java/com/scalar/db/api/GetWithIndex.java b/core/src/main/java/com/scalar/db/api/GetWithIndex.java index 75f3c29d7b..393837dc58 100644 --- a/core/src/main/java/com/scalar/db/api/GetWithIndex.java +++ b/core/src/main/java/com/scalar/db/api/GetWithIndex.java @@ -1,14 +1,27 @@ package com.scalar.db.api; +import com.google.common.collect.ImmutableSet; import com.scalar.db.io.Key; import java.util.Collection; +import java.util.List; import java.util.Objects; +import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; /** A command to retrieve an entry from the underlying storage by using an index. */ @NotThreadSafe public class GetWithIndex extends Get { + GetWithIndex( + @Nullable String namespace, + String tableName, + Key indexKey, + @Nullable Consistency consistency, + List projections, + ImmutableSet conjunctions) { + super(namespace, tableName, indexKey, null, consistency, projections, conjunctions); + } + /** * Constructs an {@code GetWithIndex} with the specified index {@code Key}. * diff --git a/core/src/main/java/com/scalar/db/api/Insert.java b/core/src/main/java/com/scalar/db/api/Insert.java index 07b3807d43..f728a35ba1 100644 --- a/core/src/main/java/com/scalar/db/api/Insert.java +++ b/core/src/main/java/com/scalar/db/api/Insert.java @@ -17,16 +17,16 @@ @NotThreadSafe public class Insert extends Mutation { - private final Map> columns; + private final ImmutableMap> columns; Insert( @Nullable String namespace, String tableName, Key partitionKey, @Nullable Key clusteringKey, - Map> columns) { - super(namespace, tableName, partitionKey, clusteringKey, null); - this.columns = ImmutableMap.copyOf(columns); + ImmutableMap> columns) { + super(namespace, tableName, partitionKey, clusteringKey, null, null); + this.columns = columns; } public Map> getColumns() { @@ -120,7 +120,7 @@ public static InsertBuilder.Namespace newBuilder() { /** * Build a {@code Insert} operation from an existing {@code Insert} object using a builder. The - * builder will be parametrized by default with all the existing {@code Insert} object attributes. + * builder will be parametrized by default with all the existing {@code Insert} parameters. * * @param insert an existing {@code Insert} operation * @return a {@code Insert} operation builder diff --git a/core/src/main/java/com/scalar/db/api/InsertBuilder.java b/core/src/main/java/com/scalar/db/api/InsertBuilder.java index 7e1a14c960..52d177fef4 100644 --- a/core/src/main/java/com/scalar/db/api/InsertBuilder.java +++ b/core/src/main/java/com/scalar/db/api/InsertBuilder.java @@ -2,6 +2,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableMap; import com.scalar.db.api.OperationBuilder.ClearClusteringKey; import com.scalar.db.api.OperationBuilder.ClearNamespace; import com.scalar.db.api.OperationBuilder.ClearValues; @@ -186,7 +187,8 @@ public Buildable value(Column column) { @Override public Insert build() { - return new Insert(namespaceName, tableName, partitionKey, clusteringKey, columns); + return new Insert( + namespaceName, tableName, partitionKey, clusteringKey, ImmutableMap.copyOf(columns)); } } diff --git a/core/src/main/java/com/scalar/db/api/Mutation.java b/core/src/main/java/com/scalar/db/api/Mutation.java index 023458a59d..d6554a16b2 100644 --- a/core/src/main/java/com/scalar/db/api/Mutation.java +++ b/core/src/main/java/com/scalar/db/api/Mutation.java @@ -18,7 +18,18 @@ public abstract class Mutation extends Operation { /** @deprecated As of release 3.13.0. Will be removed in release 5.0.0. */ - @Deprecated private Optional condition; + @Deprecated @Nullable private MutationCondition condition; + + Mutation( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Key clusteringKey, + @Nullable Consistency consistency, + @Nullable MutationCondition condition) { + super(namespace, tableName, partitionKey, clusteringKey, consistency); + this.condition = condition; + } /** * @param partitionKey a partition key @@ -28,7 +39,7 @@ public abstract class Mutation extends Operation { @Deprecated public Mutation(Key partitionKey, Key clusteringKey) { super(partitionKey, clusteringKey); - condition = Optional.empty(); + condition = null; } /** @@ -48,7 +59,7 @@ public Mutation(Mutation mutation) { @Nullable Key clusteringKey, @Nullable MutationCondition condition) { super(namespace, tableName, partitionKey, clusteringKey); - this.condition = Optional.ofNullable(condition); + this.condition = condition; } /** @@ -60,7 +71,7 @@ public Mutation(Mutation mutation) { @Deprecated @Nonnull public Optional getCondition() { - return condition; + return Optional.ofNullable(condition); } /** @@ -72,7 +83,7 @@ public Optional getCondition() { */ @Deprecated public Mutation withCondition(MutationCondition condition) { - this.condition = Optional.ofNullable(condition); + this.condition = condition; return this; } @@ -101,7 +112,7 @@ public boolean equals(Object o) { return false; } Mutation other = (Mutation) o; - return condition.equals(other.condition); + return Objects.equals(condition, other.condition); } @Override diff --git a/core/src/main/java/com/scalar/db/api/Operation.java b/core/src/main/java/com/scalar/db/api/Operation.java index dd06929047..7225bab70c 100644 --- a/core/src/main/java/com/scalar/db/api/Operation.java +++ b/core/src/main/java/com/scalar/db/api/Operation.java @@ -1,7 +1,5 @@ package com.scalar.db.api; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.collect.ComparisonChain; import com.scalar.db.io.Key; import java.util.Comparator; @@ -23,28 +21,66 @@ public abstract class Operation { private static final Logger logger = LoggerFactory.getLogger(Operation.class); private final Key partitionKey; - private final Optional clusteringKey; - private Optional namespace; - private Optional tableName; + @Nullable private final Key clusteringKey; + @Nullable private String namespace; + private String tableName; private Consistency consistency; - public Operation(Key partitionKey, Key clusteringKey) { - this.partitionKey = checkNotNull(partitionKey); - this.clusteringKey = Optional.ofNullable(clusteringKey); - namespace = Optional.empty(); - tableName = Optional.empty(); + Operation( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Key clusteringKey, + @Nullable Consistency consistency) { + this.partitionKey = Objects.requireNonNull(partitionKey); + this.clusteringKey = clusteringKey; + this.namespace = namespace; + this.tableName = Objects.requireNonNull(tableName); + this.consistency = consistency != null ? consistency : Consistency.SEQUENTIAL; + } + + /** + * Constructs an {@code Operation}. + * + * @param partitionKey the partition key + * @param clusteringKey the clustering key + * @deprecated As of release 3.15.0. Will be removed in release 5.0.0 + */ + @Deprecated + public Operation(Key partitionKey, @Nullable Key clusteringKey) { + this.partitionKey = Objects.requireNonNull(partitionKey); + this.clusteringKey = clusteringKey; + namespace = null; + tableName = null; consistency = Consistency.SEQUENTIAL; } + /** + * Constructs an {@code Operation}. + * + * @param namespace the namespace + * @param tableName the table name + * @param partitionKey the partition key + * @param clusteringKey the clustering key + * @deprecated As of release 3.15.0. Will be removed in release 5.0.0 + */ + @Deprecated public Operation( @Nullable String namespace, String tableName, Key partitionKey, @Nullable Key clusteringKey) { - this.partitionKey = checkNotNull(partitionKey); - this.clusteringKey = Optional.ofNullable(clusteringKey); - this.namespace = Optional.ofNullable(namespace); - this.tableName = Optional.of(tableName); + this.partitionKey = Objects.requireNonNull(partitionKey); + this.clusteringKey = clusteringKey; + this.namespace = namespace; + this.tableName = tableName; consistency = Consistency.SEQUENTIAL; } + /** + * Constructs an {@code Operation}. + * + * @param operation the operation + * @deprecated As of release 3.15.0. Will be removed in release 5.0.0 + */ + @Deprecated public Operation(Operation operation) { this.partitionKey = operation.partitionKey; this.clusteringKey = operation.clusteringKey; @@ -60,7 +96,7 @@ public Operation(Operation operation) { */ @Nonnull public Optional forNamespace() { - return namespace; + return Optional.ofNullable(namespace); } /** @@ -70,7 +106,7 @@ public Optional forNamespace() { */ @Nonnull public Optional forTable() { - return tableName; + return Optional.ofNullable(tableName); } /** @@ -80,11 +116,11 @@ public Optional forTable() { */ @Nonnull public Optional forFullTableName() { - if (!namespace.isPresent() || !tableName.isPresent()) { + if (namespace == null || tableName == null) { logger.warn("Namespace or table name isn't specified"); return Optional.empty(); } - return Optional.of(namespace.get() + "." + tableName.get()); + return Optional.of(namespace + "." + tableName); } /** @@ -96,7 +132,7 @@ public Optional forFullTableName() { */ @Deprecated public Operation forNamespace(String namespace) { - this.namespace = Optional.ofNullable(namespace); + this.namespace = namespace; return this; } @@ -109,7 +145,7 @@ public Operation forNamespace(String namespace) { */ @Deprecated public Operation forTable(String tableName) { - this.tableName = Optional.ofNullable(tableName); + this.tableName = tableName; return this; } @@ -130,7 +166,7 @@ public Key getPartitionKey() { */ @Nonnull public Optional getClusteringKey() { - return clusteringKey; + return Optional.ofNullable(clusteringKey); } /** @@ -180,17 +216,11 @@ public boolean equals(Object o) { return ComparisonChain.start() .compare(partitionKey, other.partitionKey) .compare( - clusteringKey.orElse(null), - other.clusteringKey.orElse(null), - Comparator.nullsFirst(Comparator.naturalOrder())) - .compare( - namespace.orElse(null), - other.namespace.orElse(null), - Comparator.nullsFirst(Comparator.naturalOrder())) - .compare( - tableName.orElse(null), - other.tableName.orElse(null), + clusteringKey, + other.clusteringKey, Comparator.nullsFirst(Comparator.naturalOrder())) + .compare(namespace, other.namespace, Comparator.nullsFirst(Comparator.naturalOrder())) + .compare(tableName, other.tableName, Comparator.nullsFirst(Comparator.naturalOrder())) .compare(consistency, other.consistency) .result() == 0; diff --git a/core/src/main/java/com/scalar/db/api/OperationBuilder.java b/core/src/main/java/com/scalar/db/api/OperationBuilder.java index 8a568c99d3..11c29d5e6d 100644 --- a/core/src/main/java/com/scalar/db/api/OperationBuilder.java +++ b/core/src/main/java/com/scalar/db/api/OperationBuilder.java @@ -64,7 +64,7 @@ public interface ClusteringKey { public interface ClearClusteringKey { /** - * Remove the clustering key + * Removes the clustering key * * @return the operation builder */ diff --git a/core/src/main/java/com/scalar/db/api/Put.java b/core/src/main/java/com/scalar/db/api/Put.java index be6ddaa686..9356f08987 100644 --- a/core/src/main/java/com/scalar/db/api/Put.java +++ b/core/src/main/java/com/scalar/db/api/Put.java @@ -46,6 +46,22 @@ public class Put extends Mutation { private boolean insertModeEnabled; + Put( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Key clusteringKey, + @Nullable Consistency consistency, + Map> columns, + @Nullable MutationCondition condition, + boolean implicitPreReadEnabled, + boolean insertModeEnabled) { + super(namespace, tableName, partitionKey, clusteringKey, consistency, condition); + this.columns = columns; + this.implicitPreReadEnabled = implicitPreReadEnabled; + this.insertModeEnabled = insertModeEnabled; + } + /** * Constructs a {@code Put} with the specified partition {@link Key}. * @@ -102,7 +118,7 @@ public static Namespace newBuilder() { /** * Build a {@code Put} operation from an existing {@code Put} object using a builder. The builder - * will be parametrized by default with all the existing {@code Put} object attributes. + * will be parametrized by default with all the existing {@code Put} parameters. * * @param put an existing {@code Put} operation * @return a {@code Put} operation builder diff --git a/core/src/main/java/com/scalar/db/api/PutBuilder.java b/core/src/main/java/com/scalar/db/api/PutBuilder.java index fd67d82035..7f42ab3ab6 100644 --- a/core/src/main/java/com/scalar/db/api/PutBuilder.java +++ b/core/src/main/java/com/scalar/db/api/PutBuilder.java @@ -243,19 +243,16 @@ public Buildable insertModeEnabled(boolean insertModeEnabled) { @Override public Put build() { - Put put = new Put(partitionKey, clusteringKey); - put.forNamespace(namespaceName).forTable(tableName); - columns.values().forEach(put::withValue); - if (consistency != null) { - put.withConsistency(consistency); - } - if (condition != null) { - put.withCondition(condition); - } - put.setImplicitPreReadEnabled(implicitPreReadEnabled); - put.setInsertModeEnabled(insertModeEnabled); - - return put; + return new Put( + namespaceName, + tableName, + partitionKey, + clusteringKey, + consistency, + columns, + condition, + implicitPreReadEnabled, + insertModeEnabled); } @Override diff --git a/core/src/main/java/com/scalar/db/api/Scan.java b/core/src/main/java/com/scalar/db/api/Scan.java index 2704b37ac1..9e198d5a17 100644 --- a/core/src/main/java/com/scalar/db/api/Scan.java +++ b/core/src/main/java/com/scalar/db/api/Scan.java @@ -4,6 +4,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.scalar.db.api.ScanBuilder.BuildableScanOrScanAllFromExisting; import com.scalar.db.api.ScanBuilder.Namespace; import com.scalar.db.io.Key; @@ -13,6 +14,7 @@ import java.util.Objects; import java.util.Optional; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.NotThreadSafe; @@ -29,12 +31,34 @@ public class Scan extends Selection { private final List orderings; - private Optional startClusteringKey; + @Nullable private Key startClusteringKey; private boolean startInclusive; - private Optional endClusteringKey; + @Nullable private Key endClusteringKey; private boolean endInclusive; private int limit; + Scan( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Consistency consistency, + List projections, + ImmutableSet conjunctions, + @Nullable Key startClusteringKey, + boolean startInclusive, + @Nullable Key endClusteringKey, + boolean endInclusive, + List orderings, + int limit) { + super(namespace, tableName, partitionKey, null, consistency, projections, conjunctions); + this.startClusteringKey = startClusteringKey; + this.startInclusive = startInclusive; + this.endClusteringKey = endClusteringKey; + this.endInclusive = endInclusive; + this.orderings = orderings; + this.limit = limit; + } + /** * Constructs a {@code Scan} with the specified partition {@link Key}. * @@ -46,8 +70,8 @@ public class Scan extends Selection { @SuppressWarnings("InlineMeSuggester") public Scan(Key partitionKey) { super(partitionKey, null); - startClusteringKey = Optional.empty(); - endClusteringKey = Optional.empty(); + startClusteringKey = null; + endClusteringKey = null; orderings = new ArrayList<>(); limit = 0; } @@ -57,7 +81,7 @@ public Scan(Key partitionKey) { * * @param scan a Scan * @deprecated As of release 3.6.0. Will be removed in release 5.0.0. Use {@link - * Scan#newBuilder(Scan)} ()} instead + * Scan#newBuilder(Scan)} instead */ @Deprecated @SuppressWarnings("InlineMeSuggester") @@ -82,7 +106,7 @@ public static Namespace newBuilder() { /** * Build a {@code Scan} operation from an existing {@code Scan} object using a builder. The - * builder will be parametrized by default with all the existing {@code Scan} attributes + * builder will be parametrized by default with all the existing {@code Scan} parameters. * * @param scan an existing {@code Scan} operation * @return a {@code Scan} operation builder @@ -116,7 +140,7 @@ public Scan withStart(Key clusteringKey) { */ @Deprecated public Scan withStart(Key clusteringKey, boolean inclusive) { - startClusteringKey = Optional.ofNullable(clusteringKey); + startClusteringKey = clusteringKey; startInclusive = inclusive; return this; } @@ -128,7 +152,7 @@ public Scan withStart(Key clusteringKey, boolean inclusive) { */ @Nonnull public Optional getStartClusteringKey() { - return startClusteringKey; + return Optional.ofNullable(startClusteringKey); } /** @@ -164,7 +188,7 @@ public Scan withEnd(Key clusteringKey) { */ @Deprecated public Scan withEnd(Key clusteringKey, boolean inclusive) { - endClusteringKey = Optional.ofNullable(clusteringKey); + endClusteringKey = clusteringKey; endInclusive = inclusive; return this; } @@ -176,7 +200,7 @@ public Scan withEnd(Key clusteringKey, boolean inclusive) { */ @Nonnull public Optional getEndClusteringKey() { - return endClusteringKey; + return Optional.ofNullable(endClusteringKey); } /** @@ -291,11 +315,6 @@ public Scan withProjections(Collection projections) { return (Scan) super.withProjections(projections); } - @Override - Scan withConjunctions(Collection conjunctions) { - return (Scan) super.withConjunctions(conjunctions); - } - /** * Indicates whether some other object is "equal to" this object. The other object is considered * equal if: @@ -321,12 +340,12 @@ public boolean equals(Object o) { return false; } Scan other = (Scan) o; - return (startClusteringKey.equals(other.startClusteringKey) + return Objects.equals(startClusteringKey, other.startClusteringKey) && startInclusive == other.startInclusive && endInclusive == other.endInclusive - && endClusteringKey.equals(other.endClusteringKey) + && Objects.equals(endClusteringKey, other.endClusteringKey) && orderings.equals(other.orderings) - && limit == other.limit); + && limit == other.limit; } @Override diff --git a/core/src/main/java/com/scalar/db/api/ScanAll.java b/core/src/main/java/com/scalar/db/api/ScanAll.java index a6ef59e7cc..ec14c5672f 100644 --- a/core/src/main/java/com/scalar/db/api/ScanAll.java +++ b/core/src/main/java/com/scalar/db/api/ScanAll.java @@ -1,8 +1,11 @@ package com.scalar.db.api; +import com.google.common.collect.ImmutableSet; import com.scalar.db.io.Key; import java.util.Collection; +import java.util.List; import java.util.Objects; +import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; /** @@ -15,6 +18,29 @@ public class ScanAll extends Scan { private static final Key DUMMY_PARTITION_KEY = Key.of(); + ScanAll( + String namespace, + String tableName, + @Nullable Consistency consistency, + List projections, + ImmutableSet conjunctions, + List orderings, + int limit) { + super( + namespace, + tableName, + DUMMY_PARTITION_KEY, + consistency, + projections, + conjunctions, + null, + false, + null, + false, + orderings, + limit); + } + /** * @deprecated As of release 3.6.0. Will be removed in release 5.0.0. Use {@link * Scan#newBuilder()} instead @@ -161,11 +187,6 @@ public ScanAll withProjections(Collection projections) { return (ScanAll) super.withProjections(projections); } - @Override - ScanAll withConjunctions(Collection conjunctions) { - return (ScanAll) super.withConjunctions(conjunctions); - } - @Override public boolean equals(Object o) { if (!super.equals(o)) { diff --git a/core/src/main/java/com/scalar/db/api/ScanBuilder.java b/core/src/main/java/com/scalar/db/api/ScanBuilder.java index 98169660bc..a412b21faf 100644 --- a/core/src/main/java/com/scalar/db/api/ScanBuilder.java +++ b/core/src/main/java/com/scalar/db/api/ScanBuilder.java @@ -2,6 +2,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableSet; import com.scalar.db.api.OperationBuilder.All; import com.scalar.db.api.OperationBuilder.And; import com.scalar.db.api.OperationBuilder.Buildable; @@ -194,25 +195,23 @@ public BuildableScan consistency(com.scalar.db.api.Consistency consistency) { @Override public Scan build() { - Scan scan = new Scan(partitionKey); - scan.forNamespace(namespaceName).forTable(tableName).withLimit(limit); - orderings.forEach(scan::withOrdering); - if (startClusteringKey != null) { - scan.withStart(startClusteringKey, startInclusive); - } - if (endClusteringKey != null) { - scan.withEnd(endClusteringKey, endInclusive); - } - - if (!projections.isEmpty()) { - scan.withProjections(projections); - } - - if (consistency != null) { - scan.withConsistency(consistency); - } - - return scan; + return build(ImmutableSet.of()); + } + + private Scan build(ImmutableSet conjunctions) { + return new Scan( + namespaceName, + tableName, + partitionKey, + consistency, + projections, + conjunctions, + startClusteringKey, + startInclusive, + endClusteringKey, + endInclusive, + orderings, + limit); } } @@ -453,7 +452,7 @@ private BuildableScanWithWhere(BuildableScanWithOngoingWhere buildable) { @Override public Scan build() { - return (Scan) addConjunctionsTo(super.build(), where); + return super.build(getConjunctions(where)); } } @@ -540,18 +539,12 @@ public BuildableScanWithIndexOngoingWhereOr whereOr(Set andCond } public Scan build() { - Scan scan = new ScanWithIndex(indexKey); - scan.forNamespace(namespaceName).forTable(tableName).withLimit(limit); - - if (!projections.isEmpty()) { - scan.withProjections(projections); - } - - if (consistency != null) { - scan.withConsistency(consistency); - } + return build(ImmutableSet.of()); + } - return scan; + private Scan build(ImmutableSet conjunctions) { + return new ScanWithIndex( + namespaceName, tableName, indexKey, consistency, projections, conjunctions, limit); } } @@ -714,7 +707,7 @@ public BuildableScanWithIndexWhere consistency(com.scalar.db.api.Consistency con } public Scan build() { - return (Scan) addConjunctionsTo(buildableScanWithIndex.build(), where); + return buildableScanWithIndex.build(getConjunctions(where)); } } @@ -820,19 +813,12 @@ public BuildableScanAllWithOngoingWhereOr whereOr(Set andCondit } public Scan build() { - Scan scan = new ScanAll(); - scan.forNamespace(namespaceName).forTable(tableName).withLimit(limit); - orderings.forEach(scan::withOrdering); - - if (!projections.isEmpty()) { - scan.withProjections(projections); - } - - if (consistency != null) { - scan.withConsistency(consistency); - } + return build(ImmutableSet.of()); + } - return scan; + private Scan build(ImmutableSet conjunctions) { + return new ScanAll( + namespaceName, tableName, consistency, projections, conjunctions, orderings, limit); } } @@ -1012,7 +998,7 @@ public BuildableScanAllWithWhere consistency(com.scalar.db.api.Consistency consi } public Scan build() { - return (Scan) addConjunctionsTo(buildableScanAll.build(), where); + return buildableScanAll.build(getConjunctions(where)); } } @@ -1221,6 +1207,7 @@ public BuildableScanFromExistingWithOngoingWhereOr whereOr( public BuildableScanOrScanAllFromExisting clearStart() { checkNotScanWithIndexOrScanAll(); this.startClusteringKey = null; + this.startInclusive = false; return this; } @@ -1228,6 +1215,7 @@ public BuildableScanOrScanAllFromExisting clearStart() { public BuildableScanOrScanAllFromExisting clearEnd() { checkNotScanWithIndexOrScanAll(); this.endClusteringKey = null; + this.endInclusive = false; return this; } @@ -1287,38 +1275,32 @@ private void checkConditionsEmpty() { @Override public Scan build() { - Scan scan; + return build( + conjunctions.stream().map(Conjunction::of).collect(ImmutableSet.toImmutableSet())); + } + private Scan build(ImmutableSet conjunctions) { if (isScanWithIndex) { - scan = new ScanWithIndex(indexKey); + return new ScanWithIndex( + namespaceName, tableName, indexKey, consistency, projections, conjunctions, limit); } else if (isScanAll) { - scan = new ScanAll(); - orderings.forEach(scan::withOrdering); + return new ScanAll( + namespaceName, tableName, consistency, projections, conjunctions, orderings, limit); } else { - scan = new Scan(partitionKey); - orderings.forEach(scan::withOrdering); - if (startClusteringKey != null) { - scan.withStart(startClusteringKey, startInclusive); - } - if (endClusteringKey != null) { - scan.withEnd(endClusteringKey, endInclusive); - } + return new Scan( + namespaceName, + tableName, + partitionKey, + consistency, + projections, + conjunctions, + startClusteringKey, + startInclusive, + endClusteringKey, + endInclusive, + orderings, + limit); } - - if (!conjunctions.isEmpty()) { - scan.withConjunctions( - conjunctions.stream().map(Conjunction::of).collect(Collectors.toSet())); - } - - scan.forNamespace(namespaceName) - .forTable(tableName) - .withLimit(limit) - .withConsistency(consistency); - if (!projections.isEmpty()) { - scan.withProjections(projections); - } - - return scan; } } @@ -1456,7 +1438,7 @@ public BuildableScanFromExistingWithWhere clearNamespace() { } public Scan build() { - return (Scan) addConjunctionsTo(buildableScanFromExisting.build(), where); + return buildableScanFromExisting.build(getConjunctions(where)); } } diff --git a/core/src/main/java/com/scalar/db/api/ScanWithIndex.java b/core/src/main/java/com/scalar/db/api/ScanWithIndex.java index 62119fdf8e..ffc4459616 100644 --- a/core/src/main/java/com/scalar/db/api/ScanWithIndex.java +++ b/core/src/main/java/com/scalar/db/api/ScanWithIndex.java @@ -1,8 +1,12 @@ package com.scalar.db.api; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.scalar.db.io.Key; import java.util.Collection; +import java.util.List; import java.util.Objects; +import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; /** @@ -12,6 +16,29 @@ @NotThreadSafe public class ScanWithIndex extends Scan { + ScanWithIndex( + @Nullable String namespace, + String tableName, + Key indexKey, + @Nullable Consistency consistency, + List projections, + ImmutableSet conjunctions, + int limit) { + super( + namespace, + tableName, + indexKey, + consistency, + projections, + conjunctions, + null, + false, + null, + false, + ImmutableList.of(), + limit); + } + /** * @param indexKey an index key * @deprecated As of release 3.6.0. Will be removed in release 5.0.0. Use {@link diff --git a/core/src/main/java/com/scalar/db/api/Selection.java b/core/src/main/java/com/scalar/db/api/Selection.java index b68c7c3aca..84c21c7293 100644 --- a/core/src/main/java/com/scalar/db/api/Selection.java +++ b/core/src/main/java/com/scalar/db/api/Selection.java @@ -5,11 +5,11 @@ import com.scalar.db.io.Key; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.NotThreadSafe; @@ -21,7 +21,20 @@ @NotThreadSafe public abstract class Selection extends Operation { private final List projections; - private final Set conjunctions; + private final ImmutableSet conjunctions; + + Selection( + @Nullable String namespace, + String tableName, + Key partitionKey, + @Nullable Key clusteringKey, + @Nullable Consistency consistency, + List projections, + ImmutableSet conjunctions) { + super(namespace, tableName, partitionKey, clusteringKey, consistency); + this.projections = projections; + this.conjunctions = conjunctions; + } /** * @param partitionKey a partition key @@ -32,7 +45,7 @@ public abstract class Selection extends Operation { public Selection(Key partitionKey, Key clusteringKey) { super(partitionKey, clusteringKey); projections = new ArrayList<>(); - conjunctions = new HashSet<>(); + conjunctions = ImmutableSet.of(); } /** @@ -43,7 +56,7 @@ public Selection(Key partitionKey, Key clusteringKey) { public Selection(Selection selection) { super(selection); projections = new ArrayList<>(selection.projections); - conjunctions = new HashSet<>(selection.conjunctions); + conjunctions = selection.conjunctions; } /** @@ -83,11 +96,6 @@ public List getProjections() { return ImmutableList.copyOf(projections); } - Selection withConjunctions(Collection conjunctions) { - this.conjunctions.addAll(conjunctions); - return this; - } - /** * Returns the set of {@code Conjunction}. We regard this set as a disjunction of conjunctions * (i.e., a disjunctive normal form, DNF). @@ -99,7 +107,7 @@ Selection withConjunctions(Collection conjunctions) { */ @Nonnull public Set getConjunctions() { - return ImmutableSet.copyOf(conjunctions); + return conjunctions; } /** diff --git a/core/src/main/java/com/scalar/db/api/SelectionBuilder.java b/core/src/main/java/com/scalar/db/api/SelectionBuilder.java index 4f9440dab2..46eace9e35 100644 --- a/core/src/main/java/com/scalar/db/api/SelectionBuilder.java +++ b/core/src/main/java/com/scalar/db/api/SelectionBuilder.java @@ -70,25 +70,20 @@ void or(Set andConditionSets) { } } - static Selection addConjunctionsTo(Selection selection, Where where) { - + static ImmutableSet getConjunctions(Where where) { if (where.condition != null) { assert where.conjunctions.isEmpty() && where.disjunctions.isEmpty(); - selection.withConjunctions(ImmutableSet.of(Conjunction.of(where.condition))); + return ImmutableSet.of(Conjunction.of(where.condition)); } else if (where.conjunctions.isEmpty()) { - selection.withConjunctions( - Sets.cartesianProduct(new ArrayList<>(where.disjunctions)).stream() - .filter(conditions -> conditions.size() > 0) - .map(Conjunction::of) - .collect(Collectors.toSet())); + return Sets.cartesianProduct(new ArrayList<>(where.disjunctions)).stream() + .filter(conditions -> !conditions.isEmpty()) + .map(Conjunction::of) + .collect(ImmutableSet.toImmutableSet()); } else { - selection.withConjunctions( - where.conjunctions.stream() - .filter(conditions -> conditions.size() > 0) - .map(Conjunction::of) - .collect(Collectors.toSet())); + return where.conjunctions.stream() + .filter(conditions -> !conditions.isEmpty()) + .map(Conjunction::of) + .collect(ImmutableSet.toImmutableSet()); } - - return selection; } } diff --git a/core/src/main/java/com/scalar/db/api/Update.java b/core/src/main/java/com/scalar/db/api/Update.java index e8eb900dd2..5014b2351d 100644 --- a/core/src/main/java/com/scalar/db/api/Update.java +++ b/core/src/main/java/com/scalar/db/api/Update.java @@ -17,17 +17,17 @@ @NotThreadSafe public class Update extends Mutation { - private final Map> columns; + private final ImmutableMap> columns; Update( @Nullable String namespace, String tableName, Key partitionKey, @Nullable Key clusteringKey, - Map> columns, + ImmutableMap> columns, @Nullable MutationCondition condition) { - super(namespace, tableName, partitionKey, clusteringKey, condition); - this.columns = ImmutableMap.copyOf(columns); + super(namespace, tableName, partitionKey, clusteringKey, null, condition); + this.columns = columns; } public Map> getColumns() { @@ -113,7 +113,7 @@ public static UpdateBuilder.Namespace newBuilder() { /** * Build a {@code Update} operation from an existing {@code Update} object using a builder. The - * builder will be parametrized by default with all the existing {@code Update} object attributes. + * builder will be parametrized by default with all the existing {@code Update} parameters. * * @param update an existing {@code Update} operation * @return a {@code Update} operation builder diff --git a/core/src/main/java/com/scalar/db/api/UpdateBuilder.java b/core/src/main/java/com/scalar/db/api/UpdateBuilder.java index 254d931887..561a479cf8 100644 --- a/core/src/main/java/com/scalar/db/api/UpdateBuilder.java +++ b/core/src/main/java/com/scalar/db/api/UpdateBuilder.java @@ -2,6 +2,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableMap; import com.scalar.db.api.OperationBuilder.ClearClusteringKey; import com.scalar.db.api.OperationBuilder.ClearCondition; import com.scalar.db.api.OperationBuilder.ClearNamespace; @@ -196,7 +197,13 @@ public Buildable value(Column column) { @Override public Update build() { - return new Update(namespaceName, tableName, partitionKey, clusteringKey, columns, condition); + return new Update( + namespaceName, + tableName, + partitionKey, + clusteringKey, + ImmutableMap.copyOf(columns), + condition); } } diff --git a/core/src/main/java/com/scalar/db/api/Upsert.java b/core/src/main/java/com/scalar/db/api/Upsert.java index f544e06188..ef3f25e7b0 100644 --- a/core/src/main/java/com/scalar/db/api/Upsert.java +++ b/core/src/main/java/com/scalar/db/api/Upsert.java @@ -17,16 +17,16 @@ @NotThreadSafe public class Upsert extends Mutation { - private final Map> columns; + private final ImmutableMap> columns; Upsert( @Nullable String namespace, String tableName, Key partitionKey, @Nullable Key clusteringKey, - Map> columns) { - super(namespace, tableName, partitionKey, clusteringKey, null); - this.columns = ImmutableMap.copyOf(columns); + ImmutableMap> columns) { + super(namespace, tableName, partitionKey, clusteringKey, null, null); + this.columns = columns; } public Map> getColumns() { @@ -120,7 +120,7 @@ public static UpsertBuilder.Namespace newBuilder() { /** * Build a {@code Upsert} operation from an existing {@code Upsert} object using a builder. The - * builder will be parametrized by default with all the existing {@code Upsert} object attributes. + * builder will be parametrized by default with all the existing {@code Upsert} parameters. * * @param upsert an existing {@code Upsert} operation * @return a {@code Upsert} operation builder diff --git a/core/src/main/java/com/scalar/db/api/UpsertBuilder.java b/core/src/main/java/com/scalar/db/api/UpsertBuilder.java index 5f3de99bea..deace621dd 100644 --- a/core/src/main/java/com/scalar/db/api/UpsertBuilder.java +++ b/core/src/main/java/com/scalar/db/api/UpsertBuilder.java @@ -2,6 +2,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableMap; import com.scalar.db.api.OperationBuilder.ClearClusteringKey; import com.scalar.db.api.OperationBuilder.ClearNamespace; import com.scalar.db.api.OperationBuilder.ClearValues; @@ -186,7 +187,8 @@ public Buildable value(Column column) { @Override public Upsert build() { - return new Upsert(namespaceName, tableName, partitionKey, clusteringKey, columns); + return new Upsert( + namespaceName, tableName, partitionKey, clusteringKey, ImmutableMap.copyOf(columns)); } } diff --git a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java index 35b0ba6864..635452c253 100644 --- a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java +++ b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java @@ -14,7 +14,6 @@ import com.scalar.db.api.Put; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; -import com.scalar.db.api.ScanAll; import com.scalar.db.api.ScanWithIndex; import com.scalar.db.api.Selection; import com.scalar.db.api.Selection.Conjunction; @@ -67,21 +66,14 @@ public static List copyAndSetTargetToIfNot( public static Get copyAndSetTargetToIfNot( Get get, Optional namespace, Optional tableName) { - Get ret = new Get(get); // copy + Get ret = Get.newBuilder(get).build(); // copy setTargetToIfNot(ret, namespace, tableName); return ret; } public static Scan copyAndSetTargetToIfNot( Scan scan, Optional namespace, Optional tableName) { - Scan ret; - if (scan instanceof ScanAll) { - ret = new ScanAll((ScanAll) scan); // copy - } else if (scan instanceof ScanWithIndex) { - ret = new ScanWithIndex((ScanWithIndex) scan); // copy - } else { - ret = new Scan(scan); // copy - } + Scan ret = Scan.newBuilder(scan).build(); // copy setTargetToIfNot(ret, namespace, tableName); return ret; } diff --git a/core/src/test/java/com/scalar/db/api/GetBuilderTest.java b/core/src/test/java/com/scalar/db/api/GetBuilderTest.java index 72a64302f0..8ff61006db 100644 --- a/core/src/test/java/com/scalar/db/api/GetBuilderTest.java +++ b/core/src/test/java/com/scalar/db/api/GetBuilderTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.scalar.db.api.Selection.Conjunction; import com.scalar.db.io.Key; @@ -162,23 +163,24 @@ public void buildGet_WithConjunctiveNormalForm_ShouldBuildGetWithConditionsCorre // Assert Get expected = - new Get(partitionKey1, clusteringKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)))); assertThat(get1).isEqualTo(expected); assertThat(get2).isEqualTo(expected); @@ -209,21 +211,22 @@ public void buildGet_WithConditionAndConditionSet_ShouldBuildGetWithConditionsCo // Assert assertThat(get) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -304,19 +307,20 @@ public void buildGet_WithDisjunctiveNormalForm_ShouldBuildGetWithConditionsCorre // Assert Get expected = - new Get(partitionKey1, clusteringKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))); assertThat(get1).isEqualTo(expected); assertThat(get2).isEqualTo(expected); @@ -342,14 +346,16 @@ public void buildGet_FromExistingAndAddTwoOrConditions_ShouldBuildGetWithUpdated // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10))))); } @Test @@ -375,18 +381,19 @@ public void buildGet_WithConditionOrConditionSet_ShouldBuildGetWithConditionsCor // Assert assertThat(get) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -414,19 +421,20 @@ public void buildGet_WithTwoOrConditionSet_ShouldBuildGetWithConditionsCorrectly // Assert assertThat(get) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))))); } @Test @@ -456,19 +464,20 @@ public void buildGet_WithOrConditionSets_ShouldBuildGetWithConditionsCorrectly() // Assert assertThat(get) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))))); } @Test @@ -498,17 +507,18 @@ public void buildGet_WithAndConditionSets_ShouldBuildGetWithConditionsCorrectly( // Assert assertThat(get) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))))); } @Test @@ -595,19 +605,20 @@ public void buildGet_FromExistingWithoutChange_ShouldCopy() { buildGet_FromExistingAndUpdateAllParametersExceptConjunctions_ShouldBuildGetWithUpdatedParameters() { // Arrange Get existingGet = - new Get(partitionKey1, clusteringKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + Consistency.LINEARIZABLE, + Arrays.asList("c1", "c2"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)))); // Act Get newGet = @@ -626,19 +637,20 @@ public void buildGet_FromExistingWithoutChange_ShouldCopy() { // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey2, clusteringKey2) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withConsistency(Consistency.EVENTUAL) - .withProjections(Arrays.asList("c3", "c4", "c5", "c6", "c7")) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10))))); + new Get( + NAMESPACE_2, + TABLE_2, + partitionKey2, + clusteringKey2, + Consistency.EVENTUAL, + Arrays.asList("c3", "c4", "c5", "c6", "c7"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -656,23 +668,24 @@ public void buildGet_FromExistingWithoutChange_ShouldCopy() { .consistency(Consistency.EVENTUAL) .build(); Get expected = - new Get(partitionKey2, clusteringKey2) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5")) - .withConsistency(Consistency.LINEARIZABLE); + new Get( + NAMESPACE_2, + TABLE_2, + partitionKey2, + clusteringKey2, + Consistency.LINEARIZABLE, + Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)))); // Act Get newGet1 = @@ -807,20 +820,22 @@ public void buildGet_FromExistingWithoutChange_ShouldCopy() { // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -846,17 +861,19 @@ public void buildGet_FromExistingWithoutChange_ShouldCopy() { // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -883,24 +900,26 @@ public void buildGet_FromExistingAndAddTwoAndConditionSet_ShouldBuildGetWithUpda // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))))); } @Test @@ -927,18 +946,20 @@ public void buildGet_FromExistingAndAddTwoOrConditionSet_ShouldBuildGetWithUpdat // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))))); } @Test @@ -967,18 +988,20 @@ public void buildGet_FromExistingWithOrConditionSets_ShouldBuildGetWithUpdatedPa // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))))); } @Test @@ -1007,16 +1030,18 @@ public void buildGet_FromExistingWithAndConditionSets_ShouldBuildGetWithUpdatedP // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))))); } @Test @@ -1038,12 +1063,15 @@ public void buildGet_FromExistingWithAndConditionSets_ShouldBuildGetWithUpdatedP // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); + new Get( + NAMESPACE_2, + TABLE_2, + partitionKey1, + null, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); } @Test @@ -1063,11 +1091,15 @@ public void buildGet_FromExistingAndClearNamespaceAfterWhere_ShouldBuildGetWitho // Assert assertThat(newGet) .isEqualTo( - new Get(partitionKey1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); + new Get( + null, + TABLE_1, + partitionKey1, + null, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); } @Test @@ -1205,23 +1237,23 @@ public void buildGetWithIndex_WithConjunctiveNormalForm_ShouldBuildGetWithCondit // Assert Get expected = - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)))); assertThat(get1).isEqualTo(expected); assertThat(get2).isEqualTo(expected); @@ -1252,21 +1284,21 @@ public void buildGetWithIndex_WithConjunctiveNormalForm_ShouldBuildGetWithCondit // Assert assertThat(get) .isEqualTo( - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -1326,19 +1358,19 @@ public void buildGetWithIndex_WithDisjunctiveNormalForm_ShouldBuildGetWithCondit // Assert Get expected = - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))); assertThat(get1).isEqualTo(expected); assertThat(get2).isEqualTo(expected); @@ -1369,18 +1401,18 @@ public void buildGetWithIndex_WithDisjunctiveNormalForm_ShouldBuildGetWithCondit // Assert assertThat(get) .isEqualTo( - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))))); } @Test @@ -1408,19 +1440,19 @@ public void buildGetWithIndex_WithTwoOrConditionSet_ShouldBuildGetWithConditions // Assert assertThat(get) .isEqualTo( - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))))); } @Test @@ -1450,19 +1482,19 @@ public void buildGetWithIndex_WithOrConditionSets_ShouldBuildGetWithConditionsCo // Assert assertThat(get) .isEqualTo( - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))))); } @Test @@ -1492,17 +1524,17 @@ public void buildGetWithIndex_WithAndConditionSets_ShouldBuildGetWithConditionsC // Assert assertThat(get) .isEqualTo( - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))))); } @Test @@ -1640,23 +1672,23 @@ public void buildGetWithIndex_FromExistingWithoutChange_ShouldCopy() { .consistency(Consistency.EVENTUAL) .build(); Get expected = - new GetWithIndex(indexKey2) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withProjections(Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5")) - .withConsistency(Consistency.LINEARIZABLE); + new GetWithIndex( + NAMESPACE_2, + TABLE_2, + indexKey2, + Consistency.LINEARIZABLE, + Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)))); // Act Get newGet1 = diff --git a/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java b/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java index a7a8e543c1..3d83d2c56a 100644 --- a/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java +++ b/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.scalar.db.api.Selection.Conjunction; import com.scalar.db.io.Key; @@ -115,8 +116,7 @@ public void buildScan_ScanWithAllParameters_ShouldBuildScanCorrectly() { .withOrdering(ordering4) .withOrdering(ordering5) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"))); } @Test @@ -185,8 +185,7 @@ public void buildScan_FromExistingWithoutChange_ShouldCopy() { .withOrdering(ordering1) .withOrdering(ordering2) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")) - .withConsistency(Consistency.EVENTUAL); + .withProjections(Arrays.asList("pk1", "ck1")); // Act Scan newScan = Scan.newBuilder(existingScan).build(); @@ -208,8 +207,7 @@ public void buildScan_FromExistingAndUpdateAllParameters_ShouldBuildScanWithUpda .withOrdering(ordering1) .withOrdering(ordering2) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2")) - .withConsistency(Consistency.EVENTUAL); + .withProjections(Arrays.asList("pk1", "ck1", "ck2")); // Act Scan newScan = @@ -321,21 +319,15 @@ public void buildScanAll_ScanWithAllParameters_ShouldBuildScanCorrectly() { // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConsistency(Consistency.EVENTUAL) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))), + Arrays.asList(ordering1, ordering2, ordering3, ordering4, ordering5), + 10)); } @Test @@ -347,8 +339,7 @@ public void buildScanAll_FromExistingWithoutChange_ShouldCopy() { .forTable(TABLE_1) .withConsistency(Consistency.EVENTUAL) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")) - .withConsistency(Consistency.EVENTUAL); + .withProjections(Arrays.asList("pk1", "ck1")); // Act Scan newScan = Scan.newBuilder(existingScan).build(); @@ -367,8 +358,7 @@ public void buildScanAll_FromExistingWithoutChange_ShouldCopy() { .forTable(TABLE_1) .withConsistency(Consistency.EVENTUAL) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")) - .withConsistency(Consistency.EVENTUAL); + .withProjections(Arrays.asList("pk1", "ck1")); // Act Scan newScan = @@ -463,8 +453,7 @@ public void buildScanWithIndex_ScanWithAllParameters_ShouldBuildScanCorrectly() .forTable(TABLE_1) .withConsistency(Consistency.EVENTUAL) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"))); } @Test @@ -476,8 +465,7 @@ public void buildScanWithIndex_FromExistingWithoutChange_ShouldCopy() { .forTable(TABLE_1) .withConsistency(Consistency.EVENTUAL) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")) - .withConsistency(Consistency.EVENTUAL); + .withProjections(Arrays.asList("pk1", "ck1")); // Act Scan newScan = Scan.newBuilder(existingScan).build(); @@ -496,8 +484,7 @@ public void buildScanWithIndex_FromExistingWithoutChange_ShouldCopy() { .forTable(TABLE_1) .withConsistency(Consistency.EVENTUAL) .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")) - .withConsistency(Consistency.EVENTUAL); + .withProjections(Arrays.asList("pk1", "ck1")); // Act Scan newScan = @@ -676,29 +663,29 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert Scan expected = - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + null, + false, + null, + false, + Arrays.asList(ordering1, ordering2, ordering3, ordering4, ordering5), + 10); assertThat(scan1).isEqualTo(expected); assertThat(scan2).isEqualTo(expected); @@ -732,22 +719,27 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + null, + false, + null, + false, + ImmutableList.of(), + 10)); } @Test @@ -862,25 +854,25 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert Scan expected = - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + null, + false, + null, + false, + Arrays.asList(ordering1, ordering2, ordering3, ordering4, ordering5), + 10); assertThat(scan1).isEqualTo(expected); assertThat(scan2).isEqualTo(expected); @@ -914,19 +906,24 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + null, + false, + null, + false, + ImmutableList.of(), + 10)); } @Test @@ -956,20 +953,25 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))), + null, + false, + null, + false, + ImmutableList.of(), + 10)); } @Test @@ -1001,20 +1003,25 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))), + null, + false, + null, + false, + ImmutableList.of(), + 10)); } @Test @@ -1046,18 +1053,23 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))), + null, + false, + null, + false, + ImmutableList.of(), + 10)); } @Test @@ -1205,24 +1217,24 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert Scan expected = - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + 10); assertThat(scan1).isEqualTo(expected); assertThat(scan2).isEqualTo(expected); @@ -1255,22 +1267,22 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + 10)); } @Test @@ -1352,20 +1364,20 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert Scan expected = - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + 10); assertThat(scan1).isEqualTo(expected); assertThat(scan2).isEqualTo(expected); @@ -1398,19 +1410,19 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith // Assert assertThat(scan) .isEqualTo( - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + 10)); } @Test @@ -1439,20 +1451,20 @@ public void buildScanWithIndex_WithTwoOrConditionSet_ShouldBuildScanWithConditio // Assert assertThat(scan) .isEqualTo( - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))), + 10)); } @Test @@ -1483,20 +1495,20 @@ public void buildScanWithIndex_WithOrConditionSets_ShouldBuildScanWithConditions // Assert assertThat(scan) .isEqualTo( - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))), + 10)); } @Test @@ -1527,18 +1539,18 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition // Assert assertThat(scan) .isEqualTo( - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))), + 10)); } @Test @@ -1630,31 +1642,29 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition .consistency(Consistency.EVENTUAL) .build(); Scan expected = - new Scan(partitionKey2) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withStart(startClusteringKey2, false) - .withEnd(endClusteringKey2) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withLimit(5) - .withProjections(Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5")) - .withConsistency(Consistency.LINEARIZABLE); + new Scan( + NAMESPACE_2, + TABLE_2, + partitionKey2, + Consistency.LINEARIZABLE, + Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + startClusteringKey2, + false, + endClusteringKey2, + true, + Arrays.asList(ordering3, ordering4, ordering5, ordering1, ordering2), + 5); // Act Scan newScan1 = @@ -1842,31 +1852,29 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition .consistency(Consistency.EVENTUAL) .build(); Scan expected = - new Scan(partitionKey2) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withStart(startClusteringKey2) - .withEnd(endClusteringKey2, false) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withLimit(5) - .withProjections(Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5")) - .withConsistency(Consistency.LINEARIZABLE); + new Scan( + NAMESPACE_2, + TABLE_2, + partitionKey2, + Consistency.LINEARIZABLE, + Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + startClusteringKey2, + true, + endClusteringKey2, + false, + Arrays.asList(ordering3, ordering4, ordering5, ordering1, ordering2), + 5); // Act Scan newScan1 = @@ -1942,24 +1950,24 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition .consistency(Consistency.EVENTUAL) .build(); Scan expected = - new ScanWithIndex(indexKey2) - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(5) - .withProjections(Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5")) - .withConsistency(Consistency.LINEARIZABLE); + new ScanWithIndex( + NAMESPACE_2, + TABLE_2, + indexKey2, + Consistency.LINEARIZABLE, + Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + 5); // Act Scan newScan1 = @@ -2182,29 +2190,24 @@ public void buildScanAll_ScanWithConjunctiveNormalForm_ShouldBuildScanWithCondit // Assert ScanAll expected = - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + Arrays.asList(ordering1, ordering2, ordering3, ordering4, ordering5), + 10); assertThat(scan1).isEqualTo(expected); assertThat(scan2).isEqualTo(expected); @@ -2238,22 +2241,22 @@ public void buildScanAll_ScanWithConjunctiveNormalForm_ShouldBuildScanWithCondit // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + ImmutableList.of(), + 10)); } @Test @@ -2282,26 +2285,26 @@ public void buildScanAll_ScanWithTwoAndConditionSet_ShouldBuildScanWithCondition // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))), + ImmutableList.of(), + 10)); } @Test @@ -2415,25 +2418,20 @@ public void buildScanAll_ScanWithDisjunctiveNormalForm_ShouldBuildScanWithCondit // Assert ScanAll expected = - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + Arrays.asList(ordering1, ordering2, ordering3, ordering4, ordering5), + 10); assertThat(scan1).isEqualTo(expected); assertThat(scan2).isEqualTo(expected); @@ -2467,19 +2465,19 @@ public void buildScanAll_ScanWithDisjunctiveNormalForm_ShouldBuildScanWithCondit // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + ImmutableList.of(), + 10)); } @Test @@ -2508,20 +2506,20 @@ public void buildScanAll_ScanWithTwoOrConditionSet_ShouldBuildScanWithConditions // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))), + ImmutableList.of(), + 10)); } @Test @@ -2552,20 +2550,20 @@ public void buildScanAll_ScanWithOrConditionSets_ShouldBuildScanWithConditionsCo // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))), + ImmutableList.of(), + 10)); } @Test @@ -2596,18 +2594,18 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(scan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4")) - .withConsistency(Consistency.EVENTUAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + Arrays.asList("pk1", "ck1", "ck2", "ck3", "ck4"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))), + ImmutableList.of(), + 10)); } @Test @@ -2721,29 +2719,24 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withLimit(5) - .withProjections(Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5")) - .withConsistency(Consistency.LINEARIZABLE)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.LINEARIZABLE, + Arrays.asList("ck1", "ck2", "ck3", "ck4", "ck5"), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + Arrays.asList(ordering3, ordering4, ordering5, ordering1, ordering2), + 5)); } @Test @@ -2768,20 +2761,22 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -2808,24 +2803,26 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck4").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck4").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -2846,14 +2843,16 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck2").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -2878,17 +2877,19 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("col1").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -2915,18 +2916,20 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck3").isGreaterThanInt(10), - ConditionBuilder.column("ck4").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("col1").isGreaterThanInt(10), - ConditionBuilder.column("col2").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck3").isGreaterThanInt(10), + ConditionBuilder.column("ck4").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("col1").isGreaterThanInt(10), + ConditionBuilder.column("col2").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -2955,18 +2958,15 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10)))) - .withOrdering(ordering3) - .withOrdering(ordering4) - .withOrdering(ordering5) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))), + Arrays.asList(ordering3, ordering4, ordering5, ordering1, ordering2), + 0)); } @Test @@ -2994,18 +2994,20 @@ public void buildScanAll_FromExistingWithOrConditionSets_ShouldBuildScanWithUpda // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)), - Conjunction.of( - ConditionBuilder.column("ck2").isGreaterThanInt(10), - ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10)), + Conjunction.of( + ConditionBuilder.column("ck2").isGreaterThanInt(10), + ConditionBuilder.column("ck3").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -3033,16 +3035,18 @@ public void buildScanAll_FromExistingWithAndConditionSets_ShouldBuildScanWithUpd // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of( - ConditionBuilder.column("ck1").isGreaterThanInt(10), - ConditionBuilder.column("ck2").isGreaterThanInt(10)), - Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10)))) - .withConsistency(Consistency.SEQUENTIAL)); + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of( + ConditionBuilder.column("ck1").isGreaterThanInt(10), + ConditionBuilder.column("ck2").isGreaterThanInt(10)), + Conjunction.of(ConditionBuilder.column("ck3").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -3080,12 +3084,15 @@ public void buildScanAll_FromExistingWithAndConditionSets_ShouldBuildScanWithUpd // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forNamespace(NAMESPACE_2) - .forTable(TABLE_2) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); + new ScanAll( + NAMESPACE_2, + TABLE_2, + null, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test @@ -3105,11 +3112,15 @@ public void buildScanAll_FromExistingWithAndConditionSets_ShouldBuildScanWithUpd // Assert assertThat(newScan) .isEqualTo( - new ScanAll() - .forTable(TABLE_1) - .withConjunctions( - ImmutableSet.of( - Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))))); + new ScanAll( + null, + TABLE_1, + Consistency.SEQUENTIAL, + ImmutableList.of(), + ImmutableSet.of( + Conjunction.of(ConditionBuilder.column("ck1").isGreaterThanInt(10))), + ImmutableList.of(), + 0)); } @Test diff --git a/core/src/test/java/com/scalar/db/util/ScalarDbUtilsTest.java b/core/src/test/java/com/scalar/db/util/ScalarDbUtilsTest.java index 3cd6f46347..96766f334e 100644 --- a/core/src/test/java/com/scalar/db/util/ScalarDbUtilsTest.java +++ b/core/src/test/java/com/scalar/db/util/ScalarDbUtilsTest.java @@ -9,6 +9,7 @@ import com.scalar.db.api.ConditionBuilder; import com.scalar.db.api.Delete; import com.scalar.db.api.Get; +import com.scalar.db.api.GetWithIndex; import com.scalar.db.api.Insert; import com.scalar.db.api.LikeExpression; import com.scalar.db.api.Mutation; @@ -41,15 +42,33 @@ public class ScalarDbUtilsTest { @Test public void copyAndSetTargetToIfNot_GetGiven_ShouldReturnDifferentInstance() { // Arrange - Get get = new Get(new Key("c1", "v1")); + Get get = Get.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); // Act Get actual = ScalarDbUtils.copyAndSetTargetToIfNot(get, NAMESPACE, TABLE); // Assert assertThat(actual == get).isFalse(); + assertThat(actual instanceof GetWithIndex).isFalse(); assertThat(get.forNamespace()).isNotPresent(); - assertThat(get.forTable()).isNotPresent(); + assertThat(get.forTable()).isEqualTo(TABLE); + assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); + assertThat(actual.forTable()).isEqualTo(TABLE); + } + + @Test + public void copyAndSetTargetToIfNot_GetWithIndexGiven_ShouldReturnDifferentInstance() { + // Arrange + Get getWithIndex = Get.newBuilder().table(TABLE.get()).indexKey(Key.ofText("c1", "v1")).build(); + + // Act + Get actual = ScalarDbUtils.copyAndSetTargetToIfNot(getWithIndex, NAMESPACE, TABLE); + + // Assert + assertThat(actual == getWithIndex).isFalse(); + assertThat(actual instanceof GetWithIndex).isTrue(); + assertThat(getWithIndex.forNamespace()).isNotPresent(); + assertThat(getWithIndex.forTable()).isEqualTo(TABLE); assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); assertThat(actual.forTable()).isEqualTo(TABLE); } @@ -57,7 +76,7 @@ public void copyAndSetTargetToIfNot_GetGiven_ShouldReturnDifferentInstance() { @Test public void copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance() { // Arrange - Scan scan = new Scan(new Key("c1", "v1")); + Scan scan = Scan.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); // Act Scan actual = ScalarDbUtils.copyAndSetTargetToIfNot(scan, NAMESPACE, TABLE); @@ -67,7 +86,7 @@ public void copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance() { assertThat(actual instanceof ScanWithIndex).isFalse(); assertThat(actual instanceof ScanAll).isFalse(); assertThat(scan.forNamespace()).isNotPresent(); - assertThat(scan.forTable()).isNotPresent(); + assertThat(scan.forTable()).isEqualTo(TABLE); assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); assertThat(actual.forTable()).isEqualTo(TABLE); } @@ -75,7 +94,7 @@ public void copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance() { @Test public void copyAndSetTargetToIfNot_ScanAllGiven_ShouldReturnDifferentInstance() { // Arrange - Scan scanAll = new ScanAll(); + Scan scanAll = Scan.newBuilder().table(TABLE.get()).all().build(); // Act Scan actual = ScalarDbUtils.copyAndSetTargetToIfNot(scanAll, NAMESPACE, TABLE); @@ -84,7 +103,7 @@ public void copyAndSetTargetToIfNot_ScanAllGiven_ShouldReturnDifferentInstance() assertThat(actual == scanAll).isFalse(); assertThat(actual instanceof ScanAll).isTrue(); assertThat(scanAll.forNamespace()).isNotPresent(); - assertThat(scanAll.forTable()).isNotPresent(); + assertThat(scanAll.forTable()).isEqualTo(TABLE); assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); assertThat(actual.forTable()).isEqualTo(TABLE); } @@ -92,7 +111,8 @@ public void copyAndSetTargetToIfNot_ScanAllGiven_ShouldReturnDifferentInstance() @Test public void copyAndSetTargetToIfNot_ScanWithIndexGiven_ShouldReturnDifferentInstance() { // Arrange - Scan scanWithIndex = new ScanWithIndex(new Key("c2", "v2")); + Scan scanWithIndex = + Scan.newBuilder().table(TABLE.get()).indexKey(Key.ofText("c1", "v1")).build(); // Act Scan actual = ScalarDbUtils.copyAndSetTargetToIfNot(scanWithIndex, NAMESPACE, TABLE); @@ -101,7 +121,7 @@ public void copyAndSetTargetToIfNot_ScanWithIndexGiven_ShouldReturnDifferentInst assertThat(actual == scanWithIndex).isFalse(); assertThat(actual instanceof ScanWithIndex).isTrue(); assertThat(scanWithIndex.forNamespace()).isNotPresent(); - assertThat(scanWithIndex.forTable()).isNotPresent(); + assertThat(scanWithIndex.forTable()).isEqualTo(TABLE); assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); assertThat(actual.forTable()).isEqualTo(TABLE); } @@ -109,7 +129,7 @@ public void copyAndSetTargetToIfNot_ScanWithIndexGiven_ShouldReturnDifferentInst @Test public void copyAndSetTargetToIfNot_PutGiven_ShouldReturnDifferentInstance() { // Arrange - Put put = new Put(new Key("c1", "v1")); + Put put = Put.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); // Act Put actual = ScalarDbUtils.copyAndSetTargetToIfNot(put, NAMESPACE, TABLE); @@ -117,7 +137,7 @@ public void copyAndSetTargetToIfNot_PutGiven_ShouldReturnDifferentInstance() { // Assert assertThat(actual == put).isFalse(); assertThat(put.forNamespace()).isNotPresent(); - assertThat(put.forTable()).isNotPresent(); + assertThat(put.forTable()).isEqualTo(TABLE); assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); assertThat(actual.forTable()).isEqualTo(TABLE); } @@ -125,7 +145,8 @@ public void copyAndSetTargetToIfNot_PutGiven_ShouldReturnDifferentInstance() { @Test public void copyAndSetTargetToIfNot_DeleteGiven_ShouldReturnDifferentInstance() { // Arrange - Delete delete = new Delete(new Key("c1", "v1")); + Delete delete = + Delete.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); // Act Delete actual = ScalarDbUtils.copyAndSetTargetToIfNot(delete, NAMESPACE, TABLE); @@ -133,7 +154,7 @@ public void copyAndSetTargetToIfNot_DeleteGiven_ShouldReturnDifferentInstance() // Assert assertThat(actual == delete).isFalse(); assertThat(delete.forNamespace()).isNotPresent(); - assertThat(delete.forTable()).isNotPresent(); + assertThat(delete.forTable()).isEqualTo(TABLE); assertThat(actual.forNamespace()).isEqualTo(NAMESPACE); assertThat(actual.forTable()).isEqualTo(TABLE); } @@ -192,8 +213,9 @@ public void copyAndSetTargetToIfNot_UpdateGiven_ShouldReturnDifferentInstance() @Test public void copyAndSetTargetToIfNot_MutationsGiven_ShouldReturnDifferentInstance() { // Arrange - Put put = new Put(new Key("c1", "v1")); - Delete delete = new Delete(new Key("c1", "v1")); + Put put = Put.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); + Delete delete = + Delete.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); Insert insert = Insert.newBuilder().table(TABLE.get()).partitionKey(Key.ofText("c1", "v1")).build(); Upsert upsert = @@ -213,9 +235,9 @@ public void copyAndSetTargetToIfNot_MutationsGiven_ShouldReturnDifferentInstance assertThat(actual.get(3) == upsert).isFalse(); assertThat(actual.get(4) == update).isFalse(); assertThat(put.forNamespace()).isNotPresent(); - assertThat(put.forTable()).isNotPresent(); + assertThat(put.forTable()).isEqualTo(TABLE); assertThat(delete.forNamespace()).isNotPresent(); - assertThat(delete.forTable()).isNotPresent(); + assertThat(delete.forTable()).isEqualTo(TABLE); assertThat(insert.forNamespace()).isNotPresent(); assertThat(insert.forTable()).isEqualTo(TABLE); assertThat(upsert.forNamespace()).isNotPresent(); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java index e947eb7366..5a6d9885b8 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java @@ -5,8 +5,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableList; -import com.scalar.db.api.Scan.Ordering; -import com.scalar.db.api.Scan.Ordering.Order; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; @@ -113,7 +111,6 @@ protected Map getCreationOptions() { @BeforeEach public void setUp() throws Exception { truncateTable(); - storage.with(namespace, TABLE); } private void truncateTable() throws ExecutionException { @@ -153,10 +150,14 @@ private void dropTable() throws ExecutionException { @Test public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { // Arrange - storage.with(null, TABLE); - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); - Get get = new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, 0); + Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Get get = + Get.newBuilder() + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); @@ -165,11 +166,15 @@ public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { @Test public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() { // Arrange - storage.with("wrong_" + namespace, TABLE); // a wrong namespace - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); - Get get = new Get(partitionKey, clusteringKey); - + Key partitionKey = Key.ofInt(COL_NAME1, 0); + Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Get get = + Get.newBuilder() + .namespace("wrong_" + namespace) // a wrong namespace + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); } @@ -177,10 +182,15 @@ public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() @Test public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() { // Arrange - storage.with(namespace, "wrong_" + TABLE); // a wrong table - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); - Get get = new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, 0); + Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Get get = + Get.newBuilder() + .namespace(namespace) + .table("wrong_" + TABLE) // a wrong table + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); @@ -189,7 +199,7 @@ public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() { @Test public void operation_DefaultNamespaceGiven_ShouldWorkProperly() { Properties properties = getProperties(TEST_NAME); - properties.put(DatabaseConfig.DEFAULT_NAMESPACE_NAME, getNamespace()); + properties.put(DatabaseConfig.DEFAULT_NAMESPACE_NAME, namespace); final DistributedStorage storageWithDefaultNamespace = StorageFactory.create(properties).getStorage(); try { @@ -272,8 +282,8 @@ public void get_GetWithoutPartitionKeyGiven_ShouldThrowInvalidUsageException() { int pKey = 0; // Act Assert - Key partitionKey = new Key(COL_NAME1, pKey); - Get get = new Get(partitionKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Get get = Get.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build(); assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); } @@ -352,11 +362,15 @@ public void scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues() // Act Scan scan = - new Scan(Key.ofInt(COL_NAME1, pKey)) - .withProjection(COL_NAME1) - .withProjection(COL_NAME2) - .withProjection(COL_NAME3) - .withProjection(COL_NAME6); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .projection(COL_NAME1) + .projection(COL_NAME2) + .projection(COL_NAME3) + .projection(COL_NAME6) + .build(); List actual = scanAll(scan); // Assert @@ -384,7 +398,12 @@ public void scan_ScanWithPartitionKeyGivenAndResultsIteratedWithOne_ShouldReturn int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); Scanner scanner = storage.scan(scan); // Assert @@ -430,7 +449,12 @@ public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyE int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); double t1 = System.currentTimeMillis(); List actual = scanAll(scan); double t2 = System.currentTimeMillis(); @@ -460,9 +484,13 @@ public void scan_ScanWithStartInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRa // Act Scan scan = - new Scan(new Key(COL_NAME1, pKey)) - .withStart(new Key(COL_NAME4, 0), true) - .withEnd(new Key(COL_NAME4, 2), false); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .start(Key.ofInt(COL_NAME4, 0)) + .end(Key.ofInt(COL_NAME4, 2), false) + .build(); List actual = scanAll(scan); // verify @@ -486,9 +514,13 @@ public void scan_ScanWithEndInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRang // Act Scan scan = - new Scan(new Key(COL_NAME1, pKey)) - .withStart(new Key(COL_NAME4, 0), false) - .withEnd(new Key(COL_NAME4, 2), true); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .start(Key.ofInt(COL_NAME4, 0), false) + .end(Key.ofInt(COL_NAME4, 2)) + .build(); List actual = scanAll(scan); // verify @@ -510,8 +542,14 @@ public void scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults() List puts = preparePuts(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.ASC)); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .start(Key.ofInt(COL_NAME4, 0)) + .end(Key.ofInt(COL_NAME4, 2)) + .ordering(Scan.Ordering.asc(COL_NAME4)) + .build(); // Act List actual = scanAll(scan); @@ -533,8 +571,16 @@ public void scan_ScanWithOrderDescGiven_ShouldReturnDescendingOrderedResults() List puts = preparePuts(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .start(Key.ofInt(COL_NAME4, 0)) + .end(Key.ofInt(COL_NAME4, 2)) + .ordering(Scan.Ordering.desc(COL_NAME4)) + .build(); + new Scan(Key.ofInt(COL_NAME1, 0)) + .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)); // Act List actual = scanAll(scan); @@ -557,9 +603,13 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)) - .withLimit(1); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .ordering(Scan.Ordering.desc(COL_NAME4)) + .limit(1) + .build(); // exercise List actual = scanAll(scan); @@ -580,7 +630,7 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() // Act Scan scan = Scan.newBuilder() - .namespace(getNamespace()) + .namespace(namespace) .table(TABLE) .partitionKey(Key.ofInt(COL_NAME1, 0)) .start(Key.ofInt(COL_NAME4, 0)) @@ -609,7 +659,12 @@ public void scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResul int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); scanner.forEach(actual::add); @@ -639,7 +694,12 @@ public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); Optional result = scanner.one(); @@ -672,7 +732,12 @@ public void scannerIterator_AllAndIteratorCalled_ShouldRetrieveCorrectResults() int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); List all = scanner.all(); @@ -705,7 +770,12 @@ public void scannerIterator_IteratorCalledMultipleTimes_ShouldRetrieveCorrectRes int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); actual.add(scanner.iterator().next()); @@ -735,9 +805,15 @@ public void put_SinglePutGiven_ShouldStoreProperly() throws ExecutionException { int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); - Get get = new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act storage.put(puts.get(pKey * 2 + cKey)); @@ -764,9 +840,15 @@ public void put_SinglePutWithIfNotExistsGiven_ShouldStoreProperly() throws Execu int cKey = 0; List puts = preparePuts(); puts.get(0).withCondition(new PutIfNotExists()); - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); - Get get = new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act storage.put(puts.get(0)); @@ -794,7 +876,12 @@ public void put_MultiplePutGiven_ShouldStoreProperly() throws IOException, Execu int pKey = 0; int cKey = 0; List puts = preparePuts(); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -827,7 +914,12 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() puts.get(0).withCondition(new PutIfNotExists()); puts.get(1).withCondition(new PutIfNotExists()); puts.get(2).withCondition(new PutIfNotExists()); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -853,32 +945,70 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() @Test public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionException { // Arrange - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + Key partitionKey = Key.ofInt(COL_NAME1, 0); + Key clusteringKey = Key.ofInt(COL_NAME4, 0); // Act - assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) + assertThatCode( + () -> + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build())) .doesNotThrowAnyException(); // Assert - Optional result = storage.get(new Get(partitionKey, clusteringKey)); + Optional result = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); assertThat(result).isPresent(); } @Test public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws ExecutionException { // Arrange - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + Key partitionKey = Key.ofInt(COL_NAME1, 0); + Key clusteringKey = Key.ofInt(COL_NAME4, 0); // Act - assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) + assertThatCode( + () -> + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build())) .doesNotThrowAnyException(); - assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) + assertThatCode( + () -> + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build())) .doesNotThrowAnyException(); // Assert - Optional result = storage.get(new Get(partitionKey, clusteringKey)); + Optional result = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); assertThat(result).isPresent(); } @@ -893,7 +1023,12 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati puts.get(0).withCondition(new PutIfNotExists()); puts.get(1).withCondition(new PutIfNotExists()); puts.get(2).withCondition(new PutIfNotExists()); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); // Act assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -922,11 +1057,29 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati // Assert List results; - results = scanAll(new Scan(new Key(COL_NAME1, 0))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .build()); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 3))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 3)) + .build()); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 6))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 6)) + .build()); assertThat(results.size()).isEqualTo(0); } @@ -942,11 +1095,29 @@ public void put_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgume // Assert List results; - results = scanAll(new Scan(new Key(COL_NAME1, 0))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .build()); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 3))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 3)) + .build()); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 6))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 6)) + .build()); assertThat(results.size()).isEqualTo(0); } @@ -968,7 +1139,13 @@ public void put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(COL_NAME1, 0))); + List results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .build()); assertThat(results.size()).isEqualTo(2); assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); @@ -1167,14 +1344,16 @@ public void delete_DeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingl populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); // Act Delete delete = prepareDelete(pKey, cKey); assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(partitionKey)); + List results = + scanAll( + Scan.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build()); assertThat(results.size()).isEqualTo(2); assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); @@ -1205,8 +1384,8 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1214,7 +1393,14 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); // Assert - Optional actual = storage.get(new Get(partitionKey, clusteringKey)); + Optional actual = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); assertThat(actual.isPresent()).isFalse(); } @@ -1225,8 +1411,8 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1239,7 +1425,14 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class); // Assert - Optional actual = storage.get(new Get(partitionKey, clusteringKey)); + Optional actual = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); assertThat(actual.isPresent()).isTrue(); } @@ -1250,8 +1443,8 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1264,7 +1457,14 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); // Assert - Optional actual = storage.get(new Get(partitionKey, clusteringKey)); + Optional actual = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); assertThat(actual.isPresent()).isFalse(); } @@ -1289,7 +1489,13 @@ public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProper .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(COL_NAME1, 0))); + List results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .build()); assertThat(results.size()).isEqualTo(0); } @@ -1299,7 +1505,12 @@ public void mutate_MultiplePutGiven_ShouldStoreProperly() throws ExecutionExcept int pKey = 0; int cKey = 0; List puts = preparePuts(); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); // Act assertThatCode(() -> storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -1334,11 +1545,29 @@ public void mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArg // Assert List results; - results = scanAll(new Scan(new Key(COL_NAME1, 0))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .build()); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 3))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 3)) + .build()); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 6))); + results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 6)) + .build()); assertThat(results.size()).isEqualTo(0); } @@ -1355,7 +1584,12 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() int cKey = 0; Delete delete = prepareDelete(pKey, cKey); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .build(); // Act assertThatCode(() -> storage.mutate(Arrays.asList(delete, puts.get(1), puts.get(2)))) @@ -1380,9 +1614,15 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); - Get get = new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act storage.mutate(Collections.singletonList(puts.get(pKey * 2 + cKey))); @@ -1412,14 +1652,22 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio int cKey = 0; // Act - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); - Delete delete = new Delete(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); assertThatCode(() -> storage.mutate(Collections.singletonList(delete))) .doesNotThrowAnyException(); // Assert - List actual = scanAll(new Scan(partitionKey)); + List actual = + scanAll( + Scan.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build()); assertThat(actual.size()).isEqualTo(2); assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); @@ -1442,8 +1690,8 @@ public void mutate_EmptyListGiven_ShouldThrowIllegalArgumentException() { public void put_PutWithoutClusteringKeyGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Put put = new Put(partitionKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Put put = Put.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build(); // Act Assert assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class); @@ -1454,8 +1702,14 @@ public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Put put = new Put(partitionKey).withValue(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Put put = + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .intValue(COL_NAME4, cKey) + .build(); // Act Assert assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class); @@ -1482,8 +1736,7 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { // Arrange storage.put(preparePuts().get(0)); // (0,0) int c3 = 0; - Get getBuiltByConstructor = new Get(new Key(COL_NAME3, c3)); - Get getBuiltByBuilder = + Get get = Get.newBuilder() .namespace(namespace) .table(TABLE) @@ -1491,17 +1744,12 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { .build(); // Act - Optional actual1 = storage.get(getBuiltByConstructor); - Optional actual2 = storage.get(getBuiltByBuilder); + Optional actual = storage.get(get); // Assert - assertThat(actual1.isPresent()).isTrue(); - assertThat(actual1.get().getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, 0))); - assertThat(actual1.get().getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); - - assertThat(actual2).isEqualTo(actual1); + assertThat(actual.isPresent()).isTrue(); + assertThat(actual.get().getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, 0))); + assertThat(actual.get().getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); } @Test @@ -1558,7 +1806,12 @@ public void get_GetGivenForIndexedColumnWithUnmatchedConjunctions_ShouldReturnEm // Arrange populateRecords(); int c3 = 3; - Get get = new Get(new Key(COL_NAME3, c3)); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .indexKey(Key.ofInt(COL_NAME3, c3)) + .build(); // Act Assert assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); @@ -1569,8 +1822,7 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws ExecutionExceptio // Arrange populateRecords(); int c3 = 3; - Scan scanBuiltByConstructor = new Scan(new Key(COL_NAME3, c3)); - Scan scanBuiltByBuilder = + Scan scan = Scan.newBuilder() .namespace(namespace) .table(TABLE) @@ -1578,15 +1830,14 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws ExecutionExceptio .build(); // Act - List actual1 = scanAll(scanBuiltByConstructor); - List actual2 = scanAll(scanBuiltByBuilder); + List actual = scanAll(scan); // Assert - assertThat(actual1.size()).isEqualTo(3); // (1,2), (2,1), (3,0) + assertThat(actual.size()).isEqualTo(3); // (1,2), (2,1), (3,0) List> expectedValues = new ArrayList<>( Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1), Arrays.asList(3, 0))); - for (Result result : actual1) { + for (Result result : actual) { assertThat(result.getValue(COL_NAME1).isPresent()).isTrue(); assertThat(result.getValue(COL_NAME4).isPresent()).isTrue(); @@ -1597,8 +1848,6 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws ExecutionExceptio expectedValues.remove(col1AndCol4); } assertThat(expectedValues).isEmpty(); - - assertThat(actual2).isEqualTo(actual1); } @Test @@ -1606,7 +1855,12 @@ public void scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentExceptio // Arrange populateRecords(); String c2 = "test"; - Scan scan = new Scan(new Key(COL_NAME2, c2)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .indexKey(Key.ofText(COL_NAME2, c2)) + .build(); // Act Assert assertThatThrownBy(() -> scanAll(scan)).isInstanceOf(IllegalArgumentException.class); @@ -1618,15 +1872,21 @@ public void scan_ScanLargeData_ShouldRetrieveExpectedValues() int recordCount = 345; // Arrange - Key partitionKey = new Key(COL_NAME1, 1); + Key partitionKey = Key.ofInt(COL_NAME1, 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = new Key(COL_NAME4, i); + Key clusteringKey = Key.ofInt(COL_NAME4, i); storage.put( - new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .build()); } - Scan scan = new Scan(partitionKey); + Scan scan = + Scan.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build(); // Act List results = scanAll(scan); @@ -1646,16 +1906,33 @@ public void scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues() int fetchCount = 234; // Arrange - Key partitionKey = new Key(COL_NAME1, 1); + Key partitionKey = Key.ofInt(COL_NAME1, 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = new Key(COL_NAME4, i); + Key clusteringKey = Key.ofInt(COL_NAME4, i); storage.put( - new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .build()); } - Scan scanAsc = new Scan(partitionKey).withOrdering(new Ordering(COL_NAME4, Order.ASC)); - Scan scanDesc = new Scan(partitionKey).withOrdering(new Ordering(COL_NAME4, Order.DESC)); + Scan scanAsc = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .ordering(Scan.Ordering.asc(COL_NAME4)) + .build(); + Scan scanDesc = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .ordering(Scan.Ordering.desc(COL_NAME4)) + .build(); // Act List resultsAsc = new ArrayList<>(); @@ -1694,14 +1971,25 @@ public void scan_ScanLargeDataWithLimit_ShouldRetrieveExpectedValues() throws Ex int recordCount = 345; int limit = 234; - Key partitionKey = new Key(COL_NAME1, 1); + Key partitionKey = Key.ofInt(COL_NAME1, 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = new Key(COL_NAME4, i); + Key clusteringKey = Key.ofInt(COL_NAME4, i); storage.put( - new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .build()); } - Scan scan = new Scan(partitionKey).withLimit(limit); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .limit(limit) + .build(); // Act List results = storage.scan(scan).all(); @@ -1719,7 +2007,7 @@ public void scan_ScanAllWithNoLimitGiven_ShouldRetrieveAllRecords() throws ExecutionException, IOException { // Arrange populateRecords(); - ScanAll scanAll = new ScanAll(); + Scan scanAll = Scan.newBuilder().namespace(namespace).table(TABLE).all().build(); // Act List results = scanAll(scanAll); @@ -1748,14 +2036,38 @@ public void scan_ScanAllWithNoLimitGiven_ShouldRetrieveAllRecords() public void scan_ScanAllWithLimitGiven_ShouldRetrieveExpectedRecords() throws ExecutionException, IOException { // Arrange - Put p1 = new Put(Key.ofInt(COL_NAME1, 1), Key.ofInt(COL_NAME4, 1)); - Put p2 = new Put(Key.ofInt(COL_NAME1, 1), Key.ofInt(COL_NAME4, 2)); - Put p3 = new Put(Key.ofInt(COL_NAME1, 2), Key.ofInt(COL_NAME4, 1)); - Put p4 = new Put(Key.ofInt(COL_NAME1, 3), Key.ofInt(COL_NAME4, 0)); + Put p1 = + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 1)) + .clusteringKey(Key.ofInt(COL_NAME4, 1)) + .build(); + Put p2 = + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 1)) + .clusteringKey(Key.ofInt(COL_NAME4, 2)) + .build(); + Put p3 = + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 2)) + .clusteringKey(Key.ofInt(COL_NAME4, 1)) + .build(); + Put p4 = + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 3)) + .clusteringKey(Key.ofInt(COL_NAME4, 0)) + .build(); storage.put(ImmutableList.of(p1, p2)); storage.put(p3); storage.put(p4); - ScanAll scanAll = new ScanAll().withLimit(2); + Scan scanAll = Scan.newBuilder().namespace(namespace).table(TABLE).all().limit(2).build(); // Act List results = scanAll(scanAll); @@ -1806,8 +2118,13 @@ public void scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues() populateRecords(); // Act - ScanAll scanAll = - new ScanAll().withProjections(Arrays.asList(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6)); + Scan scanAll = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .all() + .projections(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6) + .build(); List actualResults = scanAll(scanAll); // Assert @@ -1837,13 +2154,18 @@ public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException { // Arrange for (int i = 0; i < 345; i++) { - Key partitionKey = new Key(COL_NAME1, i % 4); - Key clusteringKey = new Key(COL_NAME4, i); + Key partitionKey = Key.ofInt(COL_NAME1, i % 4); + Key clusteringKey = Key.ofInt(COL_NAME4, i); storage.put( - new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .build()); } - Scan scan = new ScanAll(); + Scan scan = Scan.newBuilder().namespace(namespace).table(TABLE).all().build(); // Act List results = scanAll(scan); @@ -1894,17 +2216,26 @@ public void scan_ScanWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyProje throws ExecutionException, IOException { // Arrange Put put = - new Put(Key.ofInt(COL_NAME1, 0), Key.ofInt(COL_NAME4, 0)) - .withTextValue(COL_NAME2, "foo") - .withIntValue(COL_NAME3, 0) - .withBooleanValue(COL_NAME5, true) - .forNamespace(namespace) - .forTable(TABLE); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .clusteringKey(Key.ofInt(COL_NAME4, 0)) + .textValue(COL_NAME2, "foo") + .intValue(COL_NAME3, 0) + .booleanValue(COL_NAME5, true) + .build(); storage.put(put); // Act Scan scan = - new Scan(Key.ofInt(COL_NAME1, 0)).withProjection(COL_NAME3).withProjection(COL_NAME5); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .projection(COL_NAME3) + .projection(COL_NAME5) + .build(); List results = scanAll(scan); // Assert @@ -1919,16 +2250,26 @@ public void scan_ScanAllWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyPr throws ExecutionException, IOException { // Arrange Put put = - new Put(Key.ofInt(COL_NAME1, 0), Key.ofInt(COL_NAME4, 0)) - .withTextValue(COL_NAME2, "foo") - .withIntValue(COL_NAME3, 0) - .withBooleanValue(COL_NAME5, true) - .forNamespace(namespace) - .forTable(TABLE); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(COL_NAME1, 0)) + .clusteringKey(Key.ofInt(COL_NAME4, 0)) + .textValue(COL_NAME2, "foo") + .intValue(COL_NAME3, 0) + .booleanValue(COL_NAME5, true) + .build(); storage.put(put); // Act - ScanAll scanAll = new ScanAll().withProjection(COL_NAME3).withProjection(COL_NAME5); + Scan scanAll = + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .all() + .projection(COL_NAME3) + .projection(COL_NAME5) + .build(); List results = scanAll(scanAll); // Assert @@ -1944,15 +2285,20 @@ public void scan_ScanAllLargeData_ShouldRetrieveExpectedValues() int recordCount = 345; // Arrange - Key clusteringKey = new Key(COL_NAME4, 1); + Key clusteringKey = Key.ofInt(COL_NAME4, 1); for (int i = 0; i < recordCount; i++) { - Key partitionKey = new Key(COL_NAME1, i); + Key partitionKey = Key.ofInt(COL_NAME1, i); storage.put( - new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .build()); } - ScanAll scanAll = new ScanAll(); + Scan scanAll = Scan.newBuilder().namespace(namespace).table(TABLE).all().build(); // Act List results = scanAll(scanAll); @@ -1976,15 +2322,20 @@ public void scan_ScanAllLargeDataWithLimit_ShouldRetrieveExpectedValues() int recordCount = 345; int limit = 234; - Key clusteringKey = new Key(COL_NAME4, 1); + Key clusteringKey = Key.ofInt(COL_NAME4, 1); for (int i = 0; i < recordCount; i++) { - Key partitionKey = new Key(COL_NAME1, i); + Key partitionKey = Key.ofInt(COL_NAME1, i); storage.put( - new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .build()); } - Scan scan = new ScanAll().withLimit(limit); + Scan scan = Scan.newBuilder().namespace(namespace).table(TABLE).all().limit(limit).build(); // Act List results = storage.scan(scan).all(); @@ -2007,9 +2358,14 @@ private void populateRecords() { } private Get prepareGet(int pKey, int cKey) { - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); - return new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + return Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private List preparePuts() { @@ -2021,13 +2377,18 @@ private List preparePuts() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(COL_NAME1, i); - Key clusteringKey = new Key(COL_NAME4, j); + Key partitionKey = Key.ofInt(COL_NAME1, i); + Key clusteringKey = Key.ofInt(COL_NAME4, j); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME2, Integer.toString(i + j)) - .withValue(COL_NAME3, i + j) - .withValue(COL_NAME5, j % 2 == 0); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(COL_NAME2, Integer.toString(i + j)) + .intValue(COL_NAME3, i + j) + .booleanValue(COL_NAME5, j % 2 == 0) + .build(); puts.add(put); })); @@ -2035,9 +2396,14 @@ private List preparePuts() { } private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); - return new Delete(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + return Delete.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private List prepareDeletes() { @@ -2049,9 +2415,15 @@ private List prepareDeletes() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(COL_NAME1, i); - Key clusteringKey = new Key(COL_NAME4, j); - Delete delete = new Delete(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(COL_NAME1, i); + Key clusteringKey = Key.ofInt(COL_NAME4, j); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); deletes.add(delete); })); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java index 8fd2de48d0..7b5e8d9006 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java @@ -109,7 +109,6 @@ protected Map getCreationOptions() { @BeforeEach public void setUp() throws Exception { truncateTable(); - storage.with(namespace, tableName); } private void truncateTable() throws ExecutionException { @@ -200,10 +199,14 @@ public void scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecif // Act Scan scan = - new Scan(new Key(columnName1, pKey)) - .withProjection(columnName1) - .withProjection(columnName2) - .withProjection(columnName3); + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(Key.ofInt(columnName1, pKey)) + .projection(columnName1) + .projection(columnName2) + .projection(columnName3) + .build(); List actual = scanAll(scan); // Assert @@ -229,7 +232,12 @@ public void scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecif int pKey = 0; // Act - Scan scan = new Scan(new Key(columnName1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(Key.ofInt(columnName1, pKey)) + .build(); Scanner scanner = storage.scan(scan); // Assert @@ -274,9 +282,15 @@ public void put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly() int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - Get get = new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(columnName1, pKey); + Key clusteringKey = Key.ofInt(columnName4, cKey); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act storage.put(puts.get(pKey * 2 + cKey)); @@ -334,7 +348,12 @@ public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() int pKey = 0; int cKey = 0; List puts = preparePuts(); - Scan scan = new Scan(new Key(columnName1, pKey)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(Key.ofInt(columnName1, pKey)) + .build(); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -376,7 +395,13 @@ public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(columnName1, 0))); + List results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(Key.ofInt(columnName1, 0)) + .build()); assertThat(results.size()).isEqualTo(2); assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue(); assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0); @@ -396,14 +421,19 @@ public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(columnName1, pKey); // Act Delete delete = prepareDelete(pKey, cKey); assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(partitionKey)); + List results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(Key.ofInt(columnName1, pKey)) + .build()); assertThat(results.size()).isEqualTo(2); assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue(); assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0); @@ -437,7 +467,13 @@ public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(columnName1, 0))); + List results = + scanAll( + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(Key.ofInt(columnName1, 0)) + .build()); assertThat(results.size()).isEqualTo(0); } @@ -449,8 +485,8 @@ public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); + Key partitionKey = Key.ofInt(columnName1, pKey); + Key clusteringKey = Key.ofInt(columnName4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -463,7 +499,14 @@ public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); // Assert - Optional actual = storage.get(new Get(partitionKey, clusteringKey)); + Optional actual = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); assertThat(actual.isPresent()).isFalse(); } @@ -473,7 +516,12 @@ public void get_WithReservedKeywordAndGetGivenForIndexedColumn_ShouldGet() // Arrange storage.put(preparePuts().get(0)); // (0,0) int c3 = 0; - Get get = new Get(new Key(columnName3, c3)); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(tableName) + .indexKey(Key.ofInt(columnName3, c3)) + .build(); // Act Optional actual = storage.get(get); @@ -492,7 +540,12 @@ public void scan_WithReservedKeywordAndScanGivenForIndexedColumn_ShouldScan() // Arrange populateRecords(); int c3 = 3; - Scan scan = new Scan(new Key(columnName3, c3)); + Scan scan = + Scan.newBuilder() + .namespace(namespace) + .table(tableName) + .indexKey(Key.ofInt(columnName3, c3)) + .build(); // Act List actual = scanAll(scan); @@ -522,9 +575,9 @@ public void scan_WithReservedKeywordAndClusteringKeyRange_ShouldReturnProperResu // Arrange populateRecords(); Scan scan = - new Scan(new Key(columnName1, 1)) - .withStart(new Key(columnName4, 1), false) - .withEnd(new Key(columnName4, 3), false) + new Scan(Key.ofInt(columnName1, 1)) + .withStart(Key.ofInt(columnName4, 1), false) + .withEnd(Key.ofInt(columnName4, 3), false) .withOrdering(new Ordering(columnName4, Order.DESC)) .forNamespace(namespace) .forTable(tableName); @@ -546,9 +599,14 @@ private void populateRecords() { } private Get prepareGet(int pKey, int cKey) { - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - return new Get(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(columnName1, pKey); + Key clusteringKey = Key.ofInt(columnName4, cKey); + return Get.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private List preparePuts() { @@ -560,13 +618,18 @@ private List preparePuts() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(columnName1, i); - Key clusteringKey = new Key(columnName4, j); + Key partitionKey = Key.ofInt(columnName1, i); + Key clusteringKey = Key.ofInt(columnName4, j); Put put = - new Put(partitionKey, clusteringKey) - .withValue(columnName2, Integer.toString(i + j)) - .withValue(columnName3, i + j) - .withValue(columnName5, j % 2 == 0); + Put.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(columnName2, Integer.toString(i + j)) + .intValue(columnName3, i + j) + .booleanValue(columnName5, j % 2 == 0) + .build(); puts.add(put); })); @@ -574,9 +637,14 @@ private List preparePuts() { } private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - return new Delete(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(columnName1, pKey); + Key clusteringKey = Key.ofInt(columnName4, cKey); + return Delete.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private List prepareDeletes() { @@ -588,9 +656,15 @@ private List prepareDeletes() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(columnName1, i); - Key clusteringKey = new Key(columnName4, j); - Delete delete = new Delete(partitionKey, clusteringKey); + Key partitionKey = Key.ofInt(columnName1, i); + Key clusteringKey = Key.ofInt(columnName4, j); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); deletes.add(delete); }));