Skip to content

Commit

Permalink
Backport to branch(3) : Rename Relational Scan to Cross-partition Scan (
Browse files Browse the repository at this point in the history
#1330)

Co-authored-by: Toshihiro Suzuki <[email protected]>
  • Loading branch information
feeblefakie and brfrn169 authored Nov 28, 2023
1 parent 3bc5607 commit 87a9d92
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.scalar.db.storage.jdbc;

import com.scalar.db.transaction.consensuscommit.ConsensusCommitRelationalScanIntegrationTestBase;
import com.scalar.db.transaction.consensuscommit.ConsensusCommitCrossPartitionScanIntegrationTestBase;
import java.util.Properties;

public class ConsensusCommitRelationalScanIntegrationTestWithJdbcDatabase
extends ConsensusCommitRelationalScanIntegrationTestBase {
public class ConsensusCommitCrossPartitionScanIntegrationTestWithJdbcDatabase
extends ConsensusCommitCrossPartitionScanIntegrationTestBase {

@Override
protected Properties getProps(String testName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.scalar.db.storage.jdbc;

import com.scalar.db.api.DistributedStorageRelationalScanIntegrationTestBase;
import com.scalar.db.api.DistributedStorageCrossPartitionScanIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.io.Column;
import com.scalar.db.io.DataType;
import com.scalar.db.util.ScalarDbUtils;
import java.util.Properties;
import java.util.Random;

public class JdbcDatabaseRelationalScanIntegrationTest
extends DistributedStorageRelationalScanIntegrationTestBase {
public class JdbcDatabaseCrossPartitionScanIntegrationTest
extends DistributedStorageCrossPartitionScanIntegrationTestBase {

private RdbEngineStrategy rdbEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.scalar.db.storage.jdbc;

import com.scalar.db.transaction.consensuscommit.TwoPhaseConsensusCommitRelationalScanIntegrationTestBase;
import com.scalar.db.transaction.consensuscommit.TwoPhaseConsensusCommitCrossPartitionScanIntegrationTestBase;
import java.util.Properties;

public class TwoPhaseConsensusCommitRelationalScanIntegrationTestWithJdbcDatabase
extends TwoPhaseConsensusCommitRelationalScanIntegrationTestBase {
public class TwoPhaseConsensusCommitCrossPartitionScanIntegrationTestWithJdbcDatabase
extends TwoPhaseConsensusCommitCrossPartitionScanIntegrationTestBase {

@Override
protected Properties getProps1(String testName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.scalar.db.transaction.jdbc;

import com.scalar.db.api.DistributedTransactionRelationalScanIntegrationTestBase;
import com.scalar.db.api.DistributedTransactionCrossPartitionScanIntegrationTestBase;
import com.scalar.db.config.DatabaseConfig;
import com.scalar.db.storage.jdbc.JdbcEnv;
import java.util.Properties;

public class JdbcTransactionRelationalScanIntegrationTest
extends DistributedTransactionRelationalScanIntegrationTestBase {
public class JdbcTransactionCrossPartitionScanIntegrationTest
extends DistributedTransactionCrossPartitionScanIntegrationTestBase {

@Override
protected String getTestName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Builder {
boolean isRangeQuery;
Optional<String> indexedColumn = Optional.empty();
boolean isConditionalQuery;
boolean isRelationalQuery;
boolean isCrossPartitionQuery;
Set<Conjunction> conjunctions = Collections.emptySet();

Builder(RdbEngineStrategy rdbEngine, List<String> projections) {
Expand Down Expand Up @@ -124,10 +124,10 @@ private void setIndexInfoIfUsed(Key partitionKey) {
}

/*
* Assumes this is called by relational scan operations
* Assumes this is called by cross-partition scan operations
*/
public Builder where(Set<Conjunction> conjunctions) {
isRelationalQuery = true;
isCrossPartitionQuery = true;
this.conjunctions = ImmutableSet.copyOf(conjunctions);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SimpleSelectQuery implements SelectQuery {
private final boolean isRangeQuery;
private final Optional<String> indexedColumn;
private final boolean isConditionalQuery;
private final boolean isRelationalQuery;
private final boolean isCrossPartitionQuery;
private final Set<Conjunction> conjunctions;

SimpleSelectQuery(Builder builder) {
Expand All @@ -57,7 +57,7 @@ public class SimpleSelectQuery implements SelectQuery {
isRangeQuery = builder.isRangeQuery;
indexedColumn = builder.indexedColumn;
isConditionalQuery = builder.isConditionalQuery;
isRelationalQuery = builder.isRelationalQuery;
isCrossPartitionQuery = builder.isCrossPartitionQuery;
conjunctions = builder.conjunctions;
}

Expand All @@ -68,12 +68,12 @@ public String sql() {
.append(projectionSqlString())
.append(" FROM ")
.append(rdbEngine.encloseFullTableName(schema, table));
if (isRelationalQuery) {
// for relational abstraction
builder.append(relationalConditionSqlString());
builder.append(relationalOrderBySqlString());
if (isCrossPartitionQuery) {
// for cross-partition scan
builder.append(crossPartitionConditionSqlString());
builder.append(crossPartitionOrderBySqlString());
} else {
// for multi-dimensional map abstraction
// for multi-dimensional map scan
if (isConditionalQuery) {
builder.append(" WHERE ");
builder.append(conditionSqlString());
Expand Down Expand Up @@ -106,7 +106,7 @@ private String conditionSqlString() {
return String.join(" AND ", conditions);
}

private String relationalConditionSqlString() {
private String crossPartitionConditionSqlString() {
if (conjunctions.isEmpty()) {
return "";
}
Expand Down Expand Up @@ -200,7 +200,7 @@ private String orderBySqlString() {
.collect(Collectors.joining(","));
}

private String relationalOrderBySqlString() {
private String crossPartitionOrderBySqlString() {
if (orderings.isEmpty()) {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ public List<Result> scan(Scan scan) throws CrudException {
List<Result> results = scanInternal(scan);

// We verify if this scan does not overlap previous writes after the actual scan. For a
// relational scan, this must be done here, using the obtained keys in the scan set and scan
// condition. This is because the condition (i.e., where clause) is arbitrary in the relational
// scan, and thus, the write command may not have columns used in the condition, which are
// necessary to determine overlaps. For a scan with clustering keys, we can determine overlaps
// without the actual scan, but we also check it here for consistent logic and readability.
// cross-partition scan, this must be done here, using the obtained keys in the scan set and
// scan condition. This is because the condition (i.e., where clause) is arbitrary in the
// cross-partition scan, and thus, the write command may not have columns used in the condition,
// which are necessary to determine overlaps. For a scan with clustering keys, we can determine
// overlaps without the actual scan, but we also check it here for consistent logic and
// readability.
snapshot.verify(scan);

return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public void whenGetScannerExecuted_withScanAll_shouldCallQueryBuilder() throws E
}

@Test
public void whenGetScannerExecuted_withRelationalScan_shouldCallQueryBuilder() throws Exception {
public void whenGetScannerExecuted_withCrossPartitionScan_shouldCallQueryBuilder()
throws Exception {
// Arrange
when(queryBuilder.select(any())).thenReturn(selectQueryBuilder);

Expand Down Expand Up @@ -243,7 +244,7 @@ public void whenScanExecuted_withScanAll_shouldCallQueryBuilder() throws Excepti
}

@Test
public void whenScanExecuted_withRelationalScan_shouldCallQueryBuilder() throws Exception {
public void whenScanExecuted_withCrossPartitionScan_shouldCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.select(any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.from(any(), any(), any())).thenReturn(selectQueryBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class QueryBuilderTest {
.addSecondaryIndex("v2")
.build();

private static final TableMetadata RELATIONAL_TABLE_METADATA =
private static final TableMetadata CROSS_PARTITION_TABLE_METADATA =
TableMetadata.newBuilder()
.addColumn("p1", DataType.TEXT)
.addColumn("p2", DataType.INT)
Expand Down Expand Up @@ -346,15 +346,15 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(ImmutableSet.of())
.build();
assertThat(query.sql()).isEqualTo(encloseSql("SELECT * FROM n1.t1", rdbEngine));

query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(ImmutableSet.of())
.orderBy(
Arrays.asList(
Expand All @@ -367,7 +367,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Arrays.asList("v1", "v2"))
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(ImmutableSet.of())
.build();
assertThat(query.sql()).isEqualTo(encloseSql("SELECT v1,v2 FROM n1.t1", rdbEngine));
Expand All @@ -376,7 +376,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(Scan.Conjunction.of(ConditionBuilder.column("v1").isEqualToInt(1))))
.build();
Expand All @@ -388,7 +388,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand All @@ -405,7 +405,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(ConditionBuilder.column("v1").isEqualToInt(1)),
Expand All @@ -421,7 +421,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand All @@ -444,7 +444,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand All @@ -469,7 +469,7 @@ public void selectQueryWithConjunctionsTest(RdbEngine rdbEngineType) throws SQLE
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand Down Expand Up @@ -498,7 +498,7 @@ public void selectQueryWithLikeConditionsTestForMySql(RdbEngine rdbEngineType)
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand Down Expand Up @@ -548,7 +548,7 @@ public void selectQueryWithLikeConditionsTestForPostgres(RdbEngine rdbEngineType
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand Down Expand Up @@ -598,7 +598,7 @@ public void selectQueryWithLikeConditionsTestForOracleAndSqlLite(RdbEngine rdbEn
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand Down Expand Up @@ -646,7 +646,7 @@ public void selectQueryWithLikeConditionsTestForSQLServer(RdbEngine rdbEngineTyp
query =
queryBuilder
.select(Collections.emptyList())
.from(NAMESPACE, TABLE, RELATIONAL_TABLE_METADATA)
.from(NAMESPACE, TABLE, CROSS_PARTITION_TABLE_METADATA)
.where(
ImmutableSet.of(
Scan.Conjunction.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private Scan prepareScan() {
return new Scan(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}

private Scan prepareRelationalScan() {
private Scan prepareCrossPartitionScan() {
return Scan.newBuilder()
.namespace(ANY_NAMESPACE_NAME)
.table(ANY_TABLE_NAME)
Expand Down Expand Up @@ -440,10 +440,10 @@ public void scan_CalledAfterDeleteUnderRealSnapshot_ShouldReturnResultsWithoutDe

@Test
public void
scan_RelationalScanAndResultFromStorageGiven_ShouldUpdateSnapshotAndValidateThenReturn()
scan_CrossPartitionScanndResultFromStorageGiven_ShouldUpdateSnapshotAndValidateThenReturn()
throws ExecutionException, CrudException {
// Arrange
Scan scan = prepareRelationalScan();
Scan scan = prepareCrossPartitionScan();
result = prepareResult(TransactionState.COMMITTED);
Snapshot.Key key = new Snapshot.Key(scan, result);
when(snapshot.get(key)).thenReturn(Optional.of((TransactionResult) result));
Expand All @@ -467,10 +467,10 @@ public void scan_CalledAfterDeleteUnderRealSnapshot_ShouldReturnResultsWithoutDe

@Test
public void
scan_RelationalScanAndPreparedResultFromStorageGiven_ShouldNeverUpdateSnapshotNorValidateButThrowUncommittedRecordException()
scan_CrossPartitionScanAndPreparedResultFromStorageGiven_ShouldNeverUpdateSnapshotNorValidateButThrowUncommittedRecordException()
throws ExecutionException {
// Arrange
Scan scan = prepareRelationalScan();
Scan scan = prepareCrossPartitionScan();
result = prepareResult(TransactionState.PREPARED);
when(scanner.iterator()).thenReturn(Collections.singletonList(result).iterator());
when(storage.scan(any(ScanAll.class))).thenReturn(scanner);
Expand Down
Loading

0 comments on commit 87a9d92

Please sign in to comment.