From 93ce2fa393983b6da97ad185afe46d015d90e87b Mon Sep 17 00:00:00 2001 From: Vincent Guilpain Date: Tue, 5 Nov 2024 22:15:55 +0900 Subject: [PATCH 1/4] Add time-related types to the Admin and Schema loader (#2301) --- .../CassandraAdminIntegrationTest.java | 5 + .../CassandraAdminRepairIntegrationTest.java | 5 + .../CassandraSchemaLoaderIntegrationTest.java | 5 + ...mmitAdminIntegrationTestWithCassandra.java | 5 + ...minRepairIntegrationTestWithCassandra.java | 5 + ...tionAdminIntegrationTestWithCassandra.java | 5 + ...tAdminRepairIntegrationTestWithCosmos.java | 2 +- .../CosmosAdminRepairIntegrationTest.java | 2 +- ...tipleClusteringKeyScanIntegrationTest.java | 4 +- ...ingleClusteringKeyScanIntegrationTest.java | 2 +- ...tipleClusteringKeyScanIntegrationTest.java | 4 +- ...moMultiplePartitionKeyIntegrationTest.java | 4 +- .../DynamoSecondaryIndexIntegrationTest.java | 2 +- ...ingleClusteringKeyScanIntegrationTest.java | 2 +- ...ltiStorageSchemaLoaderIntegrationTest.java | 5 + .../main/java/com/scalar/db/io/DataType.java | 15 ++- .../db/storage/cassandra/CassandraAdmin.java | 22 ++++ .../scalar/db/storage/cosmos/CosmosAdmin.java | 8 ++ .../scalar/db/storage/dynamo/DynamoAdmin.java | 12 ++ .../db/storage/jdbc/RdbEngineMysql.java | 7 ++ .../db/storage/jdbc/RdbEngineOracle.java | 7 ++ .../db/storage/jdbc/RdbEnginePostgresql.java | 8 ++ .../db/storage/jdbc/RdbEngineSqlServer.java | 8 ++ .../db/storage/jdbc/RdbEngineSqlite.java | 4 + .../storage/cassandra/CassandraAdminTest.java | 22 +++- .../db/storage/cosmos/CosmosAdminTest.java | 49 +++++++- .../storage/dynamo/DynamoAdminTestBase.java | 16 +++ .../scalar/db/storage/jdbc/JdbcAdminTest.java | 90 +++++++++++---- ...ibutedStorageAdminIntegrationTestBase.java | 95 +++++++++++++-- ...StorageAdminRepairIntegrationTestBase.java | 82 ++++++++----- ...onditionalMutationIntegrationTestBase.java | 2 +- ...CrossPartitionScanIntegrationTestBase.java | 4 +- ...eClusteringKeyScanIntegrationTestBase.java | 4 +- ...ltiplePartitionKeyIntegrationTestBase.java | 4 +- ...rageSecondaryIndexIntegrationTestBase.java | 2 +- ...eClusteringKeyScanIntegrationTestBase.java | 2 +- ...SinglePartitionKeyIntegrationTestBase.java | 2 +- ...edTransactionAdminIntegrationTestBase.java | 93 +++++++++++++-- ...sactionAdminRepairIntegrationTestBase.java | 82 ++++++++----- .../SchemaLoaderIntegrationTestBase.java | 109 +++++++++++------- .../scalar/db/schemaloader/TableSchema.java | 4 + .../db/schemaloader/TableSchemaTest.java | 16 ++- 42 files changed, 649 insertions(+), 177 deletions(-) diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java index f271bd47c2..119b2ca2a3 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java @@ -21,4 +21,9 @@ protected Map getCreationOptions() { protected AdminTestUtils getAdminTestUtils(String testName) { return new CassandraAdminTestUtils(getProperties(testName)); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java index 99514b2b1c..5246591bb9 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java @@ -28,4 +28,9 @@ protected void initialize(String testName) { admin = new CassandraAdmin(clusterManager, new DatabaseConfig(properties)); adminTestUtils = new CassandraAdminTestUtils(properties, clusterManager); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java index 2b3a76c0a7..29315b5e81 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java @@ -54,4 +54,9 @@ protected List getCommandArgsForUpgrade(Path configFilePath) { .add("--replication-factor=1") .build(); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java index 25b02a4636..b0eb1c4bab 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java @@ -22,4 +22,9 @@ protected Map getCreationOptions() { protected AdminTestUtils getAdminTestUtils(String testName) { return new CassandraAdminTestUtils(getProperties(testName)); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java index 6ac91b5b4c..5a7ad0e31d 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java @@ -30,4 +30,9 @@ protected void initialize(String testName) { admin = new ConsensusCommitAdmin(storageAdmin, new DatabaseConfig(properties)); adminTestUtils = new CassandraAdminTestUtils(getProperties(testName), clusterManager); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java index aa46a16da0..4669045a58 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java @@ -17,4 +17,9 @@ protected Properties getProps(String testName) { protected Map getCreationOptions() { return Collections.singletonMap(CassandraAdmin.REPLICATION_FACTOR, "1"); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java index 4831239269..11d722ee33 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java @@ -35,7 +35,7 @@ public void repairTable_ForTableWithoutStoredProcedure_ShouldCreateStoredProcedu cosmosAdminTestUtils.getTableStoredProcedure(getNamespace(), getTable()).delete(); // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThatCode( diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java index 039f934aa2..fc1426f2ee 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java @@ -35,7 +35,7 @@ public void repairTable_ForTableWithoutStoredProcedure_ShouldCreateStoredProcedu cosmosAdminTestUtils.getTableStoredProcedure(getNamespace(), getTable()).delete(); // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThatCode( diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java index ad97f1a7c3..52465ad6a7 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java @@ -19,11 +19,11 @@ protected Properties getProperties(String testName) { protected ListMultimap getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.values()) { + for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { if (firstClusteringKeyType == DataType.BLOB) { continue; } - for (DataType secondClusteringKeyType : DataType.values()) { + for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { if (secondClusteringKeyType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java index c3e77f4c1a..17e6a6cc43 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java @@ -18,7 +18,7 @@ protected Properties getProperties(String testName) { protected Set getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now Set clusteringKeyTypes = new HashSet<>(); - for (DataType dataType : DataType.values()) { + for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { if (dataType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java index 03ed09eab0..710acfa6de 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java @@ -21,11 +21,11 @@ protected Properties getProperties(String testName) { protected ListMultimap getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.values()) { + for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { if (firstClusteringKeyType == DataType.BLOB) { continue; } - for (DataType secondClusteringKeyType : DataType.values()) { + for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { if (secondClusteringKeyType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java index d0e747c70f..3972535e01 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java @@ -24,12 +24,12 @@ protected Map getCreationOptions() { @Override protected ListMultimap getPartitionKeyTypes() { ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.values()) { + for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { // BLOB type is supported only for the last value in partition key if (firstClusteringKeyType == DataType.BLOB) { continue; } - for (DataType secondClusteringKeyType : DataType.values()) { + for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { clusteringKeyTypes.put(firstClusteringKeyType, secondClusteringKeyType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java index a9e509e048..d57e1ee390 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java @@ -21,7 +21,7 @@ protected Properties getProperties(String testName) { protected Set getSecondaryIndexTypes() { // Return types without BOOLEAN because boolean is not supported for secondary index for now Set clusteringKeyTypes = new HashSet<>(); - for (DataType dataType : DataType.values()) { + for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { if (dataType == DataType.BOOLEAN) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java index 429fa917d4..d1c7c60b72 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java @@ -21,7 +21,7 @@ protected Properties getProperties(String testName) { protected Set getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now Set clusteringKeyTypes = new HashSet<>(); - for (DataType dataType : DataType.values()) { + for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { if (dataType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java index 0fa2ab2293..6d9ccc111e 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java @@ -110,4 +110,9 @@ protected void waitForCreationIfNecessary() { // one session to the other, so we need to wait Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS); } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } } diff --git a/core/src/main/java/com/scalar/db/io/DataType.java b/core/src/main/java/com/scalar/db/io/DataType.java index 12d345efbf..a4d601d629 100644 --- a/core/src/main/java/com/scalar/db/io/DataType.java +++ b/core/src/main/java/com/scalar/db/io/DataType.java @@ -1,5 +1,7 @@ package com.scalar.db.io; +import java.util.Arrays; + public enum DataType { BOOLEAN, INT, @@ -7,5 +9,16 @@ public enum DataType { FLOAT, DOUBLE, TEXT, - BLOB + BLOB, + DATE, + TIME, + TIMESTAMP, + TIMESTAMPTZ; + + // Temporary added until the CRUD operations for time-related types is completed + public static DataType[] valuesWithoutTimesRelatedTypes() { + return Arrays.stream(values()) + .filter(type -> type != DATE && type != TIME && type != TIMESTAMP && type != TIMESTAMPTZ) + .toArray(DataType[]::new); + } } diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java b/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java index 94272f18f2..26ac81f940 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java @@ -65,6 +65,12 @@ public CassandraAdmin(DatabaseConfig config) { public void createTable( String namespace, String table, TableMetadata metadata, Map options) throws ExecutionException { + for (String column : metadata.getColumnNames()) { + if (metadata.getColumnDataTypes().get(column).equals(DataType.TIMESTAMP)) { + throw new UnsupportedOperationException( + "The TIMESTAMP data type is not supported in Cassandra. column: " + column); + } + } try { createNamespacesTableIfNotExists(); createTableInternal(namespace, table, metadata, false, options); @@ -370,6 +376,10 @@ public void repairTable( public void addNewColumnToTable( String namespace, String table, String columnName, DataType columnType) throws ExecutionException { + if (columnType == DataType.TIMESTAMP) { + throw new UnsupportedOperationException( + "The TIMESTAMP data type is not supported in Cassandra. column: " + columnName); + } try { String alterTableQuery = SchemaBuilder.alterTable(namespace, table) @@ -583,6 +593,12 @@ private DataType fromCassandraDataType( return DataType.BOOLEAN; case BLOB: return DataType.BLOB; + case DATE: + return DataType.DATE; + case TIME: + return DataType.TIME; + case TIMESTAMP: + return DataType.TIMESTAMPTZ; default: throw new ExecutionException( String.format("%s is not yet supported", cassandraDataTypeName)); @@ -610,6 +626,12 @@ private com.datastax.driver.core.DataType toCassandraDataType(DataType dataType) return com.datastax.driver.core.DataType.text(); case BLOB: return com.datastax.driver.core.DataType.blob(); + case DATE: + return com.datastax.driver.core.DataType.date(); + case TIME: + return com.datastax.driver.core.DataType.time(); + case TIMESTAMPTZ: + return com.datastax.driver.core.DataType.timestamp(); default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java index 8382abe010..5f1962677d 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java @@ -518,6 +518,14 @@ private DataType convertDataType(String columnType) throws ExecutionException { return DataType.BOOLEAN; case "blob": return DataType.BLOB; + case "date": + return DataType.DATE; + case "time": + return DataType.TIME; + case "timestamp": + return DataType.TIMESTAMP; + case "timestamptz": + return DataType.TIMESTAMPTZ; default: throw new ExecutionException("Unknown column type: " + columnType); } diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java index b7d9b3d733..46c6dab220 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java @@ -127,6 +127,10 @@ public class DynamoAdmin implements DistributedStorageAdmin { .put(DataType.DOUBLE, ScalarAttributeType.N) .put(DataType.TEXT, ScalarAttributeType.S) .put(DataType.BLOB, ScalarAttributeType.B) + .put(DataType.DATE, ScalarAttributeType.S) + .put(DataType.TIME, ScalarAttributeType.S) + .put(DataType.TIMESTAMP, ScalarAttributeType.S) + .put(DataType.TIMESTAMPTZ, ScalarAttributeType.S) .build(); private static final ImmutableSet TABLE_SCALING_TYPE_SET = ImmutableSet.builder().add(SCALING_TYPE_READ).add(SCALING_TYPE_WRITE).build(); @@ -1245,6 +1249,14 @@ private DataType convertDataType(String columnType) throws ExecutionException { return DataType.BOOLEAN; case "blob": return DataType.BLOB; + case "date": + return DataType.DATE; + case "time": + return DataType.TIME; + case "timestamp": + return DataType.TIMESTAMP; + case "timestamptz": + return DataType.TIMESTAMPTZ; default: throw new ExecutionException("Unknown column type: " + columnType); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java index 643baebcf0..888b0a9bf9 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java @@ -203,6 +203,13 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "INT"; case TEXT: return "LONGTEXT"; + case DATE: + return "DATE"; + case TIME: + return "TIME"; + case TIMESTAMP: + case TIMESTAMPTZ: + return "DATETIME"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java index 4cba5d5b3b..2406400e26 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java @@ -210,6 +210,13 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "NUMBER(10)"; case TEXT: return "VARCHAR2(4000)"; + case DATE: + return "DATE"; + case TIME: + case TIMESTAMP: + return "TIMESTAMP"; + case TIMESTAMPTZ: + return "TIMESTAMP WITH TIME ZONE"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java index c6020713d3..4d49370506 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java @@ -197,6 +197,14 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "INT"; case TEXT: return "TEXT"; + case DATE: + return "DATE"; + case TIME: + return "TIME"; + case TIMESTAMP: + return "TIMESTAMP"; + case TIMESTAMPTZ: + return "TIMESTAMP WITH TIME ZONE"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java index b6d92a1055..0f6930d6b3 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java @@ -177,6 +177,14 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "INT"; case TEXT: return "VARCHAR(8000)"; + case DATE: + return "DATE"; + case TIME: + return "TIME"; + case TIMESTAMP: + return "DATETIME2"; + case TIMESTAMPTZ: + return "DATETIMEOFFSET"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java index dce69fd267..746791feb3 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java @@ -92,6 +92,10 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { case DOUBLE: return "DOUBLE"; case TEXT: + case DATE: + case TIME: + case TIMESTAMP: + case TIMESTAMPTZ: return "TEXT"; case BLOB: return "BLOB"; diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java index bfb0da5d87..987a216842 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java @@ -247,8 +247,13 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addColumn("c1", DataType.INT) .addColumn("c2", DataType.TEXT) .addColumn("c3", DataType.BLOB) - .addColumn("c4", DataType.INT) + .addColumn("c4", DataType.BIGINT) .addColumn("c5", DataType.BOOLEAN) + .addColumn("c6", DataType.DOUBLE) + .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMPTZ) .addSecondaryIndex("c2") .addSecondaryIndex("c4") .build(); @@ -260,10 +265,15 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { TableOptions createTableStatement = SchemaBuilder.createTable(namespace, table) .addPartitionKey("c1", com.datastax.driver.core.DataType.cint()) - .addClusteringColumn("c4", com.datastax.driver.core.DataType.cint()) + .addClusteringColumn("c4", com.datastax.driver.core.DataType.bigint()) .addColumn("c2", com.datastax.driver.core.DataType.text()) .addColumn("c3", com.datastax.driver.core.DataType.blob()) .addColumn("c5", com.datastax.driver.core.DataType.cboolean()) + .addColumn("c6", com.datastax.driver.core.DataType.cdouble()) + .addColumn("c7", com.datastax.driver.core.DataType.cfloat()) + .addColumn("c8", com.datastax.driver.core.DataType.date()) + .addColumn("c9", com.datastax.driver.core.DataType.time()) + .addColumn("c10", com.datastax.driver.core.DataType.timestamp()) .withOptions() .clusteringOrder("c4", Direction.ASC) .compactionOptions(SchemaBuilder.sizedTieredStategy()); @@ -283,6 +293,7 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addPartitionKey("c7") .addClusteringKey("c4") .addClusteringKey("c6", Order.DESC) + .addClusteringKey("c9", Order.ASC) .addColumn("c1", DataType.INT) .addColumn("c2", DataType.TEXT) .addColumn("c3", DataType.BLOB) @@ -290,6 +301,9 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addColumn("c5", DataType.BIGINT) .addColumn("c6", DataType.BOOLEAN) .addColumn("c7", DataType.TEXT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMPTZ) .addSecondaryIndex("c2") .addSecondaryIndex("c4") .build(); @@ -306,12 +320,16 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addPartitionKey("c7", com.datastax.driver.core.DataType.text()) .addClusteringColumn("c4", com.datastax.driver.core.DataType.cdouble()) .addClusteringColumn("c6", com.datastax.driver.core.DataType.cboolean()) + .addClusteringColumn("c9", com.datastax.driver.core.DataType.time()) .addColumn("c2", com.datastax.driver.core.DataType.text()) .addColumn("c3", com.datastax.driver.core.DataType.blob()) .addColumn("c5", com.datastax.driver.core.DataType.bigint()) + .addColumn("c8", com.datastax.driver.core.DataType.date()) + .addColumn("c10", com.datastax.driver.core.DataType.timestamp()) .withOptions() .clusteringOrder("c4", Direction.ASC) .clusteringOrder("c6", Direction.DESC) + .clusteringOrder("c9", Direction.ASC) .compactionOptions(SchemaBuilder.leveledStrategy()); verify(cassandraSession).execute(createTableStatement.getQueryString()); } diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java index e9a84509b4..9dc24dac5a 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java @@ -41,6 +41,7 @@ import com.scalar.db.io.DataType; import java.util.Collections; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.function.Consumer; import java.util.stream.Stream; @@ -92,11 +93,27 @@ public void getTableMetadata_ShouldReturnCorrectTableMetadata() throws Execution any(PartitionKey.class), ArgumentMatchers.>any())) .thenReturn(response); - + Map columnsMap = + new ImmutableMap.Builder() + .put("c1", "int") + .put("c2", "text") + .put("c3", "bigint") + .put("c4", "boolean") + .put("c5", "blob") + .put("c6", "float") + .put("c7", "double") + .put("c8", "date") + .put("c9", "time") + .put("c10", "timestamp") + .put("c11", "timestamptz") + .build(); CosmosTableMetadata cosmosTableMetadata = CosmosTableMetadata.newBuilder() .partitionKeyNames(Sets.newLinkedHashSet("c1")) - .columns(ImmutableMap.of("c1", "int", "c2", "text", "c3", "bigint")) + .clusteringKeyNames(Sets.newLinkedHashSet("c2", "c3")) + .clusteringOrders(ImmutableMap.of("c2", "ASC", "c3", "DESC")) + .secondaryIndexNames(ImmutableSet.of("c4", "c9")) + .columns(columnsMap) .build(); when(response.getItem()).thenReturn(cosmosTableMetadata); @@ -108,10 +125,22 @@ public void getTableMetadata_ShouldReturnCorrectTableMetadata() throws Execution assertThat(actual) .isEqualTo( TableMetadata.newBuilder() + .addPartitionKey("c1") + .addClusteringKey("c2", Order.ASC) + .addClusteringKey("c3", Order.DESC) + .addSecondaryIndex("c4") + .addSecondaryIndex("c9") .addColumn("c1", DataType.INT) .addColumn("c2", DataType.TEXT) .addColumn("c3", DataType.BIGINT) - .addPartitionKey("c1") + .addColumn("c4", DataType.BOOLEAN) + .addColumn("c5", DataType.BLOB) + .addColumn("c6", DataType.FLOAT) + .addColumn("c7", DataType.DOUBLE) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .build()); verify(client).getDatabase(METADATA_DATABASE); @@ -242,6 +271,10 @@ public void createTable_ShouldCreateContainer() throws ExecutionException { .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -318,6 +351,10 @@ public void createTable_ShouldCreateContainer() throws ExecutionException { .put("c5", "int") .put("c6", "double") .put("c7", "float") + .put("c8", "date") + .put("c9", "time") + .put("c10", "timestamp") + .put("c11", "timestamptz") .build()) .secondaryIndexNames(ImmutableSet.of("c4")) .build(); @@ -340,6 +377,9 @@ public void createTable_WithoutClusteringKeys_ShouldCreateContainerWithComposite .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -404,6 +444,9 @@ public void createTable_WithoutClusteringKeys_ShouldCreateContainerWithComposite .put("c5", "int") .put("c6", "double") .put("c7", "float") + .put("c8", "date") + .put("c9", "time") + .put("c10", "timestamptz") .build()) .build(); verify(metadataContainer).upsertItem(cosmosTableMetadata); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java index 86f78558a1..7e17c4d8d8 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java @@ -314,6 +314,10 @@ public void createTable_WhenMetadataTableNotExist_ShouldCreateTableAndMetadataTa .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -453,6 +457,10 @@ public void createTable_WhenMetadataTableNotExist_ShouldCreateTableAndMetadataTa columns.put("c5", AttributeValue.builder().s("int").build()); columns.put("c6", AttributeValue.builder().s("double").build()); columns.put("c7", AttributeValue.builder().s("float").build()); + columns.put("c8", AttributeValue.builder().s("date").build()); + columns.put("c9", AttributeValue.builder().s("time").build()); + columns.put("c10", AttributeValue.builder().s("timestamp").build()); + columns.put("c11", AttributeValue.builder().s("timestamptz").build()); itemValues.put(DynamoAdmin.METADATA_ATTR_COLUMNS, AttributeValue.builder().m(columns).build()); itemValues.put( DynamoAdmin.METADATA_ATTR_PARTITION_KEY, @@ -505,6 +513,10 @@ public void createTable_WhenMetadataTableExists_ShouldCreateOnlyTable() .addColumn("c5", DataType.BLOB) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -606,6 +618,10 @@ public void createTable_WhenMetadataTableExists_ShouldCreateOnlyTable() columns.put("c5", AttributeValue.builder().s("blob").build()); columns.put("c6", AttributeValue.builder().s("double").build()); columns.put("c7", AttributeValue.builder().s("float").build()); + columns.put("c8", AttributeValue.builder().s("date").build()); + columns.put("c9", AttributeValue.builder().s("time").build()); + columns.put("c10", AttributeValue.builder().s("timestamp").build()); + columns.put("c11", AttributeValue.builder().s("timestamptz").build()); itemValues.put(DynamoAdmin.METADATA_ATTR_COLUMNS, AttributeValue.builder().m(columns).build()); itemValues.put( DynamoAdmin.METADATA_ATTR_PARTITION_KEY, diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java index 1a89820777..87d591076f 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java @@ -211,7 +211,15 @@ private void getTableMetadata_forX_ShouldReturnTableMetadata( new SelectAllFromMetadataTableResultSetMocker.Row( "c6", DataType.DOUBLE.toString(), null, null, false), new SelectAllFromMetadataTableResultSetMocker.Row( - "c7", DataType.FLOAT.toString(), null, null, false)); + "c7", DataType.FLOAT.toString(), null, null, false), + new SelectAllFromMetadataTableResultSetMocker.Row( + "c8", DataType.DATE.toString(), null, null, false), + new SelectAllFromMetadataTableResultSetMocker.Row( + "c9", DataType.TIME.toString(), null, null, false), + new SelectAllFromMetadataTableResultSetMocker.Row( + "c10", DataType.TIMESTAMP.toString(), null, null, false), + new SelectAllFromMetadataTableResultSetMocker.Row( + "c11", DataType.TIMESTAMPTZ.toString(), null, null, false)); when(selectStatement.executeQuery()).thenReturn(resultSet); when(connection.prepareStatement(any())).thenReturn(selectStatement); when(dataSource.getConnection()).thenReturn(connection); @@ -234,6 +242,10 @@ private void getTableMetadata_forX_ShouldReturnTableMetadata( .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); assertThat(actualMetadata).isEqualTo(expectedMetadata); @@ -466,7 +478,7 @@ public void createTableInternal_ForSqlite_withInvalidTableName_ShouldThrowExecut public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.MYSQL, - "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", + "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL,`c8` DATE,`c9` TIME,`c10` DATETIME,`c11` DATETIME, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", "CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)", "CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)"); } @@ -478,7 +490,7 @@ public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes() throws SQ when(config.getMysqlVariableKeyColumnSize()).thenReturn(64); createTableInternal_ForX_CreateTableAndIndexes( new RdbEngineMysql(config), - "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", + "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL,`c8` DATE,`c9` TIME,`c10` DATETIME,`c11` DATETIME, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", "CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)", "CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)"); } @@ -487,7 +499,7 @@ public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes() throws SQ public void createTableInternal_ForPostgresql_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.POSTGRESQL, - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL,\"c8\" DATE,\"c9\" TIME,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", "CREATE INDEX \"index_my_ns_foo_table_c1\" ON \"my_ns\".\"foo_table\" (\"c1\")"); @@ -497,8 +509,7 @@ public void createTableInternal_ForPostgresql_ShouldCreateTableAndIndexes() thro public void createTableInternal_ForSqlServer_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.SQL_SERVER, - "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000)," - + "[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", + "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000),[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24),[c8] DATE,[c9] TIME,[c10] DATETIME2,[c11] DATETIMEOFFSET, PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", "CREATE INDEX [index_my_ns_foo_table_c4] ON [my_ns].[foo_table] ([c4])", "CREATE INDEX [index_my_ns_foo_table_c1] ON [my_ns].[foo_table] ([c1])"); } @@ -507,7 +518,7 @@ public void createTableInternal_ForSqlServer_ShouldCreateTableAndIndexes() throw public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.ORACLE, - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT,\"c8\" DATE,\"c9\" TIMESTAMP,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", "ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", @@ -521,7 +532,7 @@ public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes() throws S when(config.getOracleVariableKeyColumnSize()).thenReturn(64); createTableInternal_ForX_CreateTableAndIndexes( new RdbEngineOracle(config), - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT,\"c8\" DATE,\"c9\" TIMESTAMP,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", "ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", @@ -532,7 +543,7 @@ public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes() throws S public void createTableInternal_ForSqlite_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.SQLITE, - "CREATE TABLE \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT,\"c8\" TEXT,\"c9\" TEXT,\"c10\" TEXT,\"c11\" TEXT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns$foo_table\" (\"c4\")", "CREATE INDEX \"index_my_ns_foo_table_c1\" ON \"my_ns$foo_table\" (\"c1\")"); } @@ -560,6 +571,10 @@ private void createTableInternal_ForX_CreateTableAndIndexes( .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -590,7 +605,7 @@ public void createTableInternal_IfNotExistsForMysql_ShouldCreateTableAndIndexesI throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.MYSQL, - "CREATE TABLE IF NOT EXISTS `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", + "CREATE TABLE IF NOT EXISTS `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL,`c8` DATE,`c9` TIME,`c10` DATETIME,`c11` DATETIME, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", "CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)", "CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)"); } @@ -600,7 +615,7 @@ public void createTableInternal_IfNotExistsForPostgresql_ShouldCreateTableAndInd throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.POSTGRESQL, - "CREATE TABLE IF NOT EXISTS \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE IF NOT EXISTS \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL,\"c8\" DATE,\"c9\" TIME,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE UNIQUE INDEX IF NOT EXISTS \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c1\" ON \"my_ns\".\"foo_table\" (\"c1\")"); @@ -611,8 +626,7 @@ public void createTableInternal_IfNotExistsForSqlServer_ShouldCreateTableAndInde throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.SQL_SERVER, - "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000)," - + "[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", + "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000),[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24),[c8] DATE,[c9] TIME,[c10] DATETIME2,[c11] DATETIMEOFFSET, PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", "CREATE INDEX [index_my_ns_foo_table_c4] ON [my_ns].[foo_table] ([c4])", "CREATE INDEX [index_my_ns_foo_table_c1] ON [my_ns].[foo_table] ([c1])"); } @@ -622,7 +636,7 @@ public void createTableInternal_IfNotExistsForOracle_ShouldCreateTableAndIndexes throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.ORACLE, - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT,\"c8\" DATE,\"c9\" TIMESTAMP,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", "ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", @@ -634,7 +648,7 @@ public void createTableInternal_IfNotExistsForSqlite_ShouldCreateTableAndIndexes throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.SQLITE, - "CREATE TABLE IF NOT EXISTS \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE IF NOT EXISTS \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT,\"c8\" TEXT,\"c9\" TEXT,\"c10\" TEXT,\"c11\" TEXT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c4\" ON \"my_ns$foo_table\" (\"c4\")", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c1\" ON \"my_ns$foo_table\" (\"c1\")"); } @@ -663,6 +677,10 @@ private void createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExist .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -1000,7 +1018,11 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForMysql_Should + "`.`metadata` VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,false,6)", "INSERT INTO `" + METADATA_SCHEMA - + "`.`metadata` VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)"); + + "`.`metadata` VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)", + "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,false,8)", + "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,false,9)", + "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,false,10)", + "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,false,11)"); } @Test @@ -1041,7 +1063,11 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForMysql_Should + "\".\"metadata\" VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,false,6)", "INSERT INTO \"" + METADATA_SCHEMA - + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)"); + + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,false,8)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,false,9)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,false,10)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,false,11)"); } @Test @@ -1081,7 +1107,11 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForSqlServer_Sh + "].[metadata] VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,0,6)", "INSERT INTO [" + METADATA_SCHEMA - + "].[metadata] VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)"); + + "].[metadata] VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)", + "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,0,8)", + "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,0,9)", + "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,0,10)", + "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,0,11)"); } @Test @@ -1114,7 +1144,11 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForOracle_Shoul + "\".\"metadata\" VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,0,6)", "INSERT INTO \"" + METADATA_SCHEMA - + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)"); + + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,0,8)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,0,9)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,0,10)", + "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,0,11)"); } @Test @@ -1153,7 +1187,11 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForSqlite_Shoul + "$metadata\" VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,FALSE,6)", "INSERT INTO \"" + METADATA_SCHEMA - + "$metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,FALSE,7)"); + + "$metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,FALSE,7)", + "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,FALSE,8)", + "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,FALSE,9)", + "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,FALSE,10)", + "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,FALSE,11)"); } private void addTableMetadata_createMetadataTableIfNotExistsForX_ShouldWorkProperly( @@ -1173,6 +1211,10 @@ private void addTableMetadata_createMetadataTableIfNotExistsForX_ShouldWorkPrope .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -1217,6 +1259,10 @@ public void createTable_ShouldCallCreateTableAndAddTableMetadataCorrectly(RdbEng .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -1252,6 +1298,10 @@ public void repairTable_ShouldCallCreateTableAndAddTableMetadataCorrectly(RdbEng .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) + .addColumn("c8", DataType.DATE) + .addColumn("c9", DataType.TIME) + .addColumn("c10", DataType.TIMESTAMP) + .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java index 705c78e0ad..b56399ac57 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java @@ -50,6 +50,10 @@ public abstract class DistributedStorageAdminIntegrationTestBase { private static final String COL_NAME9 = "c9"; private static final String COL_NAME10 = "c10"; private static final String COL_NAME11 = "c11"; + private static final String COL_NAME12 = "c12"; + private static final String COL_NAME13 = "c13"; + private static final String COL_NAME14 = "c14"; + private static final String COL_NAME15 = "c15"; private static final TableMetadata TABLE_METADATA = TableMetadata.newBuilder() @@ -64,6 +68,9 @@ public abstract class DistributedStorageAdminIntegrationTestBase { .addColumn(COL_NAME9, DataType.DOUBLE) .addColumn(COL_NAME10, DataType.BOOLEAN) .addColumn(COL_NAME11, DataType.BLOB) + .addColumn(COL_NAME12, DataType.DATE) + .addColumn(COL_NAME13, DataType.TIME) + .addColumn(COL_NAME14, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME2) .addPartitionKey(COL_NAME1) .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) @@ -153,6 +160,9 @@ private void dropTables() throws ExecutionException { public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() throws ExecutionException { // Arrange + if (isTimestampTypeSupported()) { + admin.addNewColumnToTable(namespace1, TABLE1, COL_NAME15, DataType.TIMESTAMP); + } // Act TableMetadata tableMetadata = admin.getTableMetadata(namespace1, TABLE1); @@ -170,7 +180,12 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(iterator.next()).isEqualTo(COL_NAME4); assertThat(iterator.next()).isEqualTo(COL_NAME3); - assertThat(tableMetadata.getColumnNames().size()).isEqualTo(11); + if (isTimestampTypeSupported()) { + assertThat(tableMetadata.getColumnNames().size()).isEqualTo(15); + } else { + assertThat(tableMetadata.getColumnNames().size()).isEqualTo(14); + } + assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue(); @@ -182,6 +197,12 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnNames().contains(COL_NAME9)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME10)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME11)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(COL_NAME12)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(COL_NAME13)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(COL_NAME14)).isTrue(); + if (isTimestampTypeSupported()) { + assertThat(tableMetadata.getColumnNames().contains(COL_NAME15)).isTrue(); + } assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT); assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT); @@ -194,6 +215,12 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnDataType(COL_NAME9)).isEqualTo(DataType.DOUBLE); assertThat(tableMetadata.getColumnDataType(COL_NAME10)).isEqualTo(DataType.BOOLEAN); assertThat(tableMetadata.getColumnDataType(COL_NAME11)).isEqualTo(DataType.BLOB); + assertThat(tableMetadata.getColumnDataType(COL_NAME12)).isEqualTo(DataType.DATE); + assertThat(tableMetadata.getColumnDataType(COL_NAME13)).isEqualTo(DataType.TIME); + assertThat(tableMetadata.getColumnDataType(COL_NAME14)).isEqualTo(DataType.TIMESTAMPTZ); + if (isTimestampTypeSupported()) { + assertThat(tableMetadata.getColumnDataType(COL_NAME15)).isEqualTo(DataType.TIMESTAMP); + } assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull(); @@ -206,6 +233,10 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getClusteringOrder(COL_NAME9)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME10)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME11)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME12)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME13)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME14)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME15)).isNull(); assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue(); @@ -472,7 +503,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre try { // Arrange Map options = getCreationOptions(); - TableMetadata metadata = + TableMetadata.Builder metadataBuilder = TableMetadata.newBuilder() .addColumn(COL_NAME1, DataType.INT) .addColumn(COL_NAME2, DataType.INT) @@ -483,9 +514,15 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .addColumn(COL_NAME7, DataType.BOOLEAN) .addColumn(COL_NAME8, DataType.BLOB) .addColumn(COL_NAME9, DataType.TEXT) + .addColumn(COL_NAME10, DataType.DATE) + .addColumn(COL_NAME11, DataType.TIME) + .addColumn(COL_NAME12, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME9) - .build(); + .addSecondaryIndex(COL_NAME9); + if (isTimestampTypeSupported()) { + metadataBuilder = metadataBuilder.addColumn(COL_NAME13, DataType.TIMESTAMP); + } + TableMetadata metadata = metadataBuilder.build(); admin.createTable(namespace1, TABLE4, metadata, options); storage = storageFactory.getStorage(); storage.put( @@ -501,6 +538,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") + // TODO add put values for data, time, timestamp and timestamptz .build()); // Act admin.createIndex(namespace1, TABLE4, COL_NAME2, options); @@ -512,6 +550,12 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre admin.createIndex(namespace1, TABLE4, COL_NAME7, options); } admin.createIndex(namespace1, TABLE4, COL_NAME8, options); + admin.createIndex(namespace1, TABLE4, COL_NAME10, options); + admin.createIndex(namespace1, TABLE4, COL_NAME11, options); + admin.createIndex(namespace1, TABLE4, COL_NAME12, options); + if (isTimestampTypeSupported()) { + admin.createIndex(namespace1, TABLE4, COL_NAME13, options); + } // Assert assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).isTrue(); @@ -523,16 +567,39 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME7)).isTrue(); } assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME9)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME10)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME11)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME12)).isTrue(); + if (isTimestampTypeSupported()) { + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME13)).isTrue(); + } + + Set actualSecondaryIndexNames = + admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames(); + assertThat(actualSecondaryIndexNames) + .contains( + COL_NAME2, + COL_NAME3, + COL_NAME4, + COL_NAME5, + COL_NAME6, + COL_NAME8, + COL_NAME9, + COL_NAME10, + COL_NAME11, + COL_NAME12); + int indexCount = 10; if (isIndexOnBooleanColumnSupported()) { - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) - .containsOnly( - COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7, COL_NAME8, - COL_NAME9); - } else { - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) - .containsOnly( - COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME8, COL_NAME9); + assertThat(actualSecondaryIndexNames).contains(COL_NAME7); + indexCount++; + } + if (isTimestampTypeSupported()) { + assertThat(actualSecondaryIndexNames).contains(COL_NAME13); + indexCount++; } + assertThat(actualSecondaryIndexNames).hasSize(indexCount); + } finally { admin.dropTable(namespace1, TABLE4, true); if (storage != null) { @@ -810,4 +877,8 @@ public void addNewColumnToTable_ForAlreadyExistingColumn_ShouldThrowIllegalArgum protected boolean isIndexOnBooleanColumnSupported() { return true; } + + protected boolean isTimestampTypeSupported() { + return true; + } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java index c1d051aa29..f916896910 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java @@ -37,32 +37,46 @@ public abstract class DistributedStorageAdminRepairIntegrationTestBase { private static final String COL_NAME9 = "c9"; private static final String COL_NAME10 = "c10"; private static final String COL_NAME11 = "c11"; - - protected static final TableMetadata TABLE_METADATA = - TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.TEXT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.INT) - .addColumn(COL_NAME5, DataType.INT) - .addColumn(COL_NAME6, DataType.TEXT) - .addColumn(COL_NAME7, DataType.BIGINT) - .addColumn(COL_NAME8, DataType.FLOAT) - .addColumn(COL_NAME9, DataType.DOUBLE) - .addColumn(COL_NAME10, DataType.BOOLEAN) - .addColumn(COL_NAME11, DataType.BLOB) - .addPartitionKey(COL_NAME2) - .addPartitionKey(COL_NAME1) - .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) - .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) - .build(); + private static final String COL_NAME12 = "c12"; + private static final String COL_NAME13 = "c13"; + private static final String COL_NAME14 = "c14"; + private static final String COL_NAME15 = "c15"; protected DistributedStorageAdmin admin; protected AdminTestUtils adminTestUtils = null; + protected TableMetadata getTableMetadata() { + TableMetadata.Builder builder = + TableMetadata.newBuilder() + .addColumn(COL_NAME1, DataType.INT) + .addColumn(COL_NAME2, DataType.TEXT) + .addColumn(COL_NAME3, DataType.TEXT) + .addColumn(COL_NAME4, DataType.INT) + .addColumn(COL_NAME5, DataType.INT) + .addColumn(COL_NAME6, DataType.TEXT) + .addColumn(COL_NAME7, DataType.BIGINT) + .addColumn(COL_NAME8, DataType.FLOAT) + .addColumn(COL_NAME9, DataType.DOUBLE) + .addColumn(COL_NAME10, DataType.BOOLEAN) + .addColumn(COL_NAME11, DataType.BLOB) + .addColumn(COL_NAME12, DataType.DATE) + .addColumn(COL_NAME13, DataType.TIME) + .addColumn(COL_NAME14, DataType.TIMESTAMPTZ); + if (isTimestampTypeSupported()) { + builder.addColumn(COL_NAME15, DataType.TIMESTAMP); + } + builder + .addPartitionKey(COL_NAME2) + .addPartitionKey(COL_NAME1) + .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) + .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) + .addSecondaryIndex(COL_NAME5) + .addSecondaryIndex(COL_NAME6) + .build(); + return builder.build(); + } + @BeforeAll public void beforeAll() throws Exception { initialize(TEST_NAME); @@ -105,7 +119,7 @@ protected String getTable() { private void createTable() throws ExecutionException { Map options = getCreationOptions(); admin.createNamespace(getNamespace(), options); - admin.createTable(getNamespace(), getTable(), TABLE_METADATA, options); + admin.createTable(getNamespace(), getTable(), getTableMetadata(), options); } protected Map getCreationOptions() { @@ -135,11 +149,11 @@ protected void waitForDifferentSessionDdl() { @Test public void repairTable_ForExistingTableAndMetadata_ShouldDoNothing() throws Exception { // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); } @Test @@ -149,12 +163,12 @@ public void repairTable_ForDeletedMetadataTable_ShouldRepairProperly() throws Ex // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); } @Test @@ -163,11 +177,11 @@ public void repairTable_ForTruncatedMetadataTable_ShouldRepairProperly() throws adminTestUtils.truncateMetadataTable(); // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); } @Test @@ -176,11 +190,11 @@ public void repairTable_ForCorruptedMetadataTable_ShouldRepairProperly() throws adminTestUtils.corruptMetadata(getNamespace(), getTable()); // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); } @Test @@ -191,12 +205,12 @@ public void repairTable_ForNonExistingTableButExistingMetadata_ShouldCreateTable // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); } @Test @@ -272,4 +286,8 @@ public void repairNamespace_ForNonExistingNamespaceAndMetadata_ShouldCreateNames assertThat(adminTestUtils.namespaceExists(getNamespace())).isTrue(); assertThat(admin.namespaceExists(getNamespace())).isTrue(); } + + protected boolean isTimestampTypeSupported() { + return true; + } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java index 22d1c19c75..e71373399d 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java @@ -163,7 +163,7 @@ protected List getOperatorAndDataTypeListForTest() { List ret = new ArrayList<>(); for (Operator operator : Operator.values()) { if (operator != Operator.LIKE && operator != Operator.NOT_LIKE) { - for (DataType dataType : DataType.values()) { + for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { ret.add(new OperatorAndDataType(operator, dataType)); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java index 4f87fd58d4..58665ab71a 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java @@ -196,8 +196,8 @@ private String getTableName(DataType firstColumnType, DataType secondColumnType) private ListMultimap getColumnTypes() { ListMultimap columnTypes = ArrayListMultimap.create(); - for (DataType firstColumnType : DataType.values()) { - for (DataType secondColumnType : DataType.values()) { + for (DataType firstColumnType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType secondColumnType : DataType.valuesWithoutTimesRelatedTypes()) { columnTypes.put(firstColumnType, secondColumnType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java index dfc584347f..b6d054ec37 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java @@ -102,8 +102,8 @@ protected String getNamespaceBaseName() { protected ListMultimap getClusteringKeyTypes() { ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.values()) { - for (DataType secondClusteringKeyType : DataType.values()) { + for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { clusteringKeyTypes.put(firstClusteringKeyType, secondClusteringKeyType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java index dbb1370859..e34ae7e704 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java @@ -84,13 +84,13 @@ protected String getNamespaceBaseName() { protected ListMultimap getPartitionKeyTypes() { ListMultimap partitionKeyTypes = ArrayListMultimap.create(); - for (DataType firstPartitionKeyType : DataType.values()) { + for (DataType firstPartitionKeyType : DataType.valuesWithoutTimesRelatedTypes()) { if (!isFloatTypeKeySupported() && (firstPartitionKeyType == DataType.FLOAT || firstPartitionKeyType == DataType.DOUBLE)) { continue; } - for (DataType secondPartitionKeyType : DataType.values()) { + for (DataType secondPartitionKeyType : DataType.valuesWithoutTimesRelatedTypes()) { if (!isFloatTypeKeySupported() && (secondPartitionKeyType == DataType.FLOAT || secondPartitionKeyType == DataType.DOUBLE)) { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java index 128de74881..ea3235d20f 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java @@ -69,7 +69,7 @@ protected String getNamespace() { } protected Set getSecondaryIndexTypes() { - return new HashSet<>(Arrays.asList(DataType.values())); + return new HashSet<>(Arrays.asList(DataType.valuesWithoutTimesRelatedTypes())); } private void createTables() throws ExecutionException { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java index 89ce96a046..932b95f680 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java @@ -81,7 +81,7 @@ protected String getNamespace() { } protected Set getClusteringKeyTypes() { - return new HashSet<>(Arrays.asList(DataType.values())); + return new HashSet<>(Arrays.asList(DataType.valuesWithoutTimesRelatedTypes())); } private void createTables() throws ExecutionException { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java index e8b0f89c3a..b43e43afae 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java @@ -70,7 +70,7 @@ protected String getNamespace() { } protected Set getPartitionKeyTypes() { - return new HashSet<>(Arrays.asList(DataType.values())); + return new HashSet<>(Arrays.asList(DataType.valuesWithoutTimesRelatedTypes())); } protected boolean isFloatTypeKeySupported() { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java index 579205ceaa..c08fb95b9e 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java @@ -48,6 +48,10 @@ public abstract class DistributedTransactionAdminIntegrationTestBase { protected static final String COL_NAME9 = "c9"; protected static final String COL_NAME10 = "c10"; protected static final String COL_NAME11 = "c11"; + private static final String COL_NAME12 = "c12"; + private static final String COL_NAME13 = "c13"; + private static final String COL_NAME14 = "c14"; + private static final String COL_NAME15 = "c15"; protected static final TableMetadata TABLE_METADATA = TableMetadata.newBuilder() @@ -62,6 +66,9 @@ public abstract class DistributedTransactionAdminIntegrationTestBase { .addColumn(COL_NAME9, DataType.DOUBLE) .addColumn(COL_NAME10, DataType.BOOLEAN) .addColumn(COL_NAME11, DataType.BLOB) + .addColumn(COL_NAME12, DataType.DATE) + .addColumn(COL_NAME13, DataType.TIME) + .addColumn(COL_NAME14, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME2) .addPartitionKey(COL_NAME1) .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) @@ -148,6 +155,9 @@ private void dropTables() throws ExecutionException { public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() throws ExecutionException { // Arrange + if (isTimestampTypeSupported()) { + admin.addNewColumnToTable(namespace1, TABLE1, COL_NAME15, DataType.TIMESTAMP); + } // Act TableMetadata tableMetadata = admin.getTableMetadata(namespace1, TABLE1); @@ -165,7 +175,11 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(iterator.next()).isEqualTo(COL_NAME4); assertThat(iterator.next()).isEqualTo(COL_NAME3); - assertThat(tableMetadata.getColumnNames().size()).isEqualTo(11); + if (isTimestampTypeSupported()) { + assertThat(tableMetadata.getColumnNames().size()).isEqualTo(15); + } else { + assertThat(tableMetadata.getColumnNames().size()).isEqualTo(14); + } assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue(); @@ -177,6 +191,12 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnNames().contains(COL_NAME9)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME10)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME11)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(COL_NAME12)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(COL_NAME13)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(COL_NAME14)).isTrue(); + if (isTimestampTypeSupported()) { + assertThat(tableMetadata.getColumnNames().contains(COL_NAME15)).isTrue(); + } assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT); assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT); @@ -189,6 +209,12 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnDataType(COL_NAME9)).isEqualTo(DataType.DOUBLE); assertThat(tableMetadata.getColumnDataType(COL_NAME10)).isEqualTo(DataType.BOOLEAN); assertThat(tableMetadata.getColumnDataType(COL_NAME11)).isEqualTo(DataType.BLOB); + assertThat(tableMetadata.getColumnDataType(COL_NAME12)).isEqualTo(DataType.DATE); + assertThat(tableMetadata.getColumnDataType(COL_NAME13)).isEqualTo(DataType.TIME); + assertThat(tableMetadata.getColumnDataType(COL_NAME14)).isEqualTo(DataType.TIMESTAMPTZ); + if (isTimestampTypeSupported()) { + assertThat(tableMetadata.getColumnDataType(COL_NAME15)).isEqualTo(DataType.TIMESTAMP); + } assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull(); @@ -201,6 +227,10 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getClusteringOrder(COL_NAME9)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME10)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME11)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME12)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME13)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME14)).isNull(); + assertThat(tableMetadata.getClusteringOrder(COL_NAME15)).isNull(); assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue(); @@ -467,7 +497,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre try { // Arrange Map options = getCreationOptions(); - TableMetadata metadata = + TableMetadata.Builder metadataBuilder = TableMetadata.newBuilder() .addColumn(COL_NAME1, DataType.INT) .addColumn(COL_NAME2, DataType.INT) @@ -478,9 +508,15 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .addColumn(COL_NAME7, DataType.BOOLEAN) .addColumn(COL_NAME8, DataType.BLOB) .addColumn(COL_NAME9, DataType.TEXT) + .addColumn(COL_NAME10, DataType.DATE) + .addColumn(COL_NAME11, DataType.TIME) + .addColumn(COL_NAME12, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME9) - .build(); + .addSecondaryIndex(COL_NAME9); + if (isTimestampTypeSupported()) { + metadataBuilder = metadataBuilder.addColumn(COL_NAME13, DataType.TIMESTAMP); + } + TableMetadata metadata = metadataBuilder.build(); admin.createTable(namespace1, TABLE4, metadata, options); transactionManager = transactionFactory.getTransactionManager(); transactionManager.put( @@ -496,6 +532,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") + // TODO add put values for data, time, timestamp and timestamptz .build()); // Act @@ -508,6 +545,12 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre admin.createIndex(namespace1, TABLE4, COL_NAME7, options); } admin.createIndex(namespace1, TABLE4, COL_NAME8, options); + admin.createIndex(namespace1, TABLE4, COL_NAME10, options); + admin.createIndex(namespace1, TABLE4, COL_NAME11, options); + admin.createIndex(namespace1, TABLE4, COL_NAME12, options); + if (isTimestampTypeSupported()) { + admin.createIndex(namespace1, TABLE4, COL_NAME13, options); + } // Assert assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).isTrue(); @@ -519,16 +562,38 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME7)).isTrue(); } assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME9)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME10)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME11)).isTrue(); + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME12)).isTrue(); + if (isTimestampTypeSupported()) { + assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME13)).isTrue(); + } + + Set actualSecondaryIndexNames = + admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames(); + assertThat(actualSecondaryIndexNames) + .contains( + COL_NAME2, + COL_NAME3, + COL_NAME4, + COL_NAME5, + COL_NAME6, + COL_NAME8, + COL_NAME9, + COL_NAME10, + COL_NAME11, + COL_NAME12); + int indexCount = 10; if (isIndexOnBooleanColumnSupported()) { - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) - .containsOnly( - COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7, COL_NAME8, - COL_NAME9); - } else { - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) - .containsOnly( - COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME8, COL_NAME9); + assertThat(actualSecondaryIndexNames).contains(COL_NAME7); + indexCount++; + } + if (isTimestampTypeSupported()) { + assertThat(actualSecondaryIndexNames).contains(COL_NAME13); + indexCount++; } + assertThat(actualSecondaryIndexNames).hasSize(indexCount); } finally { admin.dropTable(namespace1, TABLE4, true); @@ -883,4 +948,8 @@ public void getNamespaceNames_ShouldReturnCreatedNamespaces() throws ExecutionEx protected boolean isIndexOnBooleanColumnSupported() { return true; } + + protected boolean isTimestampTypeSupported() { + return true; + } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java index bc43a09d33..637bb4d497 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java @@ -42,32 +42,46 @@ public abstract class DistributedTransactionAdminRepairIntegrationTestBase { protected static final String COL_NAME9 = "c9"; protected static final String COL_NAME10 = "c10"; protected static final String COL_NAME11 = "c11"; - - protected static final TableMetadata TABLE_METADATA = - TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.TEXT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.INT) - .addColumn(COL_NAME5, DataType.INT) - .addColumn(COL_NAME6, DataType.TEXT) - .addColumn(COL_NAME7, DataType.BIGINT) - .addColumn(COL_NAME8, DataType.FLOAT) - .addColumn(COL_NAME9, DataType.DOUBLE) - .addColumn(COL_NAME10, DataType.BOOLEAN) - .addColumn(COL_NAME11, DataType.BLOB) - .addPartitionKey(COL_NAME2) - .addPartitionKey(COL_NAME1) - .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) - .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) - .build(); + private static final String COL_NAME12 = "c12"; + private static final String COL_NAME13 = "c13"; + private static final String COL_NAME14 = "c14"; + private static final String COL_NAME15 = "c15"; protected DistributedTransactionAdmin admin; protected DistributedStorageAdmin storageAdmin; protected AdminTestUtils adminTestUtils = null; + protected TableMetadata getTableMetadata() { + TableMetadata.Builder builder = + TableMetadata.newBuilder() + .addColumn(COL_NAME1, DataType.INT) + .addColumn(COL_NAME2, DataType.TEXT) + .addColumn(COL_NAME3, DataType.TEXT) + .addColumn(COL_NAME4, DataType.INT) + .addColumn(COL_NAME5, DataType.INT) + .addColumn(COL_NAME6, DataType.TEXT) + .addColumn(COL_NAME7, DataType.BIGINT) + .addColumn(COL_NAME8, DataType.FLOAT) + .addColumn(COL_NAME9, DataType.DOUBLE) + .addColumn(COL_NAME10, DataType.BOOLEAN) + .addColumn(COL_NAME11, DataType.BLOB) + .addColumn(COL_NAME12, DataType.DATE) + .addColumn(COL_NAME13, DataType.TIME) + .addColumn(COL_NAME14, DataType.TIMESTAMPTZ); + if (isTimestampTypeSupported()) { + builder.addColumn(COL_NAME15, DataType.TIMESTAMP); + } + builder + .addPartitionKey(COL_NAME2) + .addPartitionKey(COL_NAME1) + .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) + .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) + .addSecondaryIndex(COL_NAME5) + .addSecondaryIndex(COL_NAME6) + .build(); + return builder.build(); + } + @BeforeAll public void beforeAll() throws Exception { initialize(TEST_NAME); @@ -126,7 +140,7 @@ private void createTable() throws ExecutionException { Map options = getCreationOptions(); admin.createCoordinatorTables(options); admin.createNamespace(getNamespace(), options); - admin.createTable(getNamespace(), getTable(), TABLE_METADATA, options); + admin.createTable(getNamespace(), getTable(), getTableMetadata(), options); } protected Map getCreationOptions() { @@ -152,11 +166,11 @@ protected void afterEach() throws Exception { @Test public void repairTable_ForExistingTableAndMetadata_ShouldDoNothing() throws Exception { // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); } @Test @@ -167,13 +181,13 @@ public void repairTableAndCoordinatorTables_ForDeletedMetadataTable_ShouldRepair // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); admin.repairCoordinatorTables(getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(admin.tableExists(getNamespace(), TABLE)).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(getTableMetadata()); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -184,12 +198,12 @@ public void repairTableAndCoordinatorTables_ForTruncatedMetadataTable_ShouldRepa adminTestUtils.truncateMetadataTable(); // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); admin.repairCoordinatorTables(getCreationOptions()); // Assert assertThat(admin.tableExists(getNamespace(), TABLE)).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(getTableMetadata()); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -199,11 +213,11 @@ public void repairTable_ForCorruptedMetadataTable_ShouldRepairProperly() throws adminTestUtils.corruptMetadata(getNamespace(), getTable()); // Act - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert assertThat(admin.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -239,12 +253,12 @@ public void repairTable_ForNonExistingTableButExistingMetadata_ShouldCreateTable // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -317,4 +331,8 @@ private boolean coordinatorNamespaceMetadataExits() throws ExecutionException { .orElse(Coordinator.NAMESPACE); return storageAdmin.namespaceExists(coordinatorNamespace); } + + protected boolean isTimestampTypeSupported() { + return true; + } } diff --git a/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java index 927edfaeda..29e7be5357 100644 --- a/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java @@ -51,34 +51,6 @@ public abstract class SchemaLoaderIntegrationTestBase { private static final String TABLE_1 = "test_table1"; private static final String NAMESPACE_2 = "int_test_" + TEST_NAME + "2"; private static final String TABLE_2 = "test_table2"; - private static final TableMetadata TABLE_1_METADATA = - TableMetadata.newBuilder() - .addPartitionKey("pk1") - .addClusteringKey("ck1", Order.DESC) - .addClusteringKey("ck2", Order.ASC) - .addColumn("pk1", DataType.INT) - .addColumn("ck1", DataType.INT) - .addColumn("ck2", DataType.TEXT) - .addColumn("col1", DataType.INT) - .addColumn("col2", DataType.BIGINT) - .addColumn("col3", DataType.FLOAT) - .addColumn("col4", DataType.DOUBLE) - .addColumn("col5", DataType.TEXT) - .addColumn("col6", DataType.BLOB) - .addColumn("col7", DataType.BOOLEAN) - .addSecondaryIndex("col1") - .addSecondaryIndex("col5") - .build(); - private static final TableMetadata TABLE_2_METADATA = - TableMetadata.newBuilder() - .addPartitionKey("pk1") - .addClusteringKey("ck1", Order.ASC) - .addColumn("pk1", DataType.INT) - .addColumn("ck1", DataType.INT) - .addColumn("col1", DataType.INT) - .addColumn("col2", DataType.BIGINT) - .addColumn("col3", DataType.FLOAT) - .build(); private DistributedStorageAdmin storageAdmin; private DistributedTransactionAdmin transactionAdmin; @@ -87,6 +59,45 @@ public abstract class SchemaLoaderIntegrationTestBase { private String systemNamespaceName; private AdminTestUtils adminTestUtils; + private TableMetadata getTable1Metadata() { + TableMetadata.Builder builder = + TableMetadata.newBuilder() + .addPartitionKey("pk1") + .addClusteringKey("ck1", Order.DESC) + .addClusteringKey("ck2", Order.ASC) + .addColumn("pk1", DataType.INT) + .addColumn("ck1", DataType.INT) + .addColumn("ck2", DataType.TEXT) + .addColumn("col1", DataType.INT) + .addColumn("col2", DataType.BIGINT) + .addColumn("col3", DataType.FLOAT) + .addColumn("col4", DataType.DOUBLE) + .addColumn("col5", DataType.TEXT) + .addColumn("col6", DataType.BLOB) + .addColumn("col7", DataType.BOOLEAN) + .addColumn("col8", DataType.DATE) + .addColumn("col9", DataType.TIME) + .addColumn("col10", DataType.TIMESTAMPTZ); + if (isTimestampTypeSupported()) { + builder.addColumn("col11", DataType.TIMESTAMP); + } + + builder.addSecondaryIndex("col1").addSecondaryIndex("col5"); + return builder.build(); + } + + private TableMetadata getTable2Metadata() { + return TableMetadata.newBuilder() + .addPartitionKey("pk1") + .addClusteringKey("ck1", Order.ASC) + .addColumn("pk1", DataType.INT) + .addColumn("ck1", DataType.INT) + .addColumn("col1", DataType.INT) + .addColumn("col2", DataType.BIGINT) + .addColumn("col3", DataType.FLOAT) + .build(); + } + @BeforeAll public void beforeAll() throws Exception { initialize(TEST_NAME); @@ -157,6 +168,12 @@ protected Map getSchemaJsonMap() { .put("col5", "TEXT") .put("col6", "BLOB") .put("col7", "BOOLEAN") + .put("col8", "DATE") + .put("col9", "TIME") + .putAll( + isTimestampTypeSupported() + ? ImmutableMap.of("col10", "TIMESTAMPTZ", "col11", "TIMESTAMP") + : ImmutableMap.of("col10", "TIMESTAMPTZ")) .build()) .put("secondary-index", Arrays.asList("col1", "col5")) .build(), @@ -193,10 +210,16 @@ protected Map getAlteredSchemaJsonMap() { .put("col5", "TEXT") .put("col6", "BLOB") .put("col7", "BOOLEAN") - .put("col8", "TEXT") - .put("col9", "BLOB") + .put("col8", "DATE") + .put("col9", "TIME") + .putAll( + isTimestampTypeSupported() + ? ImmutableMap.of("col10", "TIMESTAMPTZ", "col11", "TIMESTAMP") + : ImmutableMap.of("col10", "TIMESTAMPTZ")) + .put("col12", "TEXT") + .put("col13", "BLOB") .build()) - .put("secondary-index", Arrays.asList("col3", "col8")) + .put("secondary-index", Arrays.asList("col3", "col12")) .put("compaction-strategy", "LCS") .put("network-strategy", "SimpleStrategy") .put("replication-factor", "1") @@ -402,8 +425,9 @@ public void createTablesThenDropTablesThenRepairAllWithoutCoordinator_ShouldExec assertThat(storageAdmin.namespaceExists(namespace2)).isTrue(); assertThat(adminTestUtils.tableExists(namespace1, TABLE_1)).isTrue(); assertThat(adminTestUtils.tableExists(namespace2, TABLE_2)).isTrue(); - assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)).isEqualTo(TABLE_1_METADATA); - assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(TABLE_2_METADATA); + assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)) + .isEqualTo(getTable1Metadata()); + assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(getTable2Metadata()); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isFalse(); } @@ -433,8 +457,9 @@ public void createTablesThenDropTablesThenRepairAllWithCoordinator_ShouldExecute assertThat(storageAdmin.namespaceExists(namespace2)).isTrue(); assertThat(adminTestUtils.tableExists(namespace1, TABLE_1)).isTrue(); assertThat(adminTestUtils.tableExists(namespace2, TABLE_2)).isTrue(); - assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)).isEqualTo(TABLE_1_METADATA); - assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(TABLE_2_METADATA); + assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)) + .isEqualTo(getTable1Metadata()); + assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(getTable2Metadata()); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -447,16 +472,16 @@ public void createTableThenAlterTables_ShouldExecuteProperly() throws Exception assertThat(exitCodeCreation).isZero(); TableMetadata expectedTable1Metadata = - TableMetadata.newBuilder(TABLE_1_METADATA) - .addColumn("col8", DataType.TEXT) - .addColumn("col9", DataType.BLOB) + TableMetadata.newBuilder(getTable1Metadata()) + .addColumn("col12", DataType.TEXT) + .addColumn("col13", DataType.BLOB) .removeSecondaryIndex("col1") .removeSecondaryIndex("col5") .addSecondaryIndex("col3") - .addSecondaryIndex("col8") + .addSecondaryIndex("col12") .build(); TableMetadata expectedTable2Metadata = - TableMetadata.newBuilder(TABLE_2_METADATA).addColumn("col4", DataType.TEXT).build(); + TableMetadata.newBuilder(getTable2Metadata()).addColumn("col4", DataType.TEXT).build(); // Act int exitCodeAlteration = @@ -555,4 +580,8 @@ private int executeWithArgs(List args) { protected void waitForCreationIfNecessary() { // Do nothing } + + protected boolean isTimestampTypeSupported() { + return true; + } } diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java index 26ffa79330..fb18d7e045 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java @@ -35,6 +35,10 @@ public class TableSchema { .put("DOUBLE", DataType.DOUBLE) .put("TEXT", DataType.TEXT) .put("BLOB", DataType.BLOB) + .put("DATE", DataType.DATE) + .put("TIME", DataType.TIME) + .put("TIMESTAMP", DataType.TIMESTAMP) + .put("TIMESTAMPTZ", DataType.TIMESTAMPTZ) .build(); private static final ImmutableMap ORDER_MAP = ImmutableMap.builder().put("ASC", Order.ASC).put("DESC", Order.DESC).build(); diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java index f54f2d59f9..13bb5dca26 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java @@ -152,7 +152,13 @@ public void buildOptions_OptionsMapFromTableDefinitionAndOptionsGiven_ShouldRetu + " \"c3\": \"BLOB\"," + " \"c4\": \"INT\"," + " \"c5\": \"BOOLEAN\"," - + " \"c6\": \"INT\"" + + " \"c6\": \"FLOAT\"," + + " \"c7\": \"DOUBLE\"," + + " \"c8\": \"BIGINT\"," + + " \"c9\": \"DATE\"," + + " \"c10\": \"TIME\"," + + " \"c11\": \"TIMESTAMP\"," + + " \"c12\": \"TIMESTAMPTZ\"" + "}," + "\"ru\": 5000," + "\"compaction-strategy\": \"LCS\"," @@ -171,7 +177,13 @@ public void buildOptions_OptionsMapFromTableDefinitionAndOptionsGiven_ShouldRetu tableBuilder.addColumn("c3", DataType.BLOB); tableBuilder.addColumn("c4", DataType.INT); tableBuilder.addColumn("c5", DataType.BOOLEAN); - tableBuilder.addColumn("c6", DataType.INT); + tableBuilder.addColumn("c6", DataType.FLOAT); + tableBuilder.addColumn("c7", DataType.DOUBLE); + tableBuilder.addColumn("c8", DataType.BIGINT); + tableBuilder.addColumn("c9", DataType.DATE); + tableBuilder.addColumn("c10", DataType.TIME); + tableBuilder.addColumn("c11", DataType.TIMESTAMP); + tableBuilder.addColumn("c12", DataType.TIMESTAMPTZ); TableMetadata expectedTableMetadata = tableBuilder.build(); // Act From 68f46ef480f9715bf381ee0fe8ea8b34dbe5d4ec Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 6 Nov 2024 16:58:21 +0900 Subject: [PATCH 2/4] Refactoring --- .../DynamoColumnValueIntegrationTest.java | 15 +- ...tipleClusteringKeyScanIntegrationTest.java | 15 +- ...moMultiplePartitionKeyIntegrationTest.java | 15 +- .../DynamoSecondaryIndexIntegrationTest.java | 15 +- ...ingleClusteringKeyScanIntegrationTest.java | 15 +- ...namoSinglePartitionKeyIntegrationTest.java | 15 +- .../db/storage/dynamo/DynamoTestUtils.java | 13 +- ...dbcDatabaseColumnValueIntegrationTest.java | 19 +- ...baseCrossPartitionScanIntegrationTest.java | 3 +- ...tipleClusteringKeyScanIntegrationTest.java | 15 +- ...seMultiplePartitionKeyIntegrationTest.java | 15 +- ...DatabaseSecondaryIndexIntegrationTest.java | 19 +- ...ingleClusteringKeyScanIntegrationTest.java | 15 +- ...baseSinglePartitionKeyIntegrationTest.java | 15 +- .../scalar/db/storage/jdbc/JdbcTestUtils.java | 20 +- .../db/common/checker/OperationChecker.java | 5 +- .../cassandra/SelectStatementHandler.java | 5 +- .../db/storage/cosmos/CosmosOperation.java | 5 +- .../db/storage/dynamo/DynamoMutation.java | 10 +- .../dynamo/SelectStatementHandler.java | 10 +- .../db/storage/jdbc/query/SelectQuery.java | 24 +- .../com/scalar/db/util/ScalarDbUtils.java | 4 +- ...ibutedStorageAdminIntegrationTestBase.java | 4 +- ...StorageColumnValueIntegrationTestBase.java | 882 ++++++------------ ...onditionalMutationIntegrationTestBase.java | 24 +- ...CrossPartitionScanIntegrationTestBase.java | 9 +- ...eClusteringKeyScanIntegrationTestBase.java | 178 ++-- ...ltiplePartitionKeyIntegrationTestBase.java | 109 ++- ...rageSecondaryIndexIntegrationTestBase.java | 83 +- ...eClusteringKeyScanIntegrationTestBase.java | 162 ++-- ...SinglePartitionKeyIntegrationTestBase.java | 116 +-- ...edTransactionAdminIntegrationTestBase.java | 4 +- ...udeMetadataEnabledIntegrationTestBase.java | 31 +- ...udeMetadataEnabledIntegrationTestBase.java | 31 +- .../java/com/scalar/db/util/TestUtils.java | 94 +- 35 files changed, 888 insertions(+), 1126 deletions(-) diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoColumnValueIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoColumnValueIntegrationTest.java index b57c4a4335..17246c80e3 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoColumnValueIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoColumnValueIntegrationTest.java @@ -1,8 +1,8 @@ package com.scalar.db.storage.dynamo; import com.scalar.db.api.DistributedStorageColumnValueIntegrationTestBase; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Map; import java.util.Properties; import java.util.Random; @@ -20,26 +20,27 @@ protected Map getCreationOptions() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getRandomDynamoDoubleValue(random, columnName); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMinDynamoDoubleValue(columnName); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMaxDynamoDoubleValue(columnName); } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java index 710acfa6de..9669062f58 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java @@ -3,8 +3,8 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import com.scalar.db.api.DistributedStorageMultipleClusteringKeyScanIntegrationTestBase; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Map; import java.util.Properties; import java.util.Random; @@ -41,26 +41,27 @@ protected Map getCreationOptions() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getRandomDynamoDoubleValue(random, columnName); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMinDynamoDoubleValue(columnName); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMaxDynamoDoubleValue(columnName); } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java index 3972535e01..f16ebfe333 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java @@ -3,8 +3,8 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import com.scalar.db.api.DistributedStorageMultiplePartitionKeyIntegrationTestBase; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Map; import java.util.Properties; import java.util.Random; @@ -37,26 +37,27 @@ protected ListMultimap getPartitionKeyTypes() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getRandomDynamoDoubleValue(random, columnName); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMinDynamoDoubleValue(columnName); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMaxDynamoDoubleValue(columnName); } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java index d57e1ee390..b0b1241183 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java @@ -1,8 +1,8 @@ package com.scalar.db.storage.dynamo; import com.scalar.db.api.DistributedStorageSecondaryIndexIntegrationTestBase; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import com.scalar.db.util.TestUtils; import java.util.HashSet; import java.util.Map; @@ -36,28 +36,29 @@ protected Map getCreationOptions() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getRandomDynamoDoubleValue(random, columnName); } // don't allow empty value since secondary index cannot contain empty value - return TestUtils.getRandomValue(random, columnName, dataType, false); + return TestUtils.getColumnWithRandomValue(random, columnName, dataType, false); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMinDynamoDoubleValue(columnName); } // don't allow empty value since secondary index cannot contain empty value - return TestUtils.getMinValue(columnName, dataType, false); + return TestUtils.getColumnWithMinValue(columnName, dataType, false); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMaxDynamoDoubleValue(columnName); } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java index d1c7c60b72..c703b6a076 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java @@ -1,8 +1,8 @@ package com.scalar.db.storage.dynamo; import com.scalar.db.api.DistributedStorageSingleClusteringKeyScanIntegrationTestBase; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.HashSet; import java.util.Map; import java.util.Properties; @@ -36,26 +36,27 @@ protected Map getCreationOptions() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getRandomDynamoDoubleValue(random, columnName); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMinDynamoDoubleValue(columnName); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMaxDynamoDoubleValue(columnName); } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSinglePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSinglePartitionKeyIntegrationTest.java index 70018307de..6b809d405b 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSinglePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSinglePartitionKeyIntegrationTest.java @@ -1,8 +1,8 @@ package com.scalar.db.storage.dynamo; import com.scalar.db.api.DistributedStorageSinglePartitionKeyIntegrationTestBase; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Map; import java.util.Properties; import java.util.Random; @@ -20,26 +20,27 @@ protected Map getCreationOptions() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getRandomDynamoDoubleValue(random, columnName); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMinDynamoDoubleValue(columnName); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (dataType == DataType.DOUBLE) { return DynamoTestUtils.getMaxDynamoDoubleValue(columnName); } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoTestUtils.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoTestUtils.java index 1084b26e21..e3148e136e 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoTestUtils.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoTestUtils.java @@ -1,7 +1,6 @@ package com.scalar.db.storage.dynamo; import com.scalar.db.io.DoubleColumn; -import com.scalar.db.io.DoubleValue; import java.util.Random; public final class DynamoTestUtils { @@ -11,8 +10,8 @@ public final class DynamoTestUtils { private DynamoTestUtils() {} - public static DoubleValue getRandomDynamoDoubleValue(Random random, String columnName) { - return new DoubleValue(columnName, nextDynamoDouble(random)); + public static DoubleColumn getRandomDynamoDoubleValue(Random random, String columnName) { + return DoubleColumn.of(columnName, nextDynamoDouble(random)); } public static DoubleColumn getRandomDynamoDoubleColumn(Random random, String columnName) { @@ -27,11 +26,11 @@ public static double nextDynamoDouble(Random random) { .orElse(0.0d); } - public static DoubleValue getMinDynamoDoubleValue(String columnName) { - return new DoubleValue(columnName, MIN_DYNAMO_DOUBLE_VALUE); + public static DoubleColumn getMinDynamoDoubleValue(String columnName) { + return DoubleColumn.of(columnName, MIN_DYNAMO_DOUBLE_VALUE); } - public static DoubleValue getMaxDynamoDoubleValue(String columnName) { - return new DoubleValue(columnName, MAX_DYNAMO_DOUBLE_VALUE); + public static DoubleColumn getMaxDynamoDoubleValue(String columnName) { + return DoubleColumn.of(columnName, MAX_DYNAMO_DOUBLE_VALUE); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseColumnValueIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseColumnValueIntegrationTest.java index 8ee14aa209..85a87ca5a0 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseColumnValueIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseColumnValueIntegrationTest.java @@ -2,8 +2,8 @@ import com.scalar.db.api.DistributedStorageColumnValueIntegrationTestBase; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import com.scalar.db.util.TestUtils; import java.util.Properties; import java.util.Random; @@ -22,31 +22,32 @@ protected Properties getProperties(String testName) { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } // don't allow empty value since Oracle treats empty value as NULL - return TestUtils.getRandomValue(random, columnName, dataType, false); + return TestUtils.getColumnWithRandomValue(random, columnName, dataType, false); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMinOracleDoubleValue(columnName); } // don't allow empty value since Oracle treats empty value as NULL - return TestUtils.getMinValue(columnName, dataType, false); + return TestUtils.getColumnWithMinValue(columnName, dataType, false); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMaxOracleDoubleValue(columnName); @@ -57,6 +58,6 @@ protected Value getMaxValue(String columnName, DataType dataType) { return JdbcTestUtils.getMaxSqlServerTextValue(columnName); } } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCrossPartitionScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCrossPartitionScanIntegrationTest.java index bcd90afb4d..ae3a57ef4a 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCrossPartitionScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCrossPartitionScanIntegrationTest.java @@ -4,7 +4,6 @@ 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; @@ -33,7 +32,7 @@ protected int getThreadNum() { protected Column getRandomColumn(Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { - return ScalarDbUtils.toColumn(JdbcTestUtils.getRandomOracleDoubleValue(random, columnName)); + return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } } return super.getRandomColumn(random, columnName, dataType); diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultipleClusteringKeyScanIntegrationTest.java index bf0d77e80d..f62169f959 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultipleClusteringKeyScanIntegrationTest.java @@ -3,8 +3,8 @@ import com.google.errorprone.annotations.concurrent.LazyInit; import com.scalar.db.api.DistributedStorageMultipleClusteringKeyScanIntegrationTestBase; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Properties; import java.util.Random; import org.junit.jupiter.api.Test; @@ -47,27 +47,28 @@ private boolean isYugabyteDb() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMinOracleDoubleValue(columnName); } } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMaxOracleDoubleValue(columnName); @@ -78,7 +79,7 @@ protected Value getMaxValue(String columnName, DataType dataType) { return JdbcTestUtils.getMaxSqlServerTextValue(columnName); } } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } // TODO: Remove this once https://github.com/yugabyte/yugabyte-db/issues/22140 is fixed and the diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultiplePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultiplePartitionKeyIntegrationTest.java index 4193e205d8..a0ed3a1250 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultiplePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseMultiplePartitionKeyIntegrationTest.java @@ -3,8 +3,8 @@ import com.google.errorprone.annotations.concurrent.LazyInit; import com.scalar.db.api.DistributedStorageMultiplePartitionKeyIntegrationTestBase; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Properties; import java.util.Random; @@ -46,27 +46,28 @@ protected boolean isFloatTypeKeySupported() { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMinOracleDoubleValue(columnName); } } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMaxOracleDoubleValue(columnName); @@ -77,6 +78,6 @@ protected Value getMaxValue(String columnName, DataType dataType) { return JdbcTestUtils.getMaxSqlServerTextValue(columnName); } } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSecondaryIndexIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSecondaryIndexIntegrationTest.java index 64fdacad43..22d1f74127 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSecondaryIndexIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSecondaryIndexIntegrationTest.java @@ -2,8 +2,8 @@ import com.scalar.db.api.DistributedStorageSecondaryIndexIntegrationTestBase; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import com.scalar.db.util.TestUtils; import java.util.Properties; import java.util.Random; @@ -22,31 +22,32 @@ protected Properties getProperties(String testName) { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } // don't allow empty value since Oracle treats empty value as NULL - return TestUtils.getRandomValue(random, columnName, dataType, false); + return TestUtils.getColumnWithRandomValue(random, columnName, dataType, false); } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMinOracleDoubleValue(columnName); } // don't allow empty value since Oracle treats empty value as NULL - return TestUtils.getMinValue(columnName, dataType, false); + return TestUtils.getColumnWithMinValue(columnName, dataType, false); } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMaxOracleDoubleValue(columnName); @@ -57,6 +58,6 @@ protected Value getMaxValue(String columnName, DataType dataType) { return JdbcTestUtils.getMaxSqlServerTextValue(columnName); } } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSingleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSingleClusteringKeyScanIntegrationTest.java index 4b8d96d173..4a7e9eda95 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSingleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSingleClusteringKeyScanIntegrationTest.java @@ -2,8 +2,8 @@ import com.scalar.db.api.DistributedStorageSingleClusteringKeyScanIntegrationTestBase; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Properties; import java.util.Random; @@ -21,27 +21,28 @@ protected Properties getProperties(String testName) { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMinOracleDoubleValue(columnName); } } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMaxOracleDoubleValue(columnName); @@ -52,6 +53,6 @@ protected Value getMaxValue(String columnName, DataType dataType) { return JdbcTestUtils.getMaxSqlServerTextValue(columnName); } } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSinglePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSinglePartitionKeyIntegrationTest.java index d3d1478318..6e70963e7a 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSinglePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseSinglePartitionKeyIntegrationTest.java @@ -2,8 +2,8 @@ import com.scalar.db.api.DistributedStorageSinglePartitionKeyIntegrationTestBase; import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.Value; import java.util.Properties; import java.util.Random; @@ -21,27 +21,28 @@ protected Properties getProperties(String testName) { } @Override - protected Value getRandomValue(Random random, String columnName, DataType dataType) { + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getRandomOracleDoubleValue(random, columnName); } } - return super.getRandomValue(random, columnName, dataType); + return super.getColumnWithRandomValue(random, columnName, dataType); } @Override - protected Value getMinValue(String columnName, DataType dataType) { + protected Column getColumnWithMinValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMinOracleDoubleValue(columnName); } } - return super.getMinValue(columnName, dataType); + return super.getColumnWithMinValue(columnName, dataType); } @Override - protected Value getMaxValue(String columnName, DataType dataType) { + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { if (JdbcTestUtils.isOracle(rdbEngine)) { if (dataType == DataType.DOUBLE) { return JdbcTestUtils.getMaxOracleDoubleValue(columnName); @@ -52,7 +53,7 @@ protected Value getMaxValue(String columnName, DataType dataType) { return JdbcTestUtils.getMaxSqlServerTextValue(columnName); } } - return super.getMaxValue(columnName, dataType); + return super.getColumnWithMaxValue(columnName, dataType); } @Override diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcTestUtils.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcTestUtils.java index 20b46faad4..ef0dd3b7d7 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcTestUtils.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcTestUtils.java @@ -2,9 +2,7 @@ import com.scalar.db.io.Column; import com.scalar.db.io.DoubleColumn; -import com.scalar.db.io.DoubleValue; -import com.scalar.db.io.TextValue; -import com.scalar.db.io.Value; +import com.scalar.db.io.TextColumn; import com.scalar.db.util.TestUtils; import java.util.Random; import java.util.stream.IntStream; @@ -16,8 +14,8 @@ public final class JdbcTestUtils { private JdbcTestUtils() {} - public static Value getRandomOracleDoubleValue(Random random, String columnName) { - return new DoubleValue(columnName, nextOracleDouble(random)); + public static Column getRandomOracleDoubleValue(Random random, String columnName) { + return DoubleColumn.of(columnName, nextOracleDouble(random)); } public static Column getRandomOracleDoubleColumn(Random random, String columnName) { @@ -32,19 +30,19 @@ public static double nextOracleDouble(Random random) { .orElse(0.0d); } - public static DoubleValue getMinOracleDoubleValue(String columnName) { - return new DoubleValue(columnName, MIN_ORACLE_DOUBLE_VALUE); + public static DoubleColumn getMinOracleDoubleValue(String columnName) { + return DoubleColumn.of(columnName, MIN_ORACLE_DOUBLE_VALUE); } - public static DoubleValue getMaxOracleDoubleValue(String columnName) { - return new DoubleValue(columnName, MAX_ORACLE_DOUBLE_VALUE); + public static DoubleColumn getMaxOracleDoubleValue(String columnName) { + return DoubleColumn.of(columnName, MAX_ORACLE_DOUBLE_VALUE); } - public static TextValue getMaxSqlServerTextValue(String columnName) { + public static TextColumn getMaxSqlServerTextValue(String columnName) { // Since SQL Server can't handle 0xFF character correctly, we use "ZZZ..." as the max value StringBuilder builder = new StringBuilder(); IntStream.range(0, TestUtils.MAX_TEXT_COUNT).forEach(i -> builder.append('Z')); - return new TextValue(columnName, builder.toString()); + return TextColumn.of(columnName, builder.toString()); } public static boolean isPostgresql(RdbEngineStrategy rdbEngine) { diff --git a/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java b/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java index 6017a8e24e..0e68dacc3f 100644 --- a/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java +++ b/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java @@ -18,7 +18,6 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.io.Column; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.util.ScalarDbUtils; import java.util.Iterator; import java.util.LinkedHashSet; @@ -188,8 +187,8 @@ private void checkClusteringKeys(Scan scan, TableMetadata metadata) { } for (int i = 0; i < startClusteringKey.size() - 1; i++) { - Value startValue = startClusteringKey.get().get(i); - Value endValue = endClusteringKey.get().get(i); + Column startValue = startClusteringKey.getColumns().get(i); + Column endValue = endClusteringKey.getColumns().get(i); if (!startValue.equals(endValue)) { throw new IllegalArgumentException(message.get()); } diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java b/core/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java index c9a74e8ac3..4d6b335b6d 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/SelectStatementHandler.java @@ -25,7 +25,6 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.io.Column; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -183,7 +182,7 @@ private void setStart(Select.Where statement, Scan scan, Set traveledEqu scan.getStartClusteringKey() .ifPresent( k -> { - List> start = k.get(); + List> start = k.getColumns(); IntStream.range(0, start.size()) .forEach( i -> { @@ -210,7 +209,7 @@ private void setEnd(Select.Where statement, Scan scan, Set traveledEqual scan.getEndClusteringKey() .ifPresent( k -> { - List> end = k.get(); + List> end = k.getColumns(); IntStream.range(0, end.size()) .forEach( i -> { diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java index 3e230c451e..e1efadc18a 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosOperation.java @@ -6,7 +6,6 @@ import com.scalar.db.api.Operation; import com.scalar.db.api.TableMetadata; import com.scalar.db.io.Column; -import com.scalar.db.io.Value; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -32,8 +31,8 @@ public boolean isPrimaryKeySpecified() { if (operation.getClusteringKey().isPresent()) { Set set = - operation.getClusteringKey().get().get().stream() - .map(Value::getName) + operation.getClusteringKey().get().getColumns().stream() + .map(Column::getName) .collect(Collectors.toSet()); return set.containsAll(metadata.getClusteringKeyNames()); } else { diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java index 34c3bce6a6..ddd9601a5f 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoMutation.java @@ -4,7 +4,7 @@ import com.scalar.db.api.Mutation; import com.scalar.db.api.Put; import com.scalar.db.api.TableMetadata; -import com.scalar.db.io.Value; +import com.scalar.db.io.Column; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -69,12 +69,12 @@ private String getUpdateExpression(boolean withKey) { int i = 0; if (withKey) { - for (Value unusedKey : put.getPartitionKey().get()) { + for (Column unusedKey : put.getPartitionKey().getColumns()) { expressions.add(COLUMN_NAME_ALIAS + i + " = " + VALUE_ALIAS + i); i++; } if (put.getClusteringKey().isPresent()) { - for (Value unusedKey : put.getClusteringKey().get().get()) { + for (Column unusedKey : put.getClusteringKey().get().getColumns()) { expressions.add(COLUMN_NAME_ALIAS + i + " = " + VALUE_ALIAS + i); i++; } @@ -105,12 +105,12 @@ private Map getColumnMap(boolean withKey) { int i = 0; if (withKey) { - for (Value key : put.getPartitionKey().get()) { + for (Column key : put.getPartitionKey().getColumns()) { columnMap.put(COLUMN_NAME_ALIAS + i, key.getName()); i++; } if (put.getClusteringKey().isPresent()) { - for (Value key : put.getClusteringKey().get().get()) { + for (Column key : put.getClusteringKey().get().getColumns()) { columnMap.put(COLUMN_NAME_ALIAS + i, key.getName()); i++; } diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java b/core/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java index 3b757af5e1..7457d4b009 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/SelectStatementHandler.java @@ -315,8 +315,8 @@ private boolean setConditions( private Key getKeyWithoutLastValue(Key originalKey) { Key.Builder keyBuilder = Key.newBuilder(); - for (int i = 0; i < originalKey.get().size() - 1; i++) { - keyBuilder.add(originalKey.get().get(i)); + for (int i = 0; i < originalKey.getColumns().size() - 1; i++) { + keyBuilder.add(originalKey.getColumns().get(i)); } return keyBuilder.build(); } @@ -506,12 +506,14 @@ private ByteBuffer getKeyBytes(Key key, TableMetadata tableMetadata) { private boolean isScanForDescClusteringOrder(Scan scan, TableMetadata tableMetadata) { if (scan.getStartClusteringKey().isPresent()) { Key startClusteringKey = scan.getStartClusteringKey().get(); - String lastValueName = startClusteringKey.get().get(startClusteringKey.size() - 1).getName(); + String lastValueName = + startClusteringKey.getColumns().get(startClusteringKey.size() - 1).getName(); return tableMetadata.getClusteringOrder(lastValueName) == Order.DESC; } if (scan.getEndClusteringKey().isPresent()) { Key endClusteringKey = scan.getEndClusteringKey().get(); - String lastValueName = endClusteringKey.get().get(endClusteringKey.size() - 1).getName(); + String lastValueName = + endClusteringKey.getColumns().get(endClusteringKey.size() - 1).getName(); return tableMetadata.getClusteringOrder(lastValueName) == Order.DESC; } return false; diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java b/core/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java index 8f680891b4..5cc5834264 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/query/SelectQuery.java @@ -76,18 +76,20 @@ public Builder where( this.partitionKey = Optional.of(partitionKey); if (startClusteringKey.isPresent()) { - commonClusteringKey = - Optional.of( - new Key( - startClusteringKey - .get() - .get() - .subList(0, startClusteringKey.get().size() - 1))); + Key.Builder keyBuilder = Key.newBuilder(); + startClusteringKey + .get() + .getColumns() + .subList(0, startClusteringKey.get().size() - 1) + .forEach(keyBuilder::add); + commonClusteringKey = Optional.of(keyBuilder.build()); } else { endClusteringKey.ifPresent( - values -> - commonClusteringKey = - Optional.of(new Key(values.get().subList(0, values.size() - 1)))); + values -> { + Key.Builder keyBuilder = Key.newBuilder(); + values.getColumns().subList(0, values.size() - 1).forEach(keyBuilder::add); + commonClusteringKey = Optional.of(keyBuilder.build()); + }); } if (startClusteringKey.isPresent()) { @@ -120,7 +122,7 @@ private void setIndexInfoIfUsed(Key partitionKey) { return; } - String column = partitionKey.get().get(0).getName(); + String column = partitionKey.getColumns().get(0).getName(); if (!tableMetadata.getSecondaryIndexNames().contains(column)) { return; } 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 51c21a7dc6..35b0ba6864 100644 --- a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java +++ b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java @@ -104,14 +104,14 @@ public static Mutation copyAndSetTargetToIfNot( public static Put copyAndSetTargetToIfNot( Put put, Optional namespace, Optional tableName) { - Put ret = new Put(put); // copy + Put ret = Put.newBuilder(put).build(); // copy setTargetToIfNot(ret, namespace, tableName); return ret; } public static Delete copyAndSetTargetToIfNot( Delete delete, Optional namespace, Optional tableName) { - Delete ret = new Delete(delete); // copy + Delete ret = Delete.newBuilder(delete).build(); // copy setTargetToIfNot(ret, namespace, tableName); return ret; } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java index b56399ac57..c768c66d91 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java @@ -437,6 +437,7 @@ public void truncateTable_ShouldTruncateProperly() throws ExecutionException, IO .withValue(COL_NAME9, 1.0d) .withValue(COL_NAME10, true) .withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)) + // TODO add put values for date, time, timestamp and timestamptz .forNamespace(namespace1) .forTable(TABLE1)); @@ -538,7 +539,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") - // TODO add put values for data, time, timestamp and timestamptz + // TODO add put values for date, time, timestamp and timestamptz .build()); // Act admin.createIndex(namespace1, TABLE4, COL_NAME2, options); @@ -725,6 +726,7 @@ public void dropIndex_ForAllDataTypesWithExistingData_ShouldDropIndexCorrectly() .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") + // TODO add put values for date, time, timestamp and timestamptz .build()); // Act diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageColumnValueIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageColumnValueIntegrationTestBase.java index 0fbef6a5bb..81d686f712 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageColumnValueIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageColumnValueIntegrationTestBase.java @@ -3,22 +3,19 @@ import static org.assertj.core.api.Assertions.assertThat; import com.scalar.db.exception.storage.ExecutionException; -import com.scalar.db.io.BigIntValue; -import com.scalar.db.io.BlobValue; -import com.scalar.db.io.BooleanValue; +import com.scalar.db.io.BigIntColumn; +import com.scalar.db.io.BlobColumn; +import com.scalar.db.io.BooleanColumn; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; -import com.scalar.db.io.DoubleValue; -import com.scalar.db.io.FloatValue; -import com.scalar.db.io.IntValue; +import com.scalar.db.io.DoubleColumn; +import com.scalar.db.io.FloatColumn; +import com.scalar.db.io.IntColumn; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; -import com.scalar.db.io.Value; +import com.scalar.db.io.TextColumn; import com.scalar.db.service.StorageFactory; import com.scalar.db.util.TestUtils; -import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -143,647 +140,368 @@ public void put_WithRandomValues_ShouldPutCorrectly() throws ExecutionException for (int i = 0; i < ATTEMPT_COUNT; i++) { // Arrange - IntValue partitionKeyValue = (IntValue) getRandomValue(random, PARTITION_KEY, DataType.INT); - BooleanValue col1Value = (BooleanValue) getRandomValue(random, COL_NAME1, DataType.BOOLEAN); - IntValue col2Value = (IntValue) getRandomValue(random, COL_NAME2, DataType.INT); - BigIntValue col3Value = (BigIntValue) getRandomValue(random, COL_NAME3, DataType.BIGINT); - FloatValue col4Value = (FloatValue) getRandomValue(random, COL_NAME4, DataType.FLOAT); - DoubleValue col5Value = (DoubleValue) getRandomValue(random, COL_NAME5, DataType.DOUBLE); - TextValue col6Value = (TextValue) getRandomValue(random, COL_NAME6, DataType.TEXT); - BlobValue col7Value = (BlobValue) getRandomValue(random, COL_NAME7, DataType.BLOB); - + IntColumn partitionKeyValue = + (IntColumn) getColumnWithRandomValue(random, PARTITION_KEY, DataType.INT); + BooleanColumn col1Value = + (BooleanColumn) getColumnWithRandomValue(random, COL_NAME1, DataType.BOOLEAN); + IntColumn col2Value = (IntColumn) getColumnWithRandomValue(random, COL_NAME2, DataType.INT); + BigIntColumn col3Value = + (BigIntColumn) getColumnWithRandomValue(random, COL_NAME3, DataType.BIGINT); + FloatColumn col4Value = + (FloatColumn) getColumnWithRandomValue(random, COL_NAME4, DataType.FLOAT); + DoubleColumn col5Value = + (DoubleColumn) getColumnWithRandomValue(random, COL_NAME5, DataType.DOUBLE); + TextColumn col6Value = + (TextColumn) getColumnWithRandomValue(random, COL_NAME6, DataType.TEXT); + BlobColumn col7Value = + (BlobColumn) getColumnWithRandomValue(random, COL_NAME7, DataType.BLOB); Put put = - new Put(new Key(partitionKeyValue)) - .withValue(col1Value) - .withValue(col2Value) - .withValue(col3Value) - .withValue(col4Value) - .withValue(col5Value) - .withValue(col6Value) - .withValue(col7Value) - .forNamespace(namespace) - .forTable(TABLE); - + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .value(col1Value) + .value(col2Value) + .value(col3Value) + .value(col4Value) + .value(col5Value) + .value(col6Value) + .value(col7Value) + .build(); // Act storage.put(put); // Assert - Optional actual = - storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE)); - assertThat(actual).isPresent(); - assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue(); - assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue); - assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value); - assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value); - assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value); - assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value); - assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value); - assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value); - assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value); - - assertThat(actual.get().getContainedColumnNames()) - .isEqualTo( - new HashSet<>( - Arrays.asList( - PARTITION_KEY, - COL_NAME1, - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME7))); - - assertThat(actual.get().contains(PARTITION_KEY)).isTrue(); - assertThat(actual.get().isNull(PARTITION_KEY)).isFalse(); - assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - - assertThat(actual.get().contains(COL_NAME1)).isTrue(); - assertThat(actual.get().isNull(COL_NAME1)).isFalse(); - assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get()); - assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get()); - - assertThat(actual.get().contains(COL_NAME2)).isTrue(); - assertThat(actual.get().isNull(COL_NAME2)).isFalse(); - assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get()); - assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get()); - - assertThat(actual.get().contains(COL_NAME3)).isTrue(); - assertThat(actual.get().isNull(COL_NAME3)).isFalse(); - assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get()); - assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get()); - - assertThat(actual.get().contains(COL_NAME4)).isTrue(); - assertThat(actual.get().isNull(COL_NAME4)).isFalse(); - assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get()); - assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get()); - - assertThat(actual.get().contains(COL_NAME5)).isTrue(); - assertThat(actual.get().isNull(COL_NAME5)).isFalse(); - assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get()); - assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get()); - - assertThat(actual.get().contains(COL_NAME6)).isTrue(); - assertThat(actual.get().isNull(COL_NAME6)).isFalse(); - assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get()); - assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get()); - - assertThat(actual.get().contains(COL_NAME7)).isTrue(); - assertThat(actual.get().isNull(COL_NAME7)).isFalse(); - assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get())); - assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)) - .isEqualTo(ByteBuffer.wrap(col7Value.get().get())); - assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get()); - assertThat(actual.get().getAsObject(COL_NAME7)) - .isEqualTo(ByteBuffer.wrap(col7Value.get().get())); + assertResult( + partitionKeyValue, + col1Value, + col2Value, + col3Value, + col4Value, + col5Value, + col6Value, + col7Value); } } @Test public void put_WithMaxValues_ShouldPutCorrectly() throws ExecutionException { // Arrange - IntValue partitionKeyValue = (IntValue) getMaxValue(PARTITION_KEY, DataType.INT); - BooleanValue col1Value = (BooleanValue) getMaxValue(COL_NAME1, DataType.BOOLEAN); - IntValue col2Value = (IntValue) getMaxValue(COL_NAME2, DataType.INT); - BigIntValue col3Value = (BigIntValue) getMaxValue(COL_NAME3, DataType.BIGINT); - FloatValue col4Value = (FloatValue) getMaxValue(COL_NAME4, DataType.FLOAT); - DoubleValue col5Value = (DoubleValue) getMaxValue(COL_NAME5, DataType.DOUBLE); - TextValue col6Value = (TextValue) getMaxValue(COL_NAME6, DataType.TEXT); - BlobValue col7Value = (BlobValue) getMaxValue(COL_NAME7, DataType.BLOB); + IntColumn partitionKeyValue = (IntColumn) getColumnWithMaxValue(PARTITION_KEY, DataType.INT); + BooleanColumn col1Value = (BooleanColumn) getColumnWithMaxValue(COL_NAME1, DataType.BOOLEAN); + IntColumn col2Value = (IntColumn) getColumnWithMaxValue(COL_NAME2, DataType.INT); + BigIntColumn col3Value = (BigIntColumn) getColumnWithMaxValue(COL_NAME3, DataType.BIGINT); + FloatColumn col4Value = (FloatColumn) getColumnWithMaxValue(COL_NAME4, DataType.FLOAT); + DoubleColumn col5Value = (DoubleColumn) getColumnWithMaxValue(COL_NAME5, DataType.DOUBLE); + TextColumn col6Value = (TextColumn) getColumnWithMaxValue(COL_NAME6, DataType.TEXT); + BlobColumn col7Value = (BlobColumn) getColumnWithMaxValue(COL_NAME7, DataType.BLOB); Put put = - new Put(new Key(partitionKeyValue)) - .withValue(col1Value) - .withValue(col2Value) - .withValue(col3Value) - .withValue(col4Value) - .withValue(col5Value) - .withValue(col6Value) - .withValue(col7Value) - .forNamespace(namespace) - .forTable(TABLE); - + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .value(col1Value) + .value(col2Value) + .value(col3Value) + .value(col4Value) + .value(col5Value) + .value(col6Value) + .value(col7Value) + .build(); // Act storage.put(put); // Assert - Optional actual = - storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE)); - assertThat(actual).isPresent(); - assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue(); - assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue); - assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value); - assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value); - assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value); - assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value); - assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value); - assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value); - assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value); - - assertThat(actual.get().getContainedColumnNames()) - .isEqualTo( - new HashSet<>( - Arrays.asList( - PARTITION_KEY, - COL_NAME1, - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME7))); - - assertThat(actual.get().contains(PARTITION_KEY)).isTrue(); - assertThat(actual.get().isNull(PARTITION_KEY)).isFalse(); - assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - - assertThat(actual.get().contains(COL_NAME1)).isTrue(); - assertThat(actual.get().isNull(COL_NAME1)).isFalse(); - assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get()); - assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get()); - - assertThat(actual.get().contains(COL_NAME2)).isTrue(); - assertThat(actual.get().isNull(COL_NAME2)).isFalse(); - assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get()); - assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get()); - - assertThat(actual.get().contains(COL_NAME3)).isTrue(); - assertThat(actual.get().isNull(COL_NAME3)).isFalse(); - assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get()); - assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get()); - - assertThat(actual.get().contains(COL_NAME4)).isTrue(); - assertThat(actual.get().isNull(COL_NAME4)).isFalse(); - assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get()); - assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get()); - - assertThat(actual.get().contains(COL_NAME5)).isTrue(); - assertThat(actual.get().isNull(COL_NAME5)).isFalse(); - assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get()); - assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get()); - - assertThat(actual.get().contains(COL_NAME6)).isTrue(); - assertThat(actual.get().isNull(COL_NAME6)).isFalse(); - assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get()); - assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get()); - - assertThat(actual.get().contains(COL_NAME7)).isTrue(); - assertThat(actual.get().isNull(COL_NAME7)).isFalse(); - assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get())); - assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)) - .isEqualTo(ByteBuffer.wrap(col7Value.get().get())); - assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get()); - assertThat(actual.get().getAsObject(COL_NAME7)) - .isEqualTo(ByteBuffer.wrap(col7Value.get().get())); + assertResult( + partitionKeyValue, + col1Value, + col2Value, + col3Value, + col4Value, + col5Value, + col6Value, + col7Value); } @Test public void put_WithMinValues_ShouldPutCorrectly() throws ExecutionException { // Arrange - IntValue partitionKeyValue = (IntValue) getMinValue(PARTITION_KEY, DataType.INT); - BooleanValue col1Value = (BooleanValue) getMinValue(COL_NAME1, DataType.BOOLEAN); - IntValue col2Value = (IntValue) getMinValue(COL_NAME2, DataType.INT); - BigIntValue col3Value = (BigIntValue) getMinValue(COL_NAME3, DataType.BIGINT); - FloatValue col4Value = (FloatValue) getMinValue(COL_NAME4, DataType.FLOAT); - DoubleValue col5Value = (DoubleValue) getMinValue(COL_NAME5, DataType.DOUBLE); - TextValue col6Value = (TextValue) getMinValue(COL_NAME6, DataType.TEXT); - BlobValue col7Value = (BlobValue) getMinValue(COL_NAME7, DataType.BLOB); + IntColumn partitionKeyValue = (IntColumn) getColumnWithMinValue(PARTITION_KEY, DataType.INT); + BooleanColumn col1Value = (BooleanColumn) getColumnWithMinValue(COL_NAME1, DataType.BOOLEAN); + IntColumn col2Value = (IntColumn) getColumnWithMinValue(COL_NAME2, DataType.INT); + BigIntColumn col3Value = (BigIntColumn) getColumnWithMinValue(COL_NAME3, DataType.BIGINT); + FloatColumn col4Value = (FloatColumn) getColumnWithMinValue(COL_NAME4, DataType.FLOAT); + DoubleColumn col5Value = (DoubleColumn) getColumnWithMinValue(COL_NAME5, DataType.DOUBLE); + TextColumn col6Value = (TextColumn) getColumnWithMinValue(COL_NAME6, DataType.TEXT); + BlobColumn col7Value = (BlobColumn) getColumnWithMinValue(COL_NAME7, DataType.BLOB); Put put = - new Put(new Key(partitionKeyValue)) - .withValue(col1Value) - .withValue(col2Value) - .withValue(col3Value) - .withValue(col4Value) - .withValue(col5Value) - .withValue(col6Value) - .withValue(col7Value) - .forNamespace(namespace) - .forTable(TABLE); - + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .value(col1Value) + .value(col2Value) + .value(col3Value) + .value(col4Value) + .value(col5Value) + .value(col6Value) + .value(col7Value) + .build(); // Act storage.put(put); // Assert - Optional actual = - storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE)); - assertThat(actual).isPresent(); - assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue(); - assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue); - assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value); - assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value); - assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value); - assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value); - assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value); - assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value); - assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value); - - assertThat(actual.get().getContainedColumnNames()) - .isEqualTo( - new HashSet<>( - Arrays.asList( - PARTITION_KEY, - COL_NAME1, - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME7))); - - assertThat(actual.get().contains(PARTITION_KEY)).isTrue(); - assertThat(actual.get().isNull(PARTITION_KEY)).isFalse(); - assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - - assertThat(actual.get().contains(COL_NAME1)).isTrue(); - assertThat(actual.get().isNull(COL_NAME1)).isFalse(); - assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get()); - assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get()); - - assertThat(actual.get().contains(COL_NAME2)).isTrue(); - assertThat(actual.get().isNull(COL_NAME2)).isFalse(); - assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get()); - assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get()); - - assertThat(actual.get().contains(COL_NAME3)).isTrue(); - assertThat(actual.get().isNull(COL_NAME3)).isFalse(); - assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get()); - assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get()); - - assertThat(actual.get().contains(COL_NAME4)).isTrue(); - assertThat(actual.get().isNull(COL_NAME4)).isFalse(); - assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get()); - assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get()); - - assertThat(actual.get().contains(COL_NAME5)).isTrue(); - assertThat(actual.get().isNull(COL_NAME5)).isFalse(); - assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get()); - assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get()); - - assertThat(actual.get().contains(COL_NAME6)).isTrue(); - assertThat(actual.get().isNull(COL_NAME6)).isFalse(); - assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get()); - assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get()); - - assertThat(actual.get().contains(COL_NAME7)).isTrue(); - assertThat(actual.get().isNull(COL_NAME7)).isFalse(); - assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get())); - assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)) - .isEqualTo(ByteBuffer.wrap(col7Value.get().get())); - assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get()); - assertThat(actual.get().getAsObject(COL_NAME7)) - .isEqualTo(ByteBuffer.wrap(col7Value.get().get())); + assertResult( + partitionKeyValue, + col1Value, + col2Value, + col3Value, + col4Value, + col5Value, + col6Value, + col7Value); } @Test public void put_WithNullValues_ShouldPutCorrectly() throws ExecutionException { // Arrange - IntValue partitionKeyValue = new IntValue(PARTITION_KEY, 1); - BooleanValue col1Value = new BooleanValue(COL_NAME1, false); - IntValue col2Value = new IntValue(COL_NAME2, 0); - BigIntValue col3Value = new BigIntValue(COL_NAME3, 0L); - FloatValue col4Value = new FloatValue(COL_NAME4, 0.0f); - DoubleValue col5Value = new DoubleValue(COL_NAME5, 0.0d); - TextValue col6Value = new TextValue(COL_NAME6, (String) null); - BlobValue col7Value = new BlobValue(COL_NAME7, (byte[]) null); + IntColumn partitionKeyValue = IntColumn.of(PARTITION_KEY, 1); + BooleanColumn col1Value = BooleanColumn.ofNull(COL_NAME1); + IntColumn col2Value = IntColumn.ofNull(COL_NAME2); + BigIntColumn col3Value = BigIntColumn.ofNull(COL_NAME3); + FloatColumn col4Value = FloatColumn.ofNull(COL_NAME4); + DoubleColumn col5Value = DoubleColumn.ofNull(COL_NAME5); + TextColumn col6Value = TextColumn.ofNull(COL_NAME6); + BlobColumn col7Value = BlobColumn.ofNull(COL_NAME7); Put put = - new Put(new Key(partitionKeyValue)) - .withBooleanValue(COL_NAME1, null) - .withIntValue(COL_NAME2, null) - .withBigIntValue(COL_NAME3, null) - .withFloatValue(COL_NAME4, null) - .withDoubleValue(COL_NAME5, null) - .withTextValue(COL_NAME6, null) - .withBlobValue(COL_NAME7, (ByteBuffer) null) - .forNamespace(namespace) - .forTable(TABLE); - + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .value(col1Value) + .value(col2Value) + .value(col3Value) + .value(col4Value) + .value(col5Value) + .value(col6Value) + .value(col7Value) + .build(); // Act storage.put(put); // Assert - Optional actual = - storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE)); - assertThat(actual).isPresent(); - assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue(); - assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue); - assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value); - assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value); - assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value); - assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value); - assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value); - assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value); - assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value); - - assertThat(actual.get().getContainedColumnNames()) - .isEqualTo( - new HashSet<>( - Arrays.asList( - PARTITION_KEY, - COL_NAME1, - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME7))); - - assertThat(actual.get().contains(PARTITION_KEY)).isTrue(); - assertThat(actual.get().isNull(PARTITION_KEY)).isFalse(); - assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - - assertThat(actual.get().contains(COL_NAME1)).isTrue(); - assertThat(actual.get().isNull(COL_NAME1)).isTrue(); - assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get()); - assertThat(actual.get().getAsObject(COL_NAME1)).isNull(); - - assertThat(actual.get().contains(COL_NAME2)).isTrue(); - assertThat(actual.get().isNull(COL_NAME2)).isTrue(); - assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get()); - assertThat(actual.get().getAsObject(COL_NAME2)).isNull(); - - assertThat(actual.get().contains(COL_NAME3)).isTrue(); - assertThat(actual.get().isNull(COL_NAME3)).isTrue(); - assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get()); - assertThat(actual.get().getAsObject(COL_NAME3)).isNull(); - - assertThat(actual.get().contains(COL_NAME4)).isTrue(); - assertThat(actual.get().isNull(COL_NAME4)).isTrue(); - assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get()); - assertThat(actual.get().getAsObject(COL_NAME4)).isNull(); - - assertThat(actual.get().contains(COL_NAME5)).isTrue(); - assertThat(actual.get().isNull(COL_NAME5)).isTrue(); - assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get()); - assertThat(actual.get().getAsObject(COL_NAME5)).isNull(); - - assertThat(actual.get().contains(COL_NAME6)).isTrue(); - assertThat(actual.get().isNull(COL_NAME6)).isTrue(); - assertThat(actual.get().getText(COL_NAME6)).isNull(); - assertThat(actual.get().getAsObject(COL_NAME6)).isNull(); - - assertThat(actual.get().contains(COL_NAME7)).isTrue(); - assertThat(actual.get().isNull(COL_NAME7)).isTrue(); - assertThat(actual.get().getBlob(COL_NAME7)).isNull(); - assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isNull(); - assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isNull(); - assertThat(actual.get().getAsObject(COL_NAME7)).isNull(); + assertResult( + partitionKeyValue, + col1Value, + col2Value, + col3Value, + col4Value, + col5Value, + col6Value, + col7Value); } @Test public void put_WithNullValues_AfterPuttingRandomValues_ShouldPutCorrectly() throws ExecutionException { // Arrange - IntValue partitionKeyValue = new IntValue(PARTITION_KEY, 1); - BooleanValue col1Value = new BooleanValue(COL_NAME1, false); - IntValue col2Value = new IntValue(COL_NAME2, 0); - BigIntValue col3Value = new BigIntValue(COL_NAME3, 0L); - FloatValue col4Value = new FloatValue(COL_NAME4, 0.0f); - DoubleValue col5Value = new DoubleValue(COL_NAME5, 0.0d); - TextValue col6Value = new TextValue(COL_NAME6, (String) null); - BlobValue col7Value = new BlobValue(COL_NAME7, (byte[]) null); + IntColumn partitionKeyValue = IntColumn.of(PARTITION_KEY, 1); + BooleanColumn col1Value = BooleanColumn.ofNull(COL_NAME1); + IntColumn col2Value = IntColumn.ofNull(COL_NAME2); + BigIntColumn col3Value = BigIntColumn.ofNull(COL_NAME3); + FloatColumn col4Value = FloatColumn.ofNull(COL_NAME4); + DoubleColumn col5Value = DoubleColumn.ofNull(COL_NAME5); + TextColumn col6Value = TextColumn.ofNull(COL_NAME6); + BlobColumn col7Value = BlobColumn.ofNull(COL_NAME7); Put putForRandomValues = - new Put(new Key(partitionKeyValue)) - .withValue(getRandomValue(random, COL_NAME1, DataType.BOOLEAN)) - .withValue(getRandomValue(random, COL_NAME2, DataType.INT)) - .withValue(getRandomValue(random, COL_NAME3, DataType.BIGINT)) - .withValue(getRandomValue(random, COL_NAME4, DataType.FLOAT)) - .withValue(getRandomValue(random, COL_NAME5, DataType.DOUBLE)) - .withValue(getRandomValue(random, COL_NAME6, DataType.TEXT)) - .withValue(getRandomValue(random, COL_NAME7, DataType.BLOB)) - .forNamespace(namespace) - .forTable(TABLE); - + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .value(getColumnWithRandomValue(random, COL_NAME1, DataType.BOOLEAN)) + .value(getColumnWithRandomValue(random, COL_NAME2, DataType.INT)) + .value(getColumnWithRandomValue(random, COL_NAME3, DataType.BIGINT)) + .value(getColumnWithRandomValue(random, COL_NAME4, DataType.FLOAT)) + .value(getColumnWithRandomValue(random, COL_NAME5, DataType.DOUBLE)) + .value(getColumnWithRandomValue(random, COL_NAME6, DataType.TEXT)) + .value(getColumnWithRandomValue(random, COL_NAME7, DataType.BLOB)) + .build(); Put putForNullValues = - new Put(new Key(partitionKeyValue)) - .withBooleanValue(COL_NAME1, null) - .withIntValue(COL_NAME2, null) - .withBigIntValue(COL_NAME3, null) - .withFloatValue(COL_NAME4, null) - .withDoubleValue(COL_NAME5, null) - .withTextValue(COL_NAME6, null) - .withBlobValue(COL_NAME7, (ByteBuffer) null) - .forNamespace(namespace) - .forTable(TABLE); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .value(col1Value) + .value(col2Value) + .value(col3Value) + .value(col4Value) + .value(col5Value) + .value(col6Value) + .value(col7Value) + .build(); // Act storage.put(putForRandomValues); storage.put(putForNullValues); // Assert - Optional actual = - storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE)); - assertThat(actual).isPresent(); - assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue(); - assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue); - assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value); - assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value); - assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value); - assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value); - assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value); - assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value); - assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value); - - assertThat(actual.get().getContainedColumnNames()) - .isEqualTo( - new HashSet<>( - Arrays.asList( - PARTITION_KEY, - COL_NAME1, - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME7))); - - assertThat(actual.get().contains(PARTITION_KEY)).isTrue(); - assertThat(actual.get().isNull(PARTITION_KEY)).isFalse(); - assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - - assertThat(actual.get().contains(COL_NAME1)).isTrue(); - assertThat(actual.get().isNull(COL_NAME1)).isTrue(); - assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get()); - assertThat(actual.get().getAsObject(COL_NAME1)).isNull(); - - assertThat(actual.get().contains(COL_NAME2)).isTrue(); - assertThat(actual.get().isNull(COL_NAME2)).isTrue(); - assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get()); - assertThat(actual.get().getAsObject(COL_NAME2)).isNull(); - - assertThat(actual.get().contains(COL_NAME3)).isTrue(); - assertThat(actual.get().isNull(COL_NAME3)).isTrue(); - assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get()); - assertThat(actual.get().getAsObject(COL_NAME3)).isNull(); - - assertThat(actual.get().contains(COL_NAME4)).isTrue(); - assertThat(actual.get().isNull(COL_NAME4)).isTrue(); - assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get()); - assertThat(actual.get().getAsObject(COL_NAME4)).isNull(); - - assertThat(actual.get().contains(COL_NAME5)).isTrue(); - assertThat(actual.get().isNull(COL_NAME5)).isTrue(); - assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get()); - assertThat(actual.get().getAsObject(COL_NAME5)).isNull(); - - assertThat(actual.get().contains(COL_NAME6)).isTrue(); - assertThat(actual.get().isNull(COL_NAME6)).isTrue(); - assertThat(actual.get().getText(COL_NAME6)).isNull(); - assertThat(actual.get().getAsObject(COL_NAME6)).isNull(); - - assertThat(actual.get().contains(COL_NAME7)).isTrue(); - assertThat(actual.get().isNull(COL_NAME7)).isTrue(); - assertThat(actual.get().getBlob(COL_NAME7)).isNull(); - assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isNull(); - assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isNull(); - assertThat(actual.get().getAsObject(COL_NAME7)).isNull(); + assertResult( + partitionKeyValue, + col1Value, + col2Value, + col3Value, + col4Value, + col5Value, + col6Value, + col7Value); } @Test public void put_WithoutValues_ShouldPutCorrectly() throws ExecutionException { // Arrange - IntValue partitionKeyValue = new IntValue(PARTITION_KEY, 1); - BooleanValue col1Value = new BooleanValue(COL_NAME1, false); - IntValue col2Value = new IntValue(COL_NAME2, 0); - BigIntValue col3Value = new BigIntValue(COL_NAME3, 0L); - FloatValue col4Value = new FloatValue(COL_NAME4, 0.0f); - DoubleValue col5Value = new DoubleValue(COL_NAME5, 0.0d); - TextValue col6Value = new TextValue(COL_NAME6, (String) null); - BlobValue col7Value = new BlobValue(COL_NAME7, (byte[]) null); + IntColumn partitionKeyValue = IntColumn.of(PARTITION_KEY, 1); + BooleanColumn col1Value = BooleanColumn.ofNull(COL_NAME1); + IntColumn col2Value = IntColumn.ofNull(COL_NAME2); + BigIntColumn col3Value = BigIntColumn.ofNull(COL_NAME3); + FloatColumn col4Value = FloatColumn.ofNull(COL_NAME4); + DoubleColumn col5Value = DoubleColumn.ofNull(COL_NAME5); + TextColumn col6Value = TextColumn.ofNull(COL_NAME6); + BlobColumn col7Value = BlobColumn.ofNull(COL_NAME7); - Put put = new Put(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE); + Put put = + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .build(); // Act storage.put(put); // Assert - Optional actual = - storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE)); - assertThat(actual).isPresent(); - assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue(); - assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue); - assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value); - assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value); - assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value); - assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value); - assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value); - assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value); - assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value); - - assertThat(actual.get().getContainedColumnNames()) - .isEqualTo( - new HashSet<>( - Arrays.asList( - PARTITION_KEY, - COL_NAME1, - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME7))); - - assertThat(actual.get().contains(PARTITION_KEY)).isTrue(); - assertThat(actual.get().isNull(PARTITION_KEY)).isFalse(); - assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get()); - - assertThat(actual.get().contains(COL_NAME1)).isTrue(); - assertThat(actual.get().isNull(COL_NAME1)).isTrue(); - assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get()); - assertThat(actual.get().getAsObject(COL_NAME1)).isNull(); - - assertThat(actual.get().contains(COL_NAME2)).isTrue(); - assertThat(actual.get().isNull(COL_NAME2)).isTrue(); - assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get()); - assertThat(actual.get().getAsObject(COL_NAME2)).isNull(); - - assertThat(actual.get().contains(COL_NAME3)).isTrue(); - assertThat(actual.get().isNull(COL_NAME3)).isTrue(); - assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get()); - assertThat(actual.get().getAsObject(COL_NAME3)).isNull(); - - assertThat(actual.get().contains(COL_NAME4)).isTrue(); - assertThat(actual.get().isNull(COL_NAME4)).isTrue(); - assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get()); - assertThat(actual.get().getAsObject(COL_NAME4)).isNull(); - - assertThat(actual.get().contains(COL_NAME5)).isTrue(); - assertThat(actual.get().isNull(COL_NAME5)).isTrue(); - assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get()); - assertThat(actual.get().getAsObject(COL_NAME5)).isNull(); - - assertThat(actual.get().contains(COL_NAME6)).isTrue(); - assertThat(actual.get().isNull(COL_NAME6)).isTrue(); - assertThat(actual.get().getText(COL_NAME6)).isNull(); - assertThat(actual.get().getAsObject(COL_NAME6)).isNull(); - - assertThat(actual.get().contains(COL_NAME7)).isTrue(); - assertThat(actual.get().isNull(COL_NAME7)).isTrue(); - assertThat(actual.get().getBlob(COL_NAME7)).isNull(); - assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isNull(); - assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isNull(); - assertThat(actual.get().getAsObject(COL_NAME7)).isNull(); + assertResult( + partitionKeyValue, + col1Value, + col2Value, + col3Value, + col4Value, + col5Value, + col6Value, + col7Value); + } + + private void assertResult( + IntColumn partitionKeyValue, + BooleanColumn col1Value, + IntColumn col2Value, + BigIntColumn col3Value, + FloatColumn col4Value, + DoubleColumn col5Value, + TextColumn col6Value, + BlobColumn col7Value) + throws ExecutionException { + Optional actualOpt = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey( + Key.ofInt(partitionKeyValue.getName(), partitionKeyValue.getIntValue())) + .build()); + + assertThat(actualOpt).isPresent(); + Result actual = actualOpt.get(); + + assertThat(actual.contains(PARTITION_KEY)).isTrue(); + assertThat(actual.getColumns().get(PARTITION_KEY)).isEqualTo(partitionKeyValue); + assertThat(actual.contains(COL_NAME1)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME1)).isEqualTo(col1Value); + assertThat(actual.contains(COL_NAME2)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME2)).isEqualTo(col2Value); + assertThat(actual.contains(COL_NAME3)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME3)).isEqualTo(col3Value); + assertThat(actual.contains(COL_NAME4)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME4)).isEqualTo(col4Value); + assertThat(actual.contains(COL_NAME5)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME5)).isEqualTo(col5Value); + assertThat(actual.contains(COL_NAME6)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME6)).isEqualTo(col6Value); + assertThat(actual.contains(COL_NAME7)).isTrue(); + assertThat(actual.getColumns().get(COL_NAME7)).isEqualTo(col7Value); + + assertThat(actual.getContainedColumnNames()) + .containsExactlyInAnyOrder( + PARTITION_KEY, + COL_NAME1, + COL_NAME2, + COL_NAME3, + COL_NAME4, + COL_NAME5, + COL_NAME6, + COL_NAME7); + + assertThat(actual.contains(PARTITION_KEY)).isTrue(); + assertThat(actual.isNull(PARTITION_KEY)).isFalse(); + assertThat(actual.getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.getIntValue()); + assertThat(actual.getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.getIntValue()); + + assertThat(actual.contains(COL_NAME1)).isTrue(); + assertThat(actual.isNull(COL_NAME1)).isEqualTo(col1Value.hasNullValue()); + assertThat(actual.getBoolean(COL_NAME1)).isEqualTo(col1Value.getBooleanValue()); + assertThat(actual.getAsObject(COL_NAME1)) + .isEqualTo(col1Value.hasNullValue() ? null : col1Value.getBooleanValue()); + + assertThat(actual.contains(COL_NAME2)).isTrue(); + assertThat(actual.isNull(COL_NAME2)).isEqualTo(col2Value.hasNullValue()); + assertThat(actual.getInt(COL_NAME2)).isEqualTo(col2Value.getIntValue()); + assertThat(actual.getAsObject(COL_NAME2)) + .isEqualTo(col2Value.hasNullValue() ? null : col2Value.getIntValue()); + + assertThat(actual.contains(COL_NAME3)).isTrue(); + assertThat(actual.isNull(COL_NAME3)).isEqualTo(col3Value.hasNullValue()); + assertThat(actual.getBigInt(COL_NAME3)).isEqualTo(col3Value.getBigIntValue()); + assertThat(actual.getAsObject(COL_NAME3)) + .isEqualTo(col3Value.hasNullValue() ? null : col3Value.getBigIntValue()); + + assertThat(actual.contains(COL_NAME4)).isTrue(); + assertThat(actual.isNull(COL_NAME4)).isEqualTo(col4Value.hasNullValue()); + assertThat(actual.getFloat(COL_NAME4)).isEqualTo(col4Value.getFloatValue()); + assertThat(actual.getAsObject(COL_NAME4)) + .isEqualTo(col4Value.hasNullValue() ? null : col4Value.getFloatValue()); + + assertThat(actual.contains(COL_NAME5)).isTrue(); + assertThat(actual.isNull(COL_NAME5)).isEqualTo(col5Value.hasNullValue()); + assertThat(actual.getDouble(COL_NAME5)).isEqualTo(col5Value.getDoubleValue()); + assertThat(actual.getAsObject(COL_NAME5)) + .isEqualTo(col5Value.hasNullValue() ? null : col5Value.getDoubleValue()); + + assertThat(actual.contains(COL_NAME6)).isTrue(); + assertThat(actual.isNull(COL_NAME6)).isEqualTo(col6Value.hasNullValue()); + assertThat(actual.getText(COL_NAME6)).isEqualTo(col6Value.getTextValue()); + assertThat(actual.getAsObject(COL_NAME6)).isEqualTo(col6Value.getTextValue()); + + assertThat(actual.contains(COL_NAME7)).isTrue(); + assertThat(actual.isNull(COL_NAME7)).isEqualTo(col7Value.hasNullValue()); + assertThat(actual.getBlob(COL_NAME7)).isEqualTo(col7Value.getBlobValue()); + assertThat(actual.getBlobAsByteBuffer(COL_NAME7)).isEqualTo(col7Value.getBlobValue()); + assertThat(actual.getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.getBlobValueAsBytes()); + assertThat(actual.getAsObject(COL_NAME7)).isEqualTo(col7Value.getBlobValueAsByteBuffer()); } - protected Value getRandomValue(Random random, String columnName, DataType dataType) { - return TestUtils.getRandomValue(random, columnName, dataType, true); + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return TestUtils.getColumnWithRandomValue(random, columnName, dataType, true); } - protected Value getMinValue(String columnName, DataType dataType) { - return TestUtils.getMinValue(columnName, dataType, true); + protected Column getColumnWithMinValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMinValue(columnName, dataType, true); } - protected Value getMaxValue(String columnName, DataType dataType) { - return TestUtils.getMaxValue(columnName, dataType); + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMaxValue(columnName, dataType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java index e71373399d..0870c7b752 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java @@ -1129,20 +1129,22 @@ private Put preparePutWithRandomValues( DataType firstDataType, @Nullable Operator secondOperator, @Nullable DataType secondDataType) { - return new Put( + return Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey( Key.ofText( PARTITION_KEY, getPartitionKeyValue(firstOperator, firstDataType, secondOperator, secondDataType))) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME1, DataType.BOOLEAN)) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME2, DataType.INT)) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME3, DataType.BIGINT)) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME4, DataType.FLOAT)) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME5, DataType.DOUBLE)) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME6, DataType.TEXT)) - .withValue(getColumnWithRandomValue(random.get(), COL_NAME7, DataType.BLOB)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(namespace) - .forTable(TABLE); + .value(getColumnWithRandomValue(random.get(), COL_NAME1, DataType.BOOLEAN)) + .value(getColumnWithRandomValue(random.get(), COL_NAME2, DataType.INT)) + .value(getColumnWithRandomValue(random.get(), COL_NAME3, DataType.BIGINT)) + .value(getColumnWithRandomValue(random.get(), COL_NAME4, DataType.FLOAT)) + .value(getColumnWithRandomValue(random.get(), COL_NAME5, DataType.DOUBLE)) + .value(getColumnWithRandomValue(random.get(), COL_NAME6, DataType.TEXT)) + .value(getColumnWithRandomValue(random.get(), COL_NAME7, DataType.BLOB)) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Delete prepareDelete() { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java index 58665ab71a..3fdf68eebd 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java @@ -24,7 +24,6 @@ import com.scalar.db.io.Key; import com.scalar.db.io.TextColumn; import com.scalar.db.service.StorageFactory; -import com.scalar.db.util.ScalarDbUtils; import com.scalar.db.util.TestUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -118,7 +117,7 @@ protected int getThreadNum() { } protected Column getRandomColumn(Random random, String columnName, DataType dataType) { - return ScalarDbUtils.toColumn(TestUtils.getRandomValue(random, columnName, dataType)); + return TestUtils.getColumnWithRandomValue(random, columnName, dataType); } private String getNamespaceName() { @@ -237,8 +236,7 @@ private List prepareRecords(DataType firstColumnType, DataType secondColu List puts = new ArrayList<>(); if (firstColumnType == DataType.BOOLEAN) { - TestUtils.booleanValues(COL_NAME1).stream() - .map(ScalarDbUtils::toColumn) + TestUtils.booleanColumns(COL_NAME1) .forEach( firstColumn -> prepareRecords(firstColumnType, firstColumn, secondColumnType, puts, ret)); @@ -277,8 +275,7 @@ private void prepareRecords( List puts, List ret) { if (secondColumnType == DataType.BOOLEAN) { - TestUtils.booleanValues(COL_NAME2).stream() - .map(ScalarDbUtils::toColumn) + TestUtils.booleanColumns(COL_NAME2).stream() .forEach( secondColumn -> { ret.add(new Tuple(firstColumn, secondColumn)); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java index b6d054ec37..a1837383c1 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java @@ -5,12 +5,12 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ComparisonChain; import com.google.common.collect.ListMultimap; -import com.scalar.db.api.Scan.Ordering; import com.scalar.db.api.Scan.Ordering.Order; +import com.scalar.db.api.ScanBuilder.BuildableScanWithPartitionKey; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.service.StorageFactory; import com.scalar.db.util.TestUtils; import edu.umd.cs.findbugs.annotations.Nullable; @@ -568,9 +568,9 @@ private void scan_WithFirstClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProp throws ExecutionException, IOException { // Arrange ClusteringKey startClusteringKey = - new ClusteringKey(getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); + new ClusteringKey(getColumnWithMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); ClusteringKey endClusteringKey = - new ClusteringKey(getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); + new ClusteringKey(getColumnWithMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); List expected = getExpected( clusteringKeys, @@ -725,7 +725,7 @@ private void scan_WithFirstClusteringKeyStartRangeWithMinValue_ShouldReturnPrope throws ExecutionException, IOException { // Arrange ClusteringKey startClusteringKey = - new ClusteringKey(getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); + new ClusteringKey(getColumnWithMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); List expected = getExpected(clusteringKeys, startClusteringKey, startInclusive, null, null, orderingType); @@ -874,7 +874,7 @@ private void scan_WithFirstClusteringKeyEndRangeWithMaxValue_ShouldReturnProperR throws ExecutionException, IOException { // Arrange ClusteringKey endClusteringKey = - new ClusteringKey(getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); + new ClusteringKey(getColumnWithMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)); List expected = getExpected(clusteringKeys, null, null, endClusteringKey, endInclusive, orderingType); @@ -957,13 +957,13 @@ private void scan_WithSecondClusteringKeyRange_ShouldReturnProperResult( throws ExecutionException, IOException { // Arrange if (firstClusteringKeyType == DataType.BOOLEAN) { - Value firstClusteringKeyValue = clusteringKeys.get(0).first; + Column firstClusteringKeyValue = clusteringKeys.get(0).first; clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); } else { - Value firstClusteringKeyValue = + Column firstClusteringKeyValue = clusteringKeys.get(getFirstClusteringKeyIndex(2, secondClusteringKeyType)).first; clusteringKeys = clusteringKeys.stream() @@ -1073,13 +1073,13 @@ private void scan_WithSecondClusteringKeyRangeWithSameValues_ShouldReturnProperR throws ExecutionException, IOException { // Arrange if (firstClusteringKeyType == DataType.BOOLEAN) { - Value firstClusteringKeyValue = clusteringKeys.get(0).first; + Column firstClusteringKeyValue = clusteringKeys.get(0).first; clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); } else { - Value firstClusteringKeyValue = + Column firstClusteringKeyValue = clusteringKeys.get(getFirstClusteringKeyIndex(2, secondClusteringKeyType)).first; clusteringKeys = clusteringKeys.stream() @@ -1187,20 +1187,22 @@ private void scan_WithSecondClusteringKeyRangeWithMinAndMaxValues_ShouldReturnPr boolean withLimit) throws ExecutionException, IOException { // Arrange - Value firstClusteringKeyValue = + Column firstClusteringKeyValue = useMinValueForFirstClusteringKeyValue - ? getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType) - : getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType); + ? getColumnWithMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType) + : getColumnWithMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType); clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); ClusteringKey startClusteringKey = new ClusteringKey( - firstClusteringKeyValue, getMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); + firstClusteringKeyValue, + getColumnWithMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); ClusteringKey endClusteringKey = new ClusteringKey( - firstClusteringKeyValue, getMaxValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); + firstClusteringKeyValue, + getColumnWithMaxValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); List expected = getExpected( clusteringKeys, @@ -1285,13 +1287,13 @@ private void scan_WithSecondClusteringKeyStartRange_ShouldReturnProperResult( throws ExecutionException, IOException { // Arrange if (firstClusteringKeyType == DataType.BOOLEAN) { - Value firstClusteringKeyValue = clusteringKeys.get(0).first; + Column firstClusteringKeyValue = clusteringKeys.get(0).first; clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); } else { - Value firstClusteringKeyValue = + Column firstClusteringKeyValue = clusteringKeys.get(getFirstClusteringKeyIndex(2, secondClusteringKeyType)).first; clusteringKeys = clusteringKeys.stream() @@ -1385,14 +1387,16 @@ private void scan_WithSecondClusteringKeyStartRangeWithMinValue_ShouldReturnProp boolean withLimit) throws ExecutionException, IOException { // Arrange - Value firstClusteringKeyValue = getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType); + Column firstClusteringKeyValue = + getColumnWithMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType); clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); ClusteringKey startClusteringKey = new ClusteringKey( - firstClusteringKeyValue, getMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); + firstClusteringKeyValue, + getColumnWithMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); List expected = getExpected(clusteringKeys, startClusteringKey, startInclusive, null, null, orderingType); @@ -1471,13 +1475,13 @@ private void scan_WithSecondClusteringKeyEndRange_ShouldReturnProperResult( throws ExecutionException, IOException { // Arrange if (firstClusteringKeyType == DataType.BOOLEAN) { - Value firstClusteringKeyValue = clusteringKeys.get(0).first; + Column firstClusteringKeyValue = clusteringKeys.get(0).first; clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); } else { - Value firstClusteringKeyValue = + Column firstClusteringKeyValue = clusteringKeys.get(getFirstClusteringKeyIndex(2, secondClusteringKeyType)).first; clusteringKeys = clusteringKeys.stream() @@ -1571,14 +1575,16 @@ private void scan_WithSecondClusteringKeyEndRangeWithMaxValue_ShouldReturnProper boolean withLimit) throws ExecutionException, IOException { // Arrange - Value firstClusteringKeyValue = getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType); + Column firstClusteringKeyValue = + getColumnWithMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType); clusteringKeys = clusteringKeys.stream() .filter(c -> c.first.equals(firstClusteringKeyValue)) .collect(Collectors.toList()); ClusteringKey endClusteringKey = new ClusteringKey( - firstClusteringKeyValue, getMaxValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); + firstClusteringKeyValue, + getColumnWithMaxValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)); List expected = getExpected(clusteringKeys, null, null, endClusteringKey, endInclusive, orderingType); @@ -1629,7 +1635,7 @@ private List prepareRecords( List puts = new ArrayList<>(); if (firstClusteringKeyType == DataType.BOOLEAN) { - TestUtils.booleanValues(FIRST_CLUSTERING_KEY) + TestUtils.booleanColumns(FIRST_CLUSTERING_KEY) .forEach( firstClusteringKeyValue -> prepareRecords( @@ -1641,12 +1647,12 @@ private List prepareRecords( puts, ret)); } else { - Set> valueSet = new HashSet<>(); + Set> valueSet = new HashSet<>(); // Add min and max first clustering key values Arrays.asList( - getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType), - getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)) + getColumnWithMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType), + getColumnWithMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)) .forEach( firstClusteringKeyValue -> { valueSet.add(firstClusteringKeyValue); @@ -1663,7 +1669,7 @@ private List prepareRecords( IntStream.range(0, FIRST_CLUSTERING_KEY_NUM - 2) .forEach( i -> { - Value firstClusteringKeyValue; + Column firstClusteringKeyValue; while (true) { firstClusteringKeyValue = getFirstClusteringKeyValue(firstClusteringKeyType); // reject duplication @@ -1705,13 +1711,13 @@ private List prepareRecords( private void prepareRecords( DataType firstClusteringKeyType, Order firstClusteringOrder, - Value firstClusteringKeyValue, + Column firstClusteringKeyValue, DataType secondClusteringKeyType, Order secondClusteringOrder, List puts, List ret) { if (secondClusteringKeyType == DataType.BOOLEAN) { - TestUtils.booleanValues(SECOND_CLUSTERING_KEY) + TestUtils.booleanColumns(SECOND_CLUSTERING_KEY) .forEach( secondClusteringKeyValue -> { ret.add(new ClusteringKey(firstClusteringKeyValue, secondClusteringKeyValue)); @@ -1725,12 +1731,12 @@ private void prepareRecords( secondClusteringKeyValue)); }); } else { - Set> valueSet = new HashSet<>(); + Set> valueSet = new HashSet<>(); // min and max second clustering key values Arrays.asList( - getMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType), - getMaxValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)) + getColumnWithMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType), + getColumnWithMaxValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType)) .forEach( secondClusteringKeyValue -> { ret.add(new ClusteringKey(firstClusteringKeyValue, secondClusteringKeyValue)); @@ -1746,10 +1752,11 @@ private void prepareRecords( }); for (int i = 0; i < SECOND_CLUSTERING_KEY_NUM - 2; i++) { - Value secondClusteringKeyValue; + Column secondClusteringKeyValue; while (true) { secondClusteringKeyValue = - getRandomValue(random.get(), SECOND_CLUSTERING_KEY, secondClusteringKeyType); + getColumnWithRandomValue( + random.get(), SECOND_CLUSTERING_KEY, secondClusteringKeyType); // reject duplication if (!valueSet.contains(secondClusteringKeyValue)) { valueSet.add(secondClusteringKeyValue); @@ -1773,19 +1780,23 @@ private void prepareRecords( private Put preparePut( DataType firstClusteringKeyType, Order firstClusteringOrder, - Value firstClusteringKeyValue, + Column firstClusteringKeyValue, DataType secondClusteringKeyType, Order secondClusteringOrder, - Value secondClusteringKeyValue) { - return new Put(getPartitionKey(), new Key(firstClusteringKeyValue, secondClusteringKeyValue)) - .withValue(COL_NAME, 1) - .forNamespace(getNamespaceName(firstClusteringKeyType)) - .forTable( + Column secondClusteringKeyValue) { + return Put.newBuilder() + .namespace(getNamespaceName(firstClusteringKeyType)) + .table( getTableName( firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, - secondClusteringOrder)); + secondClusteringOrder)) + .partitionKey(getPartitionKey()) + .clusteringKey( + Key.newBuilder().add(firstClusteringKeyValue).add(secondClusteringKeyValue).build()) + .intValue(COL_NAME, 1) + .build(); } private int getFirstClusteringKeyIndex(int i, DataType secondClusteringKeyType) { @@ -1823,23 +1834,24 @@ private String description( } private Key getPartitionKey() { - return new Key(PARTITION_KEY, 1); + return Key.ofInt(PARTITION_KEY, 1); } - private Value getFirstClusteringKeyValue(DataType dataType) { - return getRandomValue(random.get(), FIRST_CLUSTERING_KEY, dataType); + private Column getFirstClusteringKeyValue(DataType dataType) { + return getColumnWithRandomValue(random.get(), FIRST_CLUSTERING_KEY, dataType); } - protected Value getRandomValue(Random random, String columnName, DataType dataType) { - return TestUtils.getRandomValue(random, columnName, dataType); + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return TestUtils.getColumnWithRandomValue(random, columnName, dataType); } - protected Value getMinValue(String columnName, DataType dataType) { - return TestUtils.getMinValue(columnName, dataType); + protected Column getColumnWithMinValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMinValue(columnName, dataType); } - protected Value getMaxValue(String columnName, DataType dataType) { - return TestUtils.getMaxValue(columnName, dataType); + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMaxValue(columnName, dataType); } private List scanAll(Scan scan) throws ExecutionException, IOException { @@ -1901,50 +1913,54 @@ private Scan getScan( @Nullable Boolean endInclusive, OrderingType orderingType, int limit) { - Scan scan = - new Scan(getPartitionKey()) - .forNamespace(getNamespaceName(firstClusteringKeyType)) - .forTable( + BuildableScanWithPartitionKey scan = + Scan.newBuilder() + .namespace(getNamespaceName(firstClusteringKeyType)) + .table( getTableName( firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, - secondClusteringOrder)); + secondClusteringOrder)) + .partitionKey(getPartitionKey()); if (startClusteringKey != null && startInclusive != null) { Key key; if (startClusteringKey.second != null) { - key = new Key(startClusteringKey.first, startClusteringKey.second); + key = Key.newBuilder().add(startClusteringKey.first).add(startClusteringKey.second).build(); } else { - key = new Key(startClusteringKey.first); + key = Key.newBuilder().add(startClusteringKey.first).build(); } - scan.withStart(key, startInclusive); + scan.start(key, startInclusive); } if (endClusteringKey != null && endInclusive != null) { Key key; if (endClusteringKey.second != null) { - key = new Key(endClusteringKey.first, endClusteringKey.second); + key = Key.newBuilder().add(endClusteringKey.first).add(endClusteringKey.second).build(); } else { - key = new Key(endClusteringKey.first); + key = Key.newBuilder().add(endClusteringKey.first).build(); } - scan.withEnd(key, endInclusive); + scan.end(key, endInclusive); } switch (orderingType) { case BOTH_SPECIFIED: - scan.withOrdering(new Ordering(FIRST_CLUSTERING_KEY, firstClusteringOrder)) - .withOrdering(new Ordering(SECOND_CLUSTERING_KEY, secondClusteringOrder)); + scan.orderings( + TestUtils.getOrdering(FIRST_CLUSTERING_KEY, firstClusteringOrder), + TestUtils.getOrdering(SECOND_CLUSTERING_KEY, secondClusteringOrder)); break; case ONLY_FIRST_SPECIFIED: - scan.withOrdering(new Ordering(FIRST_CLUSTERING_KEY, firstClusteringOrder)); + scan.ordering(TestUtils.getOrdering(FIRST_CLUSTERING_KEY, firstClusteringOrder)); break; case BOTH_SPECIFIED_AND_REVERSED: - scan.withOrdering( - new Ordering(FIRST_CLUSTERING_KEY, TestUtils.reverseOrder(firstClusteringOrder))) - .withOrdering( - new Ordering(SECOND_CLUSTERING_KEY, TestUtils.reverseOrder(secondClusteringOrder))); + scan.orderings( + TestUtils.getOrdering( + FIRST_CLUSTERING_KEY, TestUtils.reverseOrder(firstClusteringOrder)), + TestUtils.getOrdering( + SECOND_CLUSTERING_KEY, TestUtils.reverseOrder(secondClusteringOrder))); break; case ONLY_FIRST_SPECIFIED_AND_REVERSED: - scan.withOrdering( - new Ordering(FIRST_CLUSTERING_KEY, TestUtils.reverseOrder(firstClusteringOrder))); + scan.ordering( + TestUtils.getOrdering( + FIRST_CLUSTERING_KEY, TestUtils.reverseOrder(firstClusteringOrder))); break; case NOTHING: break; @@ -1952,21 +1968,21 @@ private Scan getScan( throw new AssertionError(); } if (limit > 0) { - scan.withLimit(limit); + scan.limit(limit); } - return scan; + return scan.build(); } private void assertScanResult( List actualResults, List expected, String description) { List actual = new ArrayList<>(); for (Result actualResult : actualResults) { - assertThat(actualResult.getValue(FIRST_CLUSTERING_KEY).isPresent()).isTrue(); - assertThat(actualResult.getValue(SECOND_CLUSTERING_KEY).isPresent()).isTrue(); + assertThat(actualResult.contains(FIRST_CLUSTERING_KEY)).isTrue(); + assertThat(actualResult.contains(SECOND_CLUSTERING_KEY)).isTrue(); actual.add( new ClusteringKey( - actualResult.getValue(FIRST_CLUSTERING_KEY).get(), - actualResult.getValue(SECOND_CLUSTERING_KEY).get())); + actualResult.getColumns().get(FIRST_CLUSTERING_KEY), + actualResult.getColumns().get(SECOND_CLUSTERING_KEY))); } assertThat(actual).describedAs(description).isEqualTo(expected); } @@ -2103,15 +2119,15 @@ void execute( } private static class ClusteringKey implements Comparable { - public final Value first; - @Nullable public final Value second; + public final Column first; + @Nullable public final Column second; - public ClusteringKey(Value first, @Nullable Value second) { + public ClusteringKey(Column first, @Nullable Column second) { this.first = first; this.second = second; } - public ClusteringKey(Value first) { + public ClusteringKey(Column first) { this(first, null); } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java index e34ae7e704..9310ead18f 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java @@ -3,9 +3,9 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.service.StorageFactory; import com.scalar.db.util.TestUtils; import java.util.ArrayList; @@ -268,28 +268,25 @@ public void getAndDelete_ShouldBehaveCorrectly() throws ExecutionException { partitionKey.second); // Act - Optional result = storage.get(get); + Optional resultOpt = storage.get(get); // Assert - Assertions.assertThat(result).describedAs(description).isPresent(); - Assertions.assertThat(result.get().getValue(FIRST_PARTITION_KEY).isPresent()) + Assertions.assertThat(resultOpt).describedAs(description).isPresent(); + Result result = resultOpt.get(); + Assertions.assertThat(result.contains(FIRST_PARTITION_KEY)) .describedAs(description) .isTrue(); - Assertions.assertThat(result.get().getValue(FIRST_PARTITION_KEY).get()) + Assertions.assertThat(result.getColumns().get(FIRST_PARTITION_KEY)) .describedAs(description) .isEqualTo(partitionKey.first); - Assertions.assertThat(result.get().getValue(SECOND_PARTITION_KEY).isPresent()) + Assertions.assertThat(result.contains(SECOND_PARTITION_KEY)) .describedAs(description) .isTrue(); - Assertions.assertThat(result.get().getValue(SECOND_PARTITION_KEY).get()) + Assertions.assertThat(result.getColumns().get(SECOND_PARTITION_KEY)) .describedAs(description) .isEqualTo(partitionKey.second); - Assertions.assertThat(result.get().getValue(COL_NAME).isPresent()) - .describedAs(description) - .isTrue(); - Assertions.assertThat(result.get().getValue(COL_NAME).get().getAsInt()) - .describedAs(description) - .isEqualTo(1); + Assertions.assertThat(result.contains(COL_NAME)).describedAs(description).isTrue(); + Assertions.assertThat(result.getInt(COL_NAME)).describedAs(description).isEqualTo(1); } // for delete @@ -325,7 +322,7 @@ private List prepareRecords( List ret = new ArrayList<>(); if (firstPartitionKeyType == DataType.BOOLEAN) { - TestUtils.booleanValues(FIRST_PARTITION_KEY) + TestUtils.booleanColumns(FIRST_PARTITION_KEY) .forEach( firstPartitionKeyValue -> prepareRecords( @@ -335,12 +332,12 @@ private List prepareRecords( puts, ret)); } else { - Set> valueSet = new HashSet<>(); + Set> valueSet = new HashSet<>(); // Add min and max partition key values Arrays.asList( - getMinValue(FIRST_PARTITION_KEY, firstPartitionKeyType), - getMaxValue(FIRST_PARTITION_KEY, firstPartitionKeyType)) + getColumnWithMinValue(FIRST_PARTITION_KEY, firstPartitionKeyType), + getColumnWithMaxValue(FIRST_PARTITION_KEY, firstPartitionKeyType)) .forEach( firstPartitionKeyValue -> { valueSet.add(firstPartitionKeyValue); @@ -355,10 +352,10 @@ private List prepareRecords( IntStream.range(0, FIRST_PARTITION_KEY_NUM - 2) .forEach( i -> { - Value firstPartitionKeyValue; + Column firstPartitionKeyValue; while (true) { firstPartitionKeyValue = - getRandomValue(random, FIRST_PARTITION_KEY, firstPartitionKeyType); + getColumnWithRandomValue(random, FIRST_PARTITION_KEY, firstPartitionKeyType); // reject duplication if (!valueSet.contains(firstPartitionKeyValue)) { valueSet.add(firstPartitionKeyValue); @@ -385,12 +382,12 @@ private List prepareRecords( private void prepareRecords( DataType firstPartitionKeyType, - Value firstPartitionKeyValue, + Column firstPartitionKeyValue, DataType secondPartitionKeyType, List puts, List ret) { if (secondPartitionKeyType == DataType.BOOLEAN) { - TestUtils.booleanValues(SECOND_PARTITION_KEY) + TestUtils.booleanColumns(SECOND_PARTITION_KEY) .forEach( secondPartitionKeyValue -> { ret.add(new PartitionKey(firstPartitionKeyValue, secondPartitionKeyValue)); @@ -402,12 +399,12 @@ private void prepareRecords( secondPartitionKeyValue)); }); } else { - Set> valueSet = new HashSet<>(); + Set> valueSet = new HashSet<>(); // min and max second partition key values Arrays.asList( - getMinValue(SECOND_PARTITION_KEY, secondPartitionKeyType), - getMaxValue(SECOND_PARTITION_KEY, secondPartitionKeyType)) + getColumnWithMinValue(SECOND_PARTITION_KEY, secondPartitionKeyType), + getColumnWithMaxValue(SECOND_PARTITION_KEY, secondPartitionKeyType)) .forEach( secondPartitionKeyValue -> { ret.add(new PartitionKey(firstPartitionKeyValue, secondPartitionKeyValue)); @@ -422,8 +419,8 @@ private void prepareRecords( for (int i = 0; i < SECOND_PARTITION_KEY_NUM - 2; i++) { while (true) { - Value secondPartitionKeyValue = - getRandomValue(random, SECOND_PARTITION_KEY, secondPartitionKeyType); + Column secondPartitionKeyValue = + getColumnWithRandomValue(random, SECOND_PARTITION_KEY, secondPartitionKeyType); // reject duplication if (!valueSet.contains(secondPartitionKeyValue)) { ret.add(new PartitionKey(firstPartitionKeyValue, secondPartitionKeyValue)); @@ -443,33 +440,42 @@ private void prepareRecords( private Put preparePut( DataType firstPartitionKeyType, - Value firstPartitionKeyValue, + Column firstPartitionKeyValue, DataType secondPartitionKeyType, - Value secondPartitionKeyValue) { - return new Put(new Key(firstPartitionKeyValue, secondPartitionKeyValue)) - .withValue(COL_NAME, 1) - .forNamespace(getNamespaceName(firstPartitionKeyType)) - .forTable(getTableName(firstPartitionKeyType, secondPartitionKeyType)); + Column secondPartitionKeyValue) { + return Put.newBuilder() + .namespace(getNamespaceName(firstPartitionKeyType)) + .table(getTableName(firstPartitionKeyType, secondPartitionKeyType)) + .partitionKey( + Key.newBuilder().add(firstPartitionKeyValue).add(secondPartitionKeyValue).build()) + .intValue(COL_NAME, 1) + .build(); } private Get prepareGet( DataType firstPartitionKeyType, - Value firstPartitionKeyValue, + Column firstPartitionKeyValue, DataType secondPartitionKeyType, - Value secondPartitionKeyValue) { - return new Get(new Key(firstPartitionKeyValue, secondPartitionKeyValue)) - .forNamespace(getNamespaceName(firstPartitionKeyType)) - .forTable(getTableName(firstPartitionKeyType, secondPartitionKeyType)); + Column secondPartitionKeyValue) { + return Get.newBuilder() + .namespace(getNamespaceName(firstPartitionKeyType)) + .table(getTableName(firstPartitionKeyType, secondPartitionKeyType)) + .partitionKey( + Key.newBuilder().add(firstPartitionKeyValue).add(secondPartitionKeyValue).build()) + .build(); } private Delete prepareDelete( DataType firstPartitionKeyType, - Value firstPartitionKeyValue, + Column firstPartitionKeyValue, DataType secondPartitionKeyType, - Value secondPartitionKeyValue) { - return new Delete(new Key(firstPartitionKeyValue, secondPartitionKeyValue)) - .forNamespace(getNamespaceName(firstPartitionKeyType)) - .forTable(getTableName(firstPartitionKeyType, secondPartitionKeyType)); + Column secondPartitionKeyValue) { + return Delete.newBuilder() + .namespace(getNamespaceName(firstPartitionKeyType)) + .table(getTableName(firstPartitionKeyType, secondPartitionKeyType)) + .partitionKey( + Key.newBuilder().add(firstPartitionKeyValue).add(secondPartitionKeyValue).build()) + .build(); } private String description(DataType firstPartitionKeyType, DataType secondPartitionKeyType) { @@ -478,23 +484,24 @@ private String description(DataType firstPartitionKeyType, DataType secondPartit firstPartitionKeyType, secondPartitionKeyType); } - protected Value getRandomValue(Random random, String columnName, DataType dataType) { - return TestUtils.getRandomValue(random, columnName, dataType); + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return TestUtils.getColumnWithRandomValue(random, columnName, dataType); } - protected Value getMinValue(String columnName, DataType dataType) { - return TestUtils.getMinValue(columnName, dataType); + protected Column getColumnWithMinValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMinValue(columnName, dataType); } - protected Value getMaxValue(String columnName, DataType dataType) { - return TestUtils.getMaxValue(columnName, dataType); + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMaxValue(columnName, dataType); } private static class PartitionKey { - public final Value first; - public final Value second; + public final Column first; + public final Column second; - public PartitionKey(Value first, Value second) { + public PartitionKey(Column first, Column second) { this.first = first; this.second = second; } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java index ea3235d20f..57f0330390 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java @@ -3,9 +3,9 @@ import static org.assertj.core.api.Assertions.assertThat; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.service.StorageFactory; import com.scalar.db.util.TestUtils; import java.io.IOException; @@ -150,12 +150,15 @@ public void scan_WithRandomSecondaryIndexValue_ShouldReturnProperResult() for (int i = 0; i < ATTEMPT_COUNT; i++) { // Arrange - Value secondaryIndexValue = getRandomValue(random, INDEX_COL_NAME, secondaryIndexType); + Column secondaryIndexValue = + getColumnWithRandomValue(random, INDEX_COL_NAME, secondaryIndexType); prepareRecords(secondaryIndexType, secondaryIndexValue); Scan scan = - new Scan(new Key(secondaryIndexValue)) - .forNamespace(namespace) - .forTable(getTableName(secondaryIndexType)); + Scan.newBuilder() + .namespace(namespace) + .table(getTableName(secondaryIndexType)) + .partitionKey(Key.newBuilder().add(secondaryIndexValue).build()) + .build(); // Act List results = scanAll(scan); @@ -174,12 +177,14 @@ public void scan_WithMaxSecondaryIndexValue_ShouldReturnProperResult() truncateTable(secondaryIndexType); // Arrange - Value secondaryIndexValue = getMaxValue(INDEX_COL_NAME, secondaryIndexType); + Column secondaryIndexValue = getColumnWithMaxValue(INDEX_COL_NAME, secondaryIndexType); prepareRecords(secondaryIndexType, secondaryIndexValue); Scan scan = - new Scan(new Key(secondaryIndexValue)) - .forNamespace(namespace) - .forTable(getTableName(secondaryIndexType)); + Scan.newBuilder() + .namespace(namespace) + .table(getTableName(secondaryIndexType)) + .partitionKey(Key.newBuilder().add(secondaryIndexValue).build()) + .build(); // Act List results = scanAll(scan); @@ -197,12 +202,14 @@ public void scan_WithMinSecondaryIndexValue_ShouldReturnProperResult() truncateTable(secondaryIndexType); // Arrange - Value secondaryIndexValue = getMinValue(INDEX_COL_NAME, secondaryIndexType); + Column secondaryIndexValue = getColumnWithMinValue(INDEX_COL_NAME, secondaryIndexType); prepareRecords(secondaryIndexType, secondaryIndexValue); Scan scan = - new Scan(new Key(secondaryIndexValue)) - .forNamespace(namespace) - .forTable(getTableName(secondaryIndexType)); + Scan.newBuilder() + .namespace(namespace) + .table(getTableName(secondaryIndexType)) + .partitionKey(Key.newBuilder().add(secondaryIndexValue).build()) + .build(); // Act List results = scanAll(scan); @@ -219,13 +226,14 @@ public void scan_WithSecondaryIndexValueAndConjunctions_ShouldReturnProperResult truncateTable(secondaryIndexType); // Arrange - Value secondaryIndexValue = getRandomValue(random, INDEX_COL_NAME, secondaryIndexType); + Column secondaryIndexValue = + getColumnWithRandomValue(random, INDEX_COL_NAME, secondaryIndexType); prepareRecords(secondaryIndexType, secondaryIndexValue); Scan scan = Scan.newBuilder() .namespace(getNamespace()) .table(getTableName(secondaryIndexType)) - .indexKey(Key.ofInt(INDEX_COL_NAME, secondaryIndexValue.getAsInt())) + .indexKey(Key.ofInt(INDEX_COL_NAME, secondaryIndexValue.getIntValue())) .where(ConditionBuilder.column(PARTITION_KEY).isEqualToInt(1)) .or(ConditionBuilder.column(PARTITION_KEY).isEqualToInt(2)) .build(); @@ -238,27 +246,29 @@ public void scan_WithSecondaryIndexValueAndConjunctions_ShouldReturnProperResult assertThat(results.get(0).contains(PARTITION_KEY)).isTrue(); assertThat(results.get(0).getInt(PARTITION_KEY)).isEqualTo(1); assertThat(results.get(0).contains(INDEX_COL_NAME)).isTrue(); - assertThat(results.get(0).getInt(INDEX_COL_NAME)).isEqualTo(secondaryIndexValue.getAsInt()); + assertThat(results.get(0).getInt(INDEX_COL_NAME)).isEqualTo(secondaryIndexValue.getIntValue()); assertThat(results.get(1).contains(PARTITION_KEY)).isTrue(); assertThat(results.get(1).getInt(PARTITION_KEY)).isEqualTo(2); assertThat(results.get(1).contains(INDEX_COL_NAME)).isTrue(); - assertThat(results.get(1).getInt(INDEX_COL_NAME)).isEqualTo(secondaryIndexValue.getAsInt()); + assertThat(results.get(1).getInt(INDEX_COL_NAME)).isEqualTo(secondaryIndexValue.getIntValue()); } - private void prepareRecords(DataType secondaryIndexType, Value secondaryIndexValue) + private void prepareRecords(DataType secondaryIndexType, Column secondaryIndexValue) throws ExecutionException { for (int i = 0; i < DATA_NUM; i++) { Put put = - new Put(new Key(PARTITION_KEY, i)) - .withValue(secondaryIndexValue) - .withValue(COL_NAME, 1) - .forNamespace(namespace) - .forTable(getTableName(secondaryIndexType)); + Put.newBuilder() + .namespace(namespace) + .table(getTableName(secondaryIndexType)) + .partitionKey(Key.ofInt(PARTITION_KEY, i)) + .value(secondaryIndexValue) + .intValue(COL_NAME, 1) + .build(); storage.put(put); } } - private void assertResults(List results, Value secondaryIndexValue) { + private void assertResults(List results, Column secondaryIndexValue) { assertThat(results.size()).isEqualTo(DATA_NUM); Set partitionKeySet = new HashSet<>(); @@ -267,12 +277,12 @@ private void assertResults(List results, Value secondaryIndexValue) { } for (Result result : results) { - assertThat(result.getValue(PARTITION_KEY).isPresent()).isTrue(); - partitionKeySet.remove(result.getValue(PARTITION_KEY).get().getAsInt()); - assertThat(result.getValue(INDEX_COL_NAME).isPresent()).isTrue(); - assertThat(result.getValue(INDEX_COL_NAME).get()).isEqualTo(secondaryIndexValue); - assertThat(result.getValue(COL_NAME).isPresent()).isTrue(); - assertThat(result.getValue(COL_NAME).get().getAsInt()).isEqualTo(1); + assertThat(result.contains(PARTITION_KEY)).isTrue(); + partitionKeySet.remove(result.getInt(PARTITION_KEY)); + assertThat(result.contains(INDEX_COL_NAME)).isTrue(); + assertThat(result.getColumns().get(INDEX_COL_NAME)).isEqualTo(secondaryIndexValue); + assertThat(result.contains(COL_NAME)).isTrue(); + assertThat(result.getInt(COL_NAME)).isEqualTo(1); } assertThat(partitionKeySet).isEmpty(); @@ -284,15 +294,16 @@ private List scanAll(Scan scan) throws ExecutionException, IOException { } } - protected Value getRandomValue(Random random, String columnName, DataType dataType) { - return TestUtils.getRandomValue(random, columnName, dataType, true); + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return TestUtils.getColumnWithRandomValue(random, columnName, dataType, true); } - protected Value getMinValue(String columnName, DataType dataType) { - return TestUtils.getMinValue(columnName, dataType, true); + protected Column getColumnWithMinValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMinValue(columnName, dataType, true); } - protected Value getMaxValue(String columnName, DataType dataType) { - return TestUtils.getMaxValue(columnName, dataType); + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMaxValue(columnName, dataType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java index 932b95f680..7b6e7ae5ab 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java @@ -2,12 +2,11 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.scalar.db.api.Scan.Ordering; import com.scalar.db.api.Scan.Ordering.Order; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.service.StorageFactory; import com.scalar.db.util.TestUtils; import edu.umd.cs.findbugs.annotations.Nullable; @@ -166,7 +165,7 @@ public void scan_WithoutClusteringKeyRange_ShouldReturnProperResult() random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (OrderingType orderingType : OrderingType.values()) { for (boolean withLimit : Arrays.asList(false, true)) { scan_WithoutClusteringKeyRange_ShouldReturnProperResult( @@ -178,14 +177,14 @@ public void scan_WithoutClusteringKeyRange_ShouldReturnProperResult() } private void scan_WithoutClusteringKeyRange_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException { // Arrange - List> expected = + List> expected = getExpected(clusteringKeyValues, null, null, null, null, orderingType); int limit = getLimit(withLimit, expected); @@ -214,7 +213,7 @@ public void scan_WithClusteringKeyRange_ShouldReturnProperResult() random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean startInclusive : Arrays.asList(true, false)) { for (boolean endInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { @@ -236,7 +235,7 @@ public void scan_WithClusteringKeyRange_ShouldReturnProperResult() } private void scan_WithClusteringKeyRange_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, @@ -245,8 +244,8 @@ private void scan_WithClusteringKeyRange_ShouldReturnProperResult( boolean withLimit) throws ExecutionException, IOException { // Arrange - Value startClusteringKeyValue; - Value endClusteringKeyValue; + Column startClusteringKeyValue; + Column endClusteringKeyValue; if (clusteringKeyType == DataType.BOOLEAN) { startClusteringKeyValue = clusteringKeyValues.get(0); endClusteringKeyValue = clusteringKeyValues.get(1); @@ -255,7 +254,7 @@ private void scan_WithClusteringKeyRange_ShouldReturnProperResult( endClusteringKeyValue = clusteringKeyValues.get(14); } - List> expected = + List> expected = getExpected( clusteringKeyValues, startClusteringKeyValue, @@ -304,7 +303,7 @@ public void scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult() random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean startInclusive : Arrays.asList(true, false)) { for (boolean endInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { @@ -326,7 +325,7 @@ public void scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult() } private void scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, @@ -335,14 +334,14 @@ private void scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult( boolean withLimit) throws ExecutionException, IOException { // Arrange - Value startAndEndClusteringKeyValue; + Column startAndEndClusteringKeyValue; if (clusteringKeyType == DataType.BOOLEAN) { startAndEndClusteringKeyValue = clusteringKeyValues.get(0); } else { startAndEndClusteringKeyValue = clusteringKeyValues.get(9); } - List> expected = + List> expected = getExpected( clusteringKeyValues, startAndEndClusteringKeyValue, @@ -391,7 +390,7 @@ public void scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResu random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean startInclusive : Arrays.asList(true, false)) { for (boolean endInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { @@ -413,7 +412,7 @@ public void scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResu } private void scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, @@ -422,9 +421,9 @@ private void scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperRes boolean withLimit) throws ExecutionException, IOException { // Arrange - Value startClusteringKeyValue = getMinValue(CLUSTERING_KEY, clusteringKeyType); - Value endClusteringKeyValue = getMaxValue(CLUSTERING_KEY, clusteringKeyType); - List> expected = + Column startClusteringKeyValue = getColumnWithMinValue(CLUSTERING_KEY, clusteringKeyType); + Column endClusteringKeyValue = getColumnWithMaxValue(CLUSTERING_KEY, clusteringKeyType); + List> expected = getExpected( clusteringKeyValues, startClusteringKeyValue, @@ -473,7 +472,7 @@ public void scan_WithClusteringKeyStartRange_ShouldReturnProperResult() random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean startInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { for (boolean withLimit : Arrays.asList(false, true)) { @@ -492,7 +491,7 @@ public void scan_WithClusteringKeyStartRange_ShouldReturnProperResult() } private void scan_WithClusteringKeyStartRange_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, @@ -500,14 +499,14 @@ private void scan_WithClusteringKeyStartRange_ShouldReturnProperResult( boolean withLimit) throws ExecutionException, IOException { // Arrange - Value startClusteringKeyValue; + Column startClusteringKeyValue; if (clusteringKeyType == DataType.BOOLEAN) { startClusteringKeyValue = clusteringKeyValues.get(0); } else { startClusteringKeyValue = clusteringKeyValues.get(4); } - List> expected = + List> expected = getExpected( clusteringKeyValues, startClusteringKeyValue, startInclusive, null, null, orderingType); @@ -546,7 +545,7 @@ public void scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResul random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean startInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { for (boolean withLimit : Arrays.asList(false, true)) { @@ -565,7 +564,7 @@ public void scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResul } private void scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, @@ -573,8 +572,8 @@ private void scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResu boolean withLimit) throws ExecutionException, IOException { // Arrange - Value startClusteringKeyValue = getMinValue(CLUSTERING_KEY, clusteringKeyType); - List> expected = + Column startClusteringKeyValue = getColumnWithMinValue(CLUSTERING_KEY, clusteringKeyType); + List> expected = getExpected( clusteringKeyValues, startClusteringKeyValue, startInclusive, null, null, orderingType); @@ -613,7 +612,7 @@ public void scan_WithClusteringKeyEndRange_ShouldReturnProperResult() random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean endInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { for (boolean withLimit : Arrays.asList(false, true)) { @@ -632,7 +631,7 @@ public void scan_WithClusteringKeyEndRange_ShouldReturnProperResult() } private void scan_WithClusteringKeyEndRange_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean endInclusive, @@ -640,14 +639,14 @@ private void scan_WithClusteringKeyEndRange_ShouldReturnProperResult( boolean withLimit) throws ExecutionException, IOException { // Arrange - Value endClusteringKeyValue; + Column endClusteringKeyValue; if (clusteringKeyType == DataType.BOOLEAN) { endClusteringKeyValue = clusteringKeyValues.get(1); } else { endClusteringKeyValue = clusteringKeyValues.get(14); } - List> expected = + List> expected = getExpected( clusteringKeyValues, null, null, endClusteringKeyValue, endInclusive, orderingType); @@ -686,7 +685,7 @@ public void scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult( random.setSeed(seed); truncateTable(clusteringKeyType, clusteringOrder); - List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); + List> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder); for (boolean endInclusive : Arrays.asList(true, false)) { for (OrderingType orderingType : OrderingType.values()) { for (boolean withLimit : Arrays.asList(false, true)) { @@ -705,7 +704,7 @@ public void scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult( } private void scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult( - List> clusteringKeyValues, + List> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean endInclusive, @@ -713,8 +712,8 @@ private void scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult boolean withLimit) throws ExecutionException, IOException { // Arrange - Value endClusteringKey = getMaxValue(CLUSTERING_KEY, clusteringKeyType); - List> expected = + Column endClusteringKey = getColumnWithMaxValue(CLUSTERING_KEY, clusteringKeyType); + List> expected = getExpected(clusteringKeyValues, null, null, endClusteringKey, endInclusive, orderingType); int limit = getLimit(withLimit, expected); @@ -744,25 +743,25 @@ private void scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult clusteringKeyType, clusteringOrder, null, endInclusive, orderingType, withLimit)); } - private List> prepareRecords(DataType clusteringKeyType, Order clusteringOrder) + private List> prepareRecords(DataType clusteringKeyType, Order clusteringOrder) throws ExecutionException { - List> ret = new ArrayList<>(); + List> ret = new ArrayList<>(); List puts = new ArrayList<>(); if (clusteringKeyType == DataType.BOOLEAN) { - TestUtils.booleanValues(CLUSTERING_KEY) + TestUtils.booleanColumns(CLUSTERING_KEY) .forEach( clusteringKeyValue -> { ret.add(clusteringKeyValue); puts.add(preparePut(clusteringKeyType, clusteringOrder, clusteringKeyValue)); }); } else { - Set> valueSet = new HashSet<>(); + Set> valueSet = new HashSet<>(); // Add min and max clustering key values Arrays.asList( - getMinValue(CLUSTERING_KEY, clusteringKeyType), - getMaxValue(CLUSTERING_KEY, clusteringKeyType)) + getColumnWithMinValue(CLUSTERING_KEY, clusteringKeyType), + getColumnWithMaxValue(CLUSTERING_KEY, clusteringKeyType)) .forEach( clusteringKeyValue -> { valueSet.add(clusteringKeyValue); @@ -773,9 +772,10 @@ private List> prepareRecords(DataType clusteringKeyType, Order clusteri IntStream.range(0, CLUSTERING_KEY_NUM - 2) .forEach( i -> { - Value clusteringKeyValue; + Column clusteringKeyValue; while (true) { - clusteringKeyValue = getRandomValue(random, CLUSTERING_KEY, clusteringKeyType); + clusteringKeyValue = + getColumnWithRandomValue(random, CLUSTERING_KEY, clusteringKeyType); // reject duplication if (!valueSet.contains(clusteringKeyValue)) { valueSet.add(clusteringKeyValue); @@ -811,27 +811,31 @@ private List> prepareRecords(DataType clusteringKeyType, Order clusteri } private Put preparePut( - DataType clusteringKeyType, Order clusteringOrder, Value clusteringKeyValue) { - return new Put(getPartitionKey(), new Key(clusteringKeyValue)) - .withValue(COL_NAME, 1) - .forNamespace(namespace) - .forTable(getTableName(clusteringKeyType, clusteringOrder)); + DataType clusteringKeyType, Order clusteringOrder, Column clusteringKeyValue) { + return Put.newBuilder() + .namespace(namespace) + .table(getTableName(clusteringKeyType, clusteringOrder)) + .partitionKey(getPartitionKey()) + .clusteringKey(Key.newBuilder().add(clusteringKeyValue).build()) + .intValue(COL_NAME, 1) + .build(); } private Key getPartitionKey() { - return new Key(PARTITION_KEY, 1); + return Key.ofInt(PARTITION_KEY, 1); } - protected Value getRandomValue(Random random, String columnName, DataType dataType) { - return TestUtils.getRandomValue(random, columnName, dataType); + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return TestUtils.getColumnWithRandomValue(random, columnName, dataType); } - protected Value getMinValue(String columnName, DataType dataType) { - return TestUtils.getMinValue(columnName, dataType); + protected Column getColumnWithMinValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMinValue(columnName, dataType); } - protected Value getMaxValue(String columnName, DataType dataType) { - return TestUtils.getMaxValue(columnName, dataType); + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMaxValue(columnName, dataType); } private String description( @@ -862,15 +866,15 @@ private List scanAll(Scan scan) throws ExecutionException, IOException { } } - private List> getExpected( - List> clusteringKeyValues, - @Nullable Value startClusteringKeyValue, + private List> getExpected( + List> clusteringKeyValues, + @Nullable Column startClusteringKeyValue, @Nullable Boolean startInclusive, - @Nullable Value endClusteringKeyValue, + @Nullable Column endClusteringKeyValue, @Nullable Boolean endInclusive, OrderingType orderingType) { - List> ret = new ArrayList<>(); - for (Value clusteringKeyValue : clusteringKeyValues) { + List> ret = new ArrayList<>(); + for (Column clusteringKeyValue : clusteringKeyValues) { if (startClusteringKeyValue != null && startInclusive != null) { int compare = Objects.compare( @@ -899,7 +903,7 @@ private List> getExpected( return ret; } - private int getLimit(boolean withLimit, List> expected) { + private int getLimit(boolean withLimit, List> expected) { int limit = 0; if (withLimit && !expected.isEmpty()) { if (expected.size() == 1) { @@ -914,28 +918,30 @@ private int getLimit(boolean withLimit, List> expected) { private Scan getScan( DataType clusteringKeyType, Order clusteringOrder, - @Nullable Value startClusteringKeyValue, + @Nullable Column startClusteringKeyValue, @Nullable Boolean startInclusive, - @Nullable Value endClusteringKeyValue, + @Nullable Column endClusteringKeyValue, @Nullable Boolean endInclusive, OrderingType orderingType, int limit) { - Scan scan = - new Scan(getPartitionKey()) - .forNamespace(namespace) - .forTable(getTableName(clusteringKeyType, clusteringOrder)); + ScanBuilder.BuildableScanWithPartitionKey scan = + Scan.newBuilder() + .namespace(namespace) + .table(getTableName(clusteringKeyType, clusteringOrder)) + .partitionKey(getPartitionKey()); if (startClusteringKeyValue != null && startInclusive != null) { - scan.withStart(new Key(startClusteringKeyValue), startInclusive); + scan.start(Key.newBuilder().add(startClusteringKeyValue).build(), startInclusive); } if (endClusteringKeyValue != null && endInclusive != null) { - scan.withEnd(new Key(endClusteringKeyValue), endInclusive); + scan.end(Key.newBuilder().add(endClusteringKeyValue).build(), endInclusive); } switch (orderingType) { case SPECIFIED: - scan.withOrdering(new Ordering(CLUSTERING_KEY, clusteringOrder)); + scan.ordering(TestUtils.getOrdering(CLUSTERING_KEY, clusteringOrder)); break; case REVERSED: - scan.withOrdering(new Ordering(CLUSTERING_KEY, TestUtils.reverseOrder(clusteringOrder))); + scan.ordering( + TestUtils.getOrdering(CLUSTERING_KEY, TestUtils.reverseOrder(clusteringOrder))); break; case NOTHING: break; @@ -943,17 +949,17 @@ private Scan getScan( throw new AssertionError(); } if (limit > 0) { - scan.withLimit(limit); + scan.limit(limit); } - return scan; + return scan.build(); } private void assertScanResult( - List actualResults, List> expected, String description) { - List> actual = new ArrayList<>(); + List actualResults, List> expected, String description) { + List> actual = new ArrayList<>(); for (Result actualResult : actualResults) { - assertThat(actualResult.getValue(CLUSTERING_KEY).isPresent()).isTrue(); - actual.add(actualResult.getValue(CLUSTERING_KEY).get()); + assertThat(actualResult.contains(CLUSTERING_KEY)).isTrue(); + actual.add(actualResult.getColumns().get(CLUSTERING_KEY)); } assertThat(actual).describedAs(description).isEqualTo(expected); } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java index b43e43afae..50c4c1144e 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java @@ -3,9 +3,9 @@ import static org.assertj.core.api.Assertions.assertThat; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Column; import com.scalar.db.io.DataType; import com.scalar.db.io.Key; -import com.scalar.db.io.Value; import com.scalar.db.service.StorageFactory; import com.scalar.db.util.TestUtils; import java.io.IOException; @@ -154,59 +154,53 @@ public void getAndScanAndDelete_ShouldBehaveCorrectly() throws ExecutionExceptio random.setSeed(seed); truncateTable(partitionKeyType); - List> partitionKeyValues = prepareRecords(partitionKeyType); + List> partitionKeyValues = prepareRecords(partitionKeyType); String description = description(partitionKeyType); // for get - for (Value partitionKeyValue : partitionKeyValues) { + for (Column partitionKeyValue : partitionKeyValues) { // Arrange Get get = prepareGet(partitionKeyType, partitionKeyValue); // Act - Optional result = storage.get(get); + Optional optResult = storage.get(get); // Assert - assertThat(result).describedAs(description).isPresent(); - assertThat(result.get().getValue(PARTITION_KEY).isPresent()) - .describedAs(description) - .isTrue(); - assertThat(result.get().getValue(PARTITION_KEY).get()) + assertThat(optResult).describedAs(description).isPresent(); + Result result = optResult.get(); + assertThat(result.contains(PARTITION_KEY)).describedAs(description).isTrue(); + assertThat(result.getColumns().get(PARTITION_KEY)) .describedAs(description) .isEqualTo(partitionKeyValue); - assertThat(result.get().getValue(COL_NAME).isPresent()).describedAs(description).isTrue(); - assertThat(result.get().getValue(COL_NAME).get().getAsInt()) - .describedAs(description) - .isEqualTo(1); + assertThat(result.contains(COL_NAME)).describedAs(description).isTrue(); + assertThat(result.getInt(COL_NAME)).describedAs(description).isEqualTo(1); } // for scan - for (Value partitionKeyValue : partitionKeyValues) { + for (Column partitionKeyValue : partitionKeyValues) { // Arrange Scan scan = prepareScan(partitionKeyType, partitionKeyValue); // Act Assert try (Scanner scanner = storage.scan(scan)) { - Optional result = scanner.one(); + Optional optResult = scanner.one(); - assertThat(result).describedAs(description).isPresent(); - assertThat(result.get().getValue(PARTITION_KEY).isPresent()) - .describedAs(description) - .isTrue(); - assertThat(result.get().getValue(PARTITION_KEY).get()) + assertThat(optResult).describedAs(description).isPresent(); + Result result = optResult.get(); + assertThat(result.contains(PARTITION_KEY)).describedAs(description).isTrue(); + assertThat(result.getColumns().get(PARTITION_KEY)) .describedAs(description) .isEqualTo(partitionKeyValue); - assertThat(result.get().getValue(COL_NAME).isPresent()).describedAs(description).isTrue(); - assertThat(result.get().getValue(COL_NAME).get().getAsInt()) - .describedAs(description) - .isEqualTo(1); + assertThat(result.contains(COL_NAME)).describedAs(description).isTrue(); + assertThat(result.getInt(COL_NAME)).describedAs(description).isEqualTo(1); assertThat(scanner.one()).isNotPresent(); } } // for delete - for (Value partitionKeyValue : partitionKeyValues) { + for (Column partitionKeyValue : partitionKeyValues) { // Arrange Delete delete = prepareDelete(partitionKeyType, partitionKeyValue); @@ -220,24 +214,24 @@ public void getAndScanAndDelete_ShouldBehaveCorrectly() throws ExecutionExceptio } } - private List> prepareRecords(DataType partitionKeyType) throws ExecutionException { - List> ret = new ArrayList<>(); + private List> prepareRecords(DataType partitionKeyType) throws ExecutionException { + List> ret = new ArrayList<>(); List puts = new ArrayList<>(); if (partitionKeyType == DataType.BOOLEAN) { - TestUtils.booleanValues(PARTITION_KEY) + TestUtils.booleanColumns(PARTITION_KEY) .forEach( partitionKeyValue -> { ret.add(partitionKeyValue); puts.add(preparePut(partitionKeyType, partitionKeyValue)); }); } else { - Set> valueSet = new HashSet<>(); + Set> valueSet = new HashSet<>(); // Add min and max partition key values Arrays.asList( - getMinValue(PARTITION_KEY, partitionKeyType), - getMaxValue(PARTITION_KEY, partitionKeyType)) + getColumnWithMinValue(PARTITION_KEY, partitionKeyType), + getColumnWithMaxValue(PARTITION_KEY, partitionKeyType)) .forEach( partitionKeyValue -> { valueSet.add(partitionKeyValue); @@ -248,9 +242,10 @@ private List> prepareRecords(DataType partitionKeyType) throws Executio IntStream.range(0, PARTITION_KEY_NUM - 2) .forEach( i -> { - Value partitionKeyValue; + Column partitionKeyValue; while (true) { - partitionKeyValue = getRandomValue(random, PARTITION_KEY, partitionKeyType); + partitionKeyValue = + getColumnWithRandomValue(random, PARTITION_KEY, partitionKeyType); // reject duplication if (!valueSet.contains(partitionKeyValue)) { valueSet.add(partitionKeyValue); @@ -272,44 +267,53 @@ private List> prepareRecords(DataType partitionKeyType) throws Executio return ret; } - private Put preparePut(DataType partitionKeyType, Value partitionKeyValue) { - return new Put(new Key(partitionKeyValue)) - .withValue(COL_NAME, 1) - .forNamespace(namespace) - .forTable(getTableName(partitionKeyType)); + private Put preparePut(DataType partitionKeyType, Column partitionKeyValue) { + return Put.newBuilder() + .namespace(namespace) + .table(getTableName(partitionKeyType)) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .intValue(COL_NAME, 1) + .build(); } - private Get prepareGet(DataType partitionKeyType, Value partitionKeyValue) { - return new Get(new Key(partitionKeyValue)) - .forNamespace(namespace) - .forTable(getTableName(partitionKeyType)); + private Get prepareGet(DataType partitionKeyType, Column partitionKeyValue) { + return Get.newBuilder() + .namespace(namespace) + .table(getTableName(partitionKeyType)) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .build(); } - private Scan prepareScan(DataType partitionKeyType, Value partitionKeyValue) { - return new Scan(new Key(partitionKeyValue)) - .forNamespace(namespace) - .forTable(getTableName(partitionKeyType)); + private Scan prepareScan(DataType partitionKeyType, Column partitionKeyValue) { + return Scan.newBuilder() + .namespace(namespace) + .table(getTableName(partitionKeyType)) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .build(); } - private Delete prepareDelete(DataType partitionKeyType, Value partitionKeyValue) { - return new Delete(new Key(partitionKeyValue)) - .forNamespace(namespace) - .forTable(getTableName(partitionKeyType)); + private Delete prepareDelete(DataType partitionKeyType, Column partitionKeyValue) { + return Delete.newBuilder() + .namespace(namespace) + .table(getTableName(partitionKeyType)) + .partitionKey(Key.newBuilder().add(partitionKeyValue).build()) + .build(); } private String description(DataType partitionKeyType) { return String.format("failed with partitionKeyType: %s", partitionKeyType); } - protected Value getRandomValue(Random random, String columnName, DataType dataType) { - return TestUtils.getRandomValue(random, columnName, dataType); + protected Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return TestUtils.getColumnWithRandomValue(random, columnName, dataType); } - protected Value getMinValue(String columnName, DataType dataType) { - return TestUtils.getMinValue(columnName, dataType); + protected Column getColumnWithMinValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMinValue(columnName, dataType); } - protected Value getMaxValue(String columnName, DataType dataType) { - return TestUtils.getMaxValue(columnName, dataType); + protected Column getColumnWithMaxValue(String columnName, DataType dataType) { + return TestUtils.getColumnWithMaxValue(columnName, dataType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java index c08fb95b9e..33734b9165 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java @@ -432,6 +432,7 @@ public void truncateTable_ShouldTruncateProperly() .withValue(COL_NAME9, 1.0d) .withValue(COL_NAME10, true) .withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)) + // TODO add put values for data, time, timestamp and timestamptz .forNamespace(namespace1) .forTable(TABLE1)); @@ -532,7 +533,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") - // TODO add put values for data, time, timestamp and timestamptz + // TODO add put values for date, time, timestamp and timestamptz .build()); // Act @@ -717,6 +718,7 @@ public void dropIndex_ForAllDataTypesWithExistingData_ShouldDropIndexCorrectly() .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") + // TODO add put values for date, time, timestamp and timestamptz .build()); // Act diff --git a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java index de6b885460..0f1dba0f66 100644 --- a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java @@ -207,21 +207,26 @@ private void selection_WithIncludeMetadataEnabled_ShouldReturnCorrectColumns( } protected Get prepareGet(int id, int type) { - Key partitionKey = new Key(ACCOUNT_ID, id); - Key clusteringKey = new Key(ACCOUNT_TYPE, type); - return new Get(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + Key partitionKey = Key.ofInt(ACCOUNT_ID, id); + Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); + return Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected Scan prepareScan(int id, int fromType, int toType) { - Key partitionKey = new Key(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE) - .withStart(new Key(ACCOUNT_TYPE, fromType)) - .withEnd(new Key(ACCOUNT_TYPE, toType)); + Key partitionKey = Key.ofInt(ACCOUNT_ID, id); + return Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .start(Key.ofInt(ACCOUNT_TYPE, fromType)) + .end(Key.ofInt(ACCOUNT_TYPE, toType)) + .build(); } } diff --git a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java index 3bb041f96e..71d5526f58 100644 --- a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitWithIncludeMetadataEnabledIntegrationTestBase.java @@ -197,21 +197,26 @@ private void selection_WithIncludeMetadataEnabled_ShouldReturnCorrectColumns( } protected Get prepareGet(int id, int type) { - Key partitionKey = new Key(ACCOUNT_ID, id); - Key clusteringKey = new Key(ACCOUNT_TYPE, type); - return new Get(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + Key partitionKey = Key.ofInt(ACCOUNT_ID, id); + Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); + return Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected Scan prepareScan(int id, int fromType, int toType) { - Key partitionKey = new Key(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE) - .withStart(new Key(ACCOUNT_TYPE, fromType)) - .withEnd(new Key(ACCOUNT_TYPE, toType)); + Key partitionKey = Key.ofInt(ACCOUNT_ID, id); + return Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .start(Key.ofInt(ACCOUNT_TYPE, fromType)) + .end(Key.ofInt(ACCOUNT_TYPE, toType)) + .build(); } } diff --git a/integration-test/src/main/java/com/scalar/db/util/TestUtils.java b/integration-test/src/main/java/com/scalar/db/util/TestUtils.java index c885cb292f..1830e6d0eb 100644 --- a/integration-test/src/main/java/com/scalar/db/util/TestUtils.java +++ b/integration-test/src/main/java/com/scalar/db/util/TestUtils.java @@ -3,24 +3,18 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import com.scalar.db.api.Result; +import com.scalar.db.api.Scan.Ordering; import com.scalar.db.api.Scan.Ordering.Order; import com.scalar.db.io.BigIntColumn; import com.scalar.db.io.BigIntValue; import com.scalar.db.io.BlobColumn; -import com.scalar.db.io.BlobValue; import com.scalar.db.io.BooleanColumn; -import com.scalar.db.io.BooleanValue; import com.scalar.db.io.Column; import com.scalar.db.io.DataType; import com.scalar.db.io.DoubleColumn; -import com.scalar.db.io.DoubleValue; import com.scalar.db.io.FloatColumn; -import com.scalar.db.io.FloatValue; import com.scalar.db.io.IntColumn; -import com.scalar.db.io.IntValue; import com.scalar.db.io.TextColumn; -import com.scalar.db.io.TextValue; -import com.scalar.db.io.Value; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Arrays; @@ -38,37 +32,9 @@ public final class TestUtils { private TestUtils() {} - public static Value getRandomValue(Random random, String columnName, DataType dataType) { - return getRandomValue(random, columnName, dataType, false); - } - - public static Value getRandomValue( - Random random, String columnName, DataType dataType, boolean allowEmpty) { - switch (dataType) { - case BIGINT: - return new BigIntValue(columnName, nextBigInt(random)); - case INT: - return new IntValue(columnName, random.nextInt()); - case FLOAT: - return new FloatValue(columnName, nextFloat(random)); - case DOUBLE: - return new DoubleValue(columnName, nextDouble(random)); - case BLOB: - int length = - allowEmpty ? random.nextInt(MAX_BLOB_LENGTH) : random.nextInt(MAX_BLOB_LENGTH - 1) + 1; - byte[] bytes = new byte[length]; - random.nextBytes(bytes); - return new BlobValue(columnName, bytes); - case TEXT: - int count = - allowEmpty ? random.nextInt(MAX_TEXT_COUNT) : random.nextInt(MAX_TEXT_COUNT - 1) + 1; - return new TextValue( - columnName, RandomStringUtils.random(count, 0, 0, true, true, null, random)); - case BOOLEAN: - return new BooleanValue(columnName, random.nextBoolean()); - default: - throw new AssertionError(); - } + public static Column getColumnWithRandomValue( + Random random, String columnName, DataType dataType) { + return getColumnWithRandomValue(random, columnName, dataType, false); } public static Column getColumnWithRandomValue( @@ -117,58 +83,59 @@ public static double nextDouble(Random random) { return random.doubles(Double.MIN_VALUE, Double.MAX_VALUE).limit(1).findFirst().orElse(0.0d); } - public static Value getMinValue(String columnName, DataType dataType) { - return getMinValue(columnName, dataType, false); + public static Column getColumnWithMinValue(String columnName, DataType dataType) { + return getColumnWithMinValue(columnName, dataType, false); } - public static Value getMinValue(String columnName, DataType dataType, boolean allowEmpty) { + public static Column getColumnWithMinValue( + String columnName, DataType dataType, boolean allowEmpty) { switch (dataType) { case BIGINT: - return new BigIntValue(columnName, BigIntValue.MIN_VALUE); + return BigIntColumn.of(columnName, BigIntValue.MIN_VALUE); case INT: - return new IntValue(columnName, Integer.MIN_VALUE); + return IntColumn.of(columnName, Integer.MIN_VALUE); case FLOAT: - return new FloatValue(columnName, Float.MIN_VALUE); + return FloatColumn.of(columnName, Float.MIN_VALUE); case DOUBLE: - return new DoubleValue(columnName, Double.MIN_VALUE); + return DoubleColumn.of(columnName, Double.MIN_VALUE); case BLOB: - return new BlobValue(columnName, allowEmpty ? new byte[0] : new byte[] {0x00}); + return BlobColumn.of(columnName, allowEmpty ? new byte[0] : new byte[] {0x00}); case TEXT: - return new TextValue(columnName, allowEmpty ? "" : "\u0001"); + return TextColumn.of(columnName, allowEmpty ? "" : "\u0001"); case BOOLEAN: - return new BooleanValue(columnName, false); + return BooleanColumn.of(columnName, false); default: throw new AssertionError(); } } - public static Value getMaxValue(String columnName, DataType dataType) { + public static Column getColumnWithMaxValue(String columnName, DataType dataType) { switch (dataType) { case BIGINT: - return new BigIntValue(columnName, BigIntValue.MAX_VALUE); + return BigIntColumn.of(columnName, BigIntValue.MAX_VALUE); case INT: - return new IntValue(columnName, Integer.MAX_VALUE); + return IntColumn.of(columnName, Integer.MAX_VALUE); case FLOAT: - return new FloatValue(columnName, Float.MAX_VALUE); + return FloatColumn.of(columnName, Float.MAX_VALUE); case DOUBLE: - return new DoubleValue(columnName, Double.MAX_VALUE); + return DoubleColumn.of(columnName, Double.MAX_VALUE); case BLOB: byte[] blobBytes = new byte[MAX_BLOB_LENGTH]; Arrays.fill(blobBytes, (byte) 0xff); - return new BlobValue(columnName, blobBytes); + return BlobColumn.of(columnName, blobBytes); case TEXT: StringBuilder builder = new StringBuilder(); IntStream.range(0, MAX_TEXT_COUNT).forEach(i -> builder.append(Character.MAX_VALUE)); - return new TextValue(columnName, builder.toString()); + return TextColumn.of(columnName, builder.toString()); case BOOLEAN: - return new BooleanValue(columnName, true); + return BooleanColumn.of(columnName, true); default: throw new AssertionError(); } } - public static List booleanValues(String columnName) { - return Arrays.asList(new BooleanValue(columnName, false), new BooleanValue(columnName, true)); + public static List booleanColumns(String columnName) { + return Arrays.asList(BooleanColumn.of(columnName, false), BooleanColumn.of(columnName, true)); } public static Order reverseOrder(Order order) { @@ -182,6 +149,17 @@ public static Order reverseOrder(Order order) { } } + public static Ordering getOrdering(String columnName, Order order) { + switch (order) { + case ASC: + return Ordering.asc(columnName); + case DESC: + return Ordering.desc(columnName); + default: + throw new AssertionError(); + } + } + /** * Find and return an expected result that matches the result * From 4031a797c4ed7200c412367c1c4226c4eda1cdfe Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 7 Nov 2024 11:52:07 +0900 Subject: [PATCH 3/4] Rename variable --- ...butedStorageMultiplePartitionKeyIntegrationTestBase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java index 9310ead18f..d111a9e02a 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java @@ -268,11 +268,11 @@ public void getAndDelete_ShouldBehaveCorrectly() throws ExecutionException { partitionKey.second); // Act - Optional resultOpt = storage.get(get); + Optional optResult = storage.get(get); // Assert - Assertions.assertThat(resultOpt).describedAs(description).isPresent(); - Result result = resultOpt.get(); + Assertions.assertThat(optResult).describedAs(description).isPresent(); + Result result = optResult.get(); Assertions.assertThat(result.contains(FIRST_PARTITION_KEY)) .describedAs(description) .isTrue(); From 97f5c909d88bd415395aa99f4aa392352fc27c09 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 7 Nov 2024 16:10:54 +0900 Subject: [PATCH 4/4] Revert "Add time-related types to the Admin and Schema loader (#2301)" This reverts commit 93ce2fa3 --- .../CassandraAdminIntegrationTest.java | 5 - .../CassandraAdminRepairIntegrationTest.java | 5 - .../CassandraSchemaLoaderIntegrationTest.java | 5 - ...mmitAdminIntegrationTestWithCassandra.java | 5 - ...minRepairIntegrationTestWithCassandra.java | 5 - ...tionAdminIntegrationTestWithCassandra.java | 5 - ...tAdminRepairIntegrationTestWithCosmos.java | 2 +- .../CosmosAdminRepairIntegrationTest.java | 2 +- ...tipleClusteringKeyScanIntegrationTest.java | 4 +- ...ingleClusteringKeyScanIntegrationTest.java | 2 +- ...tipleClusteringKeyScanIntegrationTest.java | 4 +- ...moMultiplePartitionKeyIntegrationTest.java | 4 +- .../DynamoSecondaryIndexIntegrationTest.java | 2 +- ...ingleClusteringKeyScanIntegrationTest.java | 2 +- ...ltiStorageSchemaLoaderIntegrationTest.java | 5 - .../main/java/com/scalar/db/io/DataType.java | 15 +-- .../db/storage/cassandra/CassandraAdmin.java | 22 ---- .../scalar/db/storage/cosmos/CosmosAdmin.java | 8 -- .../scalar/db/storage/dynamo/DynamoAdmin.java | 12 -- .../db/storage/jdbc/RdbEngineMysql.java | 7 -- .../db/storage/jdbc/RdbEngineOracle.java | 7 -- .../db/storage/jdbc/RdbEnginePostgresql.java | 8 -- .../db/storage/jdbc/RdbEngineSqlServer.java | 8 -- .../db/storage/jdbc/RdbEngineSqlite.java | 4 - .../storage/cassandra/CassandraAdminTest.java | 22 +--- .../db/storage/cosmos/CosmosAdminTest.java | 49 +------- .../storage/dynamo/DynamoAdminTestBase.java | 16 --- .../scalar/db/storage/jdbc/JdbcAdminTest.java | 90 ++++----------- ...ibutedStorageAdminIntegrationTestBase.java | 97 ++-------------- ...StorageAdminRepairIntegrationTestBase.java | 82 +++++-------- ...onditionalMutationIntegrationTestBase.java | 2 +- ...CrossPartitionScanIntegrationTestBase.java | 4 +- ...eClusteringKeyScanIntegrationTestBase.java | 4 +- ...ltiplePartitionKeyIntegrationTestBase.java | 4 +- ...rageSecondaryIndexIntegrationTestBase.java | 2 +- ...eClusteringKeyScanIntegrationTestBase.java | 2 +- ...SinglePartitionKeyIntegrationTestBase.java | 2 +- ...edTransactionAdminIntegrationTestBase.java | 95 ++------------- ...sactionAdminRepairIntegrationTestBase.java | 82 +++++-------- .../SchemaLoaderIntegrationTestBase.java | 109 +++++++----------- .../scalar/db/schemaloader/TableSchema.java | 4 - .../db/schemaloader/TableSchemaTest.java | 16 +-- 42 files changed, 177 insertions(+), 653 deletions(-) diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java index 119b2ca2a3..f271bd47c2 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminIntegrationTest.java @@ -21,9 +21,4 @@ protected Map getCreationOptions() { protected AdminTestUtils getAdminTestUtils(String testName) { return new CassandraAdminTestUtils(getProperties(testName)); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java index 5246591bb9..99514b2b1c 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminRepairIntegrationTest.java @@ -28,9 +28,4 @@ protected void initialize(String testName) { admin = new CassandraAdmin(clusterManager, new DatabaseConfig(properties)); adminTestUtils = new CassandraAdminTestUtils(properties, clusterManager); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java index 29315b5e81..2b3a76c0a7 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraSchemaLoaderIntegrationTest.java @@ -54,9 +54,4 @@ protected List getCommandArgsForUpgrade(Path configFilePath) { .add("--replication-factor=1") .build(); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java index b0eb1c4bab..25b02a4636 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminIntegrationTestWithCassandra.java @@ -22,9 +22,4 @@ protected Map getCreationOptions() { protected AdminTestUtils getAdminTestUtils(String testName) { return new CassandraAdminTestUtils(getProperties(testName)); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java index 5a7ad0e31d..6ac91b5b4c 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/ConsensusCommitAdminRepairIntegrationTestWithCassandra.java @@ -30,9 +30,4 @@ protected void initialize(String testName) { admin = new ConsensusCommitAdmin(storageAdmin, new DatabaseConfig(properties)); adminTestUtils = new CassandraAdminTestUtils(getProperties(testName), clusterManager); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java index 4669045a58..aa46a16da0 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/SingleCrudOperationTransactionAdminIntegrationTestWithCassandra.java @@ -17,9 +17,4 @@ protected Properties getProps(String testName) { protected Map getCreationOptions() { return Collections.singletonMap(CassandraAdmin.REPLICATION_FACTOR, "1"); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java index 11d722ee33..4831239269 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminRepairIntegrationTestWithCosmos.java @@ -35,7 +35,7 @@ public void repairTable_ForTableWithoutStoredProcedure_ShouldCreateStoredProcedu cosmosAdminTestUtils.getTableStoredProcedure(getNamespace(), getTable()).delete(); // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThatCode( diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java index fc1426f2ee..039f934aa2 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminRepairIntegrationTest.java @@ -35,7 +35,7 @@ public void repairTable_ForTableWithoutStoredProcedure_ShouldCreateStoredProcedu cosmosAdminTestUtils.getTableStoredProcedure(getNamespace(), getTable()).delete(); // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThatCode( diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java index 52465ad6a7..ad97f1a7c3 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosMultipleClusteringKeyScanIntegrationTest.java @@ -19,11 +19,11 @@ protected Properties getProperties(String testName) { protected ListMultimap getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType firstClusteringKeyType : DataType.values()) { if (firstClusteringKeyType == DataType.BLOB) { continue; } - for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType secondClusteringKeyType : DataType.values()) { if (secondClusteringKeyType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java index 17e6a6cc43..c3e77f4c1a 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosSingleClusteringKeyScanIntegrationTest.java @@ -18,7 +18,7 @@ protected Properties getProperties(String testName) { protected Set getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now Set clusteringKeyTypes = new HashSet<>(); - for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType dataType : DataType.values()) { if (dataType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java index 9669062f58..1b714d5a97 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultipleClusteringKeyScanIntegrationTest.java @@ -21,11 +21,11 @@ protected Properties getProperties(String testName) { protected ListMultimap getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType firstClusteringKeyType : DataType.values()) { if (firstClusteringKeyType == DataType.BLOB) { continue; } - for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType secondClusteringKeyType : DataType.values()) { if (secondClusteringKeyType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java index f16ebfe333..f9539ffa81 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoMultiplePartitionKeyIntegrationTest.java @@ -24,12 +24,12 @@ protected Map getCreationOptions() { @Override protected ListMultimap getPartitionKeyTypes() { ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType firstClusteringKeyType : DataType.values()) { // BLOB type is supported only for the last value in partition key if (firstClusteringKeyType == DataType.BLOB) { continue; } - for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType secondClusteringKeyType : DataType.values()) { clusteringKeyTypes.put(firstClusteringKeyType, secondClusteringKeyType); } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java index b0b1241183..e1f3dca0c5 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSecondaryIndexIntegrationTest.java @@ -21,7 +21,7 @@ protected Properties getProperties(String testName) { protected Set getSecondaryIndexTypes() { // Return types without BOOLEAN because boolean is not supported for secondary index for now Set clusteringKeyTypes = new HashSet<>(); - for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType dataType : DataType.values()) { if (dataType == DataType.BOOLEAN) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java index c703b6a076..55a0f21f67 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoSingleClusteringKeyScanIntegrationTest.java @@ -21,7 +21,7 @@ protected Properties getProperties(String testName) { protected Set getClusteringKeyTypes() { // Return types without BLOB because blob is not supported for clustering key for now Set clusteringKeyTypes = new HashSet<>(); - for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType dataType : DataType.values()) { if (dataType == DataType.BLOB) { continue; } diff --git a/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java index 6d9ccc111e..0fa2ab2293 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageSchemaLoaderIntegrationTest.java @@ -110,9 +110,4 @@ protected void waitForCreationIfNecessary() { // one session to the other, so we need to wait Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS); } - - @Override - protected boolean isTimestampTypeSupported() { - return false; - } } diff --git a/core/src/main/java/com/scalar/db/io/DataType.java b/core/src/main/java/com/scalar/db/io/DataType.java index a4d601d629..12d345efbf 100644 --- a/core/src/main/java/com/scalar/db/io/DataType.java +++ b/core/src/main/java/com/scalar/db/io/DataType.java @@ -1,7 +1,5 @@ package com.scalar.db.io; -import java.util.Arrays; - public enum DataType { BOOLEAN, INT, @@ -9,16 +7,5 @@ public enum DataType { FLOAT, DOUBLE, TEXT, - BLOB, - DATE, - TIME, - TIMESTAMP, - TIMESTAMPTZ; - - // Temporary added until the CRUD operations for time-related types is completed - public static DataType[] valuesWithoutTimesRelatedTypes() { - return Arrays.stream(values()) - .filter(type -> type != DATE && type != TIME && type != TIMESTAMP && type != TIMESTAMPTZ) - .toArray(DataType[]::new); - } + BLOB } diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java b/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java index 26ac81f940..94272f18f2 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java @@ -65,12 +65,6 @@ public CassandraAdmin(DatabaseConfig config) { public void createTable( String namespace, String table, TableMetadata metadata, Map options) throws ExecutionException { - for (String column : metadata.getColumnNames()) { - if (metadata.getColumnDataTypes().get(column).equals(DataType.TIMESTAMP)) { - throw new UnsupportedOperationException( - "The TIMESTAMP data type is not supported in Cassandra. column: " + column); - } - } try { createNamespacesTableIfNotExists(); createTableInternal(namespace, table, metadata, false, options); @@ -376,10 +370,6 @@ public void repairTable( public void addNewColumnToTable( String namespace, String table, String columnName, DataType columnType) throws ExecutionException { - if (columnType == DataType.TIMESTAMP) { - throw new UnsupportedOperationException( - "The TIMESTAMP data type is not supported in Cassandra. column: " + columnName); - } try { String alterTableQuery = SchemaBuilder.alterTable(namespace, table) @@ -593,12 +583,6 @@ private DataType fromCassandraDataType( return DataType.BOOLEAN; case BLOB: return DataType.BLOB; - case DATE: - return DataType.DATE; - case TIME: - return DataType.TIME; - case TIMESTAMP: - return DataType.TIMESTAMPTZ; default: throw new ExecutionException( String.format("%s is not yet supported", cassandraDataTypeName)); @@ -626,12 +610,6 @@ private com.datastax.driver.core.DataType toCassandraDataType(DataType dataType) return com.datastax.driver.core.DataType.text(); case BLOB: return com.datastax.driver.core.DataType.blob(); - case DATE: - return com.datastax.driver.core.DataType.date(); - case TIME: - return com.datastax.driver.core.DataType.time(); - case TIMESTAMPTZ: - return com.datastax.driver.core.DataType.timestamp(); default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java index 5f1962677d..8382abe010 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java @@ -518,14 +518,6 @@ private DataType convertDataType(String columnType) throws ExecutionException { return DataType.BOOLEAN; case "blob": return DataType.BLOB; - case "date": - return DataType.DATE; - case "time": - return DataType.TIME; - case "timestamp": - return DataType.TIMESTAMP; - case "timestamptz": - return DataType.TIMESTAMPTZ; default: throw new ExecutionException("Unknown column type: " + columnType); } diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java index 46c6dab220..b7d9b3d733 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java @@ -127,10 +127,6 @@ public class DynamoAdmin implements DistributedStorageAdmin { .put(DataType.DOUBLE, ScalarAttributeType.N) .put(DataType.TEXT, ScalarAttributeType.S) .put(DataType.BLOB, ScalarAttributeType.B) - .put(DataType.DATE, ScalarAttributeType.S) - .put(DataType.TIME, ScalarAttributeType.S) - .put(DataType.TIMESTAMP, ScalarAttributeType.S) - .put(DataType.TIMESTAMPTZ, ScalarAttributeType.S) .build(); private static final ImmutableSet TABLE_SCALING_TYPE_SET = ImmutableSet.builder().add(SCALING_TYPE_READ).add(SCALING_TYPE_WRITE).build(); @@ -1249,14 +1245,6 @@ private DataType convertDataType(String columnType) throws ExecutionException { return DataType.BOOLEAN; case "blob": return DataType.BLOB; - case "date": - return DataType.DATE; - case "time": - return DataType.TIME; - case "timestamp": - return DataType.TIMESTAMP; - case "timestamptz": - return DataType.TIMESTAMPTZ; default: throw new ExecutionException("Unknown column type: " + columnType); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java index 888b0a9bf9..643baebcf0 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineMysql.java @@ -203,13 +203,6 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "INT"; case TEXT: return "LONGTEXT"; - case DATE: - return "DATE"; - case TIME: - return "TIME"; - case TIMESTAMP: - case TIMESTAMPTZ: - return "DATETIME"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java index 2406400e26..4cba5d5b3b 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java @@ -210,13 +210,6 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "NUMBER(10)"; case TEXT: return "VARCHAR2(4000)"; - case DATE: - return "DATE"; - case TIME: - case TIMESTAMP: - return "TIMESTAMP"; - case TIMESTAMPTZ: - return "TIMESTAMP WITH TIME ZONE"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java index 4d49370506..c6020713d3 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEnginePostgresql.java @@ -197,14 +197,6 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "INT"; case TEXT: return "TEXT"; - case DATE: - return "DATE"; - case TIME: - return "TIME"; - case TIMESTAMP: - return "TIMESTAMP"; - case TIMESTAMPTZ: - return "TIMESTAMP WITH TIME ZONE"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java index 0f6930d6b3..b6d92a1055 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlServer.java @@ -177,14 +177,6 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { return "INT"; case TEXT: return "VARCHAR(8000)"; - case DATE: - return "DATE"; - case TIME: - return "TIME"; - case TIMESTAMP: - return "DATETIME2"; - case TIMESTAMPTZ: - return "DATETIMEOFFSET"; default: throw new AssertionError(); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java index 746791feb3..dce69fd267 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineSqlite.java @@ -92,10 +92,6 @@ public String getDataTypeForEngine(DataType scalarDbDataType) { case DOUBLE: return "DOUBLE"; case TEXT: - case DATE: - case TIME: - case TIMESTAMP: - case TIMESTAMPTZ: return "TEXT"; case BLOB: return "BLOB"; diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java index 987a216842..bfb0da5d87 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTest.java @@ -247,13 +247,8 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addColumn("c1", DataType.INT) .addColumn("c2", DataType.TEXT) .addColumn("c3", DataType.BLOB) - .addColumn("c4", DataType.BIGINT) + .addColumn("c4", DataType.INT) .addColumn("c5", DataType.BOOLEAN) - .addColumn("c6", DataType.DOUBLE) - .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMPTZ) .addSecondaryIndex("c2") .addSecondaryIndex("c4") .build(); @@ -265,15 +260,10 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { TableOptions createTableStatement = SchemaBuilder.createTable(namespace, table) .addPartitionKey("c1", com.datastax.driver.core.DataType.cint()) - .addClusteringColumn("c4", com.datastax.driver.core.DataType.bigint()) + .addClusteringColumn("c4", com.datastax.driver.core.DataType.cint()) .addColumn("c2", com.datastax.driver.core.DataType.text()) .addColumn("c3", com.datastax.driver.core.DataType.blob()) .addColumn("c5", com.datastax.driver.core.DataType.cboolean()) - .addColumn("c6", com.datastax.driver.core.DataType.cdouble()) - .addColumn("c7", com.datastax.driver.core.DataType.cfloat()) - .addColumn("c8", com.datastax.driver.core.DataType.date()) - .addColumn("c9", com.datastax.driver.core.DataType.time()) - .addColumn("c10", com.datastax.driver.core.DataType.timestamp()) .withOptions() .clusteringOrder("c4", Direction.ASC) .compactionOptions(SchemaBuilder.sizedTieredStategy()); @@ -293,7 +283,6 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addPartitionKey("c7") .addClusteringKey("c4") .addClusteringKey("c6", Order.DESC) - .addClusteringKey("c9", Order.ASC) .addColumn("c1", DataType.INT) .addColumn("c2", DataType.TEXT) .addColumn("c3", DataType.BLOB) @@ -301,9 +290,6 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addColumn("c5", DataType.BIGINT) .addColumn("c6", DataType.BOOLEAN) .addColumn("c7", DataType.TEXT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMPTZ) .addSecondaryIndex("c2") .addSecondaryIndex("c4") .build(); @@ -320,16 +306,12 @@ private void verifyInsertIntoKeyspacesTableQuery(String keyspace) { .addPartitionKey("c7", com.datastax.driver.core.DataType.text()) .addClusteringColumn("c4", com.datastax.driver.core.DataType.cdouble()) .addClusteringColumn("c6", com.datastax.driver.core.DataType.cboolean()) - .addClusteringColumn("c9", com.datastax.driver.core.DataType.time()) .addColumn("c2", com.datastax.driver.core.DataType.text()) .addColumn("c3", com.datastax.driver.core.DataType.blob()) .addColumn("c5", com.datastax.driver.core.DataType.bigint()) - .addColumn("c8", com.datastax.driver.core.DataType.date()) - .addColumn("c10", com.datastax.driver.core.DataType.timestamp()) .withOptions() .clusteringOrder("c4", Direction.ASC) .clusteringOrder("c6", Direction.DESC) - .clusteringOrder("c9", Direction.ASC) .compactionOptions(SchemaBuilder.leveledStrategy()); verify(cassandraSession).execute(createTableStatement.getQueryString()); } diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java index 9dc24dac5a..e9a84509b4 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTest.java @@ -41,7 +41,6 @@ import com.scalar.db.io.DataType; import java.util.Collections; import java.util.Iterator; -import java.util.Map; import java.util.Set; import java.util.function.Consumer; import java.util.stream.Stream; @@ -93,27 +92,11 @@ public void getTableMetadata_ShouldReturnCorrectTableMetadata() throws Execution any(PartitionKey.class), ArgumentMatchers.>any())) .thenReturn(response); - Map columnsMap = - new ImmutableMap.Builder() - .put("c1", "int") - .put("c2", "text") - .put("c3", "bigint") - .put("c4", "boolean") - .put("c5", "blob") - .put("c6", "float") - .put("c7", "double") - .put("c8", "date") - .put("c9", "time") - .put("c10", "timestamp") - .put("c11", "timestamptz") - .build(); + CosmosTableMetadata cosmosTableMetadata = CosmosTableMetadata.newBuilder() .partitionKeyNames(Sets.newLinkedHashSet("c1")) - .clusteringKeyNames(Sets.newLinkedHashSet("c2", "c3")) - .clusteringOrders(ImmutableMap.of("c2", "ASC", "c3", "DESC")) - .secondaryIndexNames(ImmutableSet.of("c4", "c9")) - .columns(columnsMap) + .columns(ImmutableMap.of("c1", "int", "c2", "text", "c3", "bigint")) .build(); when(response.getItem()).thenReturn(cosmosTableMetadata); @@ -125,22 +108,10 @@ public void getTableMetadata_ShouldReturnCorrectTableMetadata() throws Execution assertThat(actual) .isEqualTo( TableMetadata.newBuilder() - .addPartitionKey("c1") - .addClusteringKey("c2", Order.ASC) - .addClusteringKey("c3", Order.DESC) - .addSecondaryIndex("c4") - .addSecondaryIndex("c9") .addColumn("c1", DataType.INT) .addColumn("c2", DataType.TEXT) .addColumn("c3", DataType.BIGINT) - .addColumn("c4", DataType.BOOLEAN) - .addColumn("c5", DataType.BLOB) - .addColumn("c6", DataType.FLOAT) - .addColumn("c7", DataType.DOUBLE) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) + .addPartitionKey("c1") .build()); verify(client).getDatabase(METADATA_DATABASE); @@ -271,10 +242,6 @@ public void createTable_ShouldCreateContainer() throws ExecutionException { .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -351,10 +318,6 @@ public void createTable_ShouldCreateContainer() throws ExecutionException { .put("c5", "int") .put("c6", "double") .put("c7", "float") - .put("c8", "date") - .put("c9", "time") - .put("c10", "timestamp") - .put("c11", "timestamptz") .build()) .secondaryIndexNames(ImmutableSet.of("c4")) .build(); @@ -377,9 +340,6 @@ public void createTable_WithoutClusteringKeys_ShouldCreateContainerWithComposite .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -444,9 +404,6 @@ public void createTable_WithoutClusteringKeys_ShouldCreateContainerWithComposite .put("c5", "int") .put("c6", "double") .put("c7", "float") - .put("c8", "date") - .put("c9", "time") - .put("c10", "timestamptz") .build()) .build(); verify(metadataContainer).upsertItem(cosmosTableMetadata); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java index 7e17c4d8d8..86f78558a1 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java @@ -314,10 +314,6 @@ public void createTable_WhenMetadataTableNotExist_ShouldCreateTableAndMetadataTa .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -457,10 +453,6 @@ public void createTable_WhenMetadataTableNotExist_ShouldCreateTableAndMetadataTa columns.put("c5", AttributeValue.builder().s("int").build()); columns.put("c6", AttributeValue.builder().s("double").build()); columns.put("c7", AttributeValue.builder().s("float").build()); - columns.put("c8", AttributeValue.builder().s("date").build()); - columns.put("c9", AttributeValue.builder().s("time").build()); - columns.put("c10", AttributeValue.builder().s("timestamp").build()); - columns.put("c11", AttributeValue.builder().s("timestamptz").build()); itemValues.put(DynamoAdmin.METADATA_ATTR_COLUMNS, AttributeValue.builder().m(columns).build()); itemValues.put( DynamoAdmin.METADATA_ATTR_PARTITION_KEY, @@ -513,10 +505,6 @@ public void createTable_WhenMetadataTableExists_ShouldCreateOnlyTable() .addColumn("c5", DataType.BLOB) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); @@ -618,10 +606,6 @@ public void createTable_WhenMetadataTableExists_ShouldCreateOnlyTable() columns.put("c5", AttributeValue.builder().s("blob").build()); columns.put("c6", AttributeValue.builder().s("double").build()); columns.put("c7", AttributeValue.builder().s("float").build()); - columns.put("c8", AttributeValue.builder().s("date").build()); - columns.put("c9", AttributeValue.builder().s("time").build()); - columns.put("c10", AttributeValue.builder().s("timestamp").build()); - columns.put("c11", AttributeValue.builder().s("timestamptz").build()); itemValues.put(DynamoAdmin.METADATA_ATTR_COLUMNS, AttributeValue.builder().m(columns).build()); itemValues.put( DynamoAdmin.METADATA_ATTR_PARTITION_KEY, diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java index 87d591076f..1a89820777 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java @@ -211,15 +211,7 @@ private void getTableMetadata_forX_ShouldReturnTableMetadata( new SelectAllFromMetadataTableResultSetMocker.Row( "c6", DataType.DOUBLE.toString(), null, null, false), new SelectAllFromMetadataTableResultSetMocker.Row( - "c7", DataType.FLOAT.toString(), null, null, false), - new SelectAllFromMetadataTableResultSetMocker.Row( - "c8", DataType.DATE.toString(), null, null, false), - new SelectAllFromMetadataTableResultSetMocker.Row( - "c9", DataType.TIME.toString(), null, null, false), - new SelectAllFromMetadataTableResultSetMocker.Row( - "c10", DataType.TIMESTAMP.toString(), null, null, false), - new SelectAllFromMetadataTableResultSetMocker.Row( - "c11", DataType.TIMESTAMPTZ.toString(), null, null, false)); + "c7", DataType.FLOAT.toString(), null, null, false)); when(selectStatement.executeQuery()).thenReturn(resultSet); when(connection.prepareStatement(any())).thenReturn(selectStatement); when(dataSource.getConnection()).thenReturn(connection); @@ -242,10 +234,6 @@ private void getTableMetadata_forX_ShouldReturnTableMetadata( .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c4") .build(); assertThat(actualMetadata).isEqualTo(expectedMetadata); @@ -478,7 +466,7 @@ public void createTableInternal_ForSqlite_withInvalidTableName_ShouldThrowExecut public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.MYSQL, - "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL,`c8` DATE,`c9` TIME,`c10` DATETIME,`c11` DATETIME, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", + "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", "CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)", "CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)"); } @@ -490,7 +478,7 @@ public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes() throws SQ when(config.getMysqlVariableKeyColumnSize()).thenReturn(64); createTableInternal_ForX_CreateTableAndIndexes( new RdbEngineMysql(config), - "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL,`c8` DATE,`c9` TIME,`c10` DATETIME,`c11` DATETIME, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", + "CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", "CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)", "CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)"); } @@ -499,7 +487,7 @@ public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes() throws SQ public void createTableInternal_ForPostgresql_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.POSTGRESQL, - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL,\"c8\" DATE,\"c9\" TIME,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", "CREATE INDEX \"index_my_ns_foo_table_c1\" ON \"my_ns\".\"foo_table\" (\"c1\")"); @@ -509,7 +497,8 @@ public void createTableInternal_ForPostgresql_ShouldCreateTableAndIndexes() thro public void createTableInternal_ForSqlServer_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.SQL_SERVER, - "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000),[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24),[c8] DATE,[c9] TIME,[c10] DATETIME2,[c11] DATETIMEOFFSET, PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", + "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000)," + + "[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", "CREATE INDEX [index_my_ns_foo_table_c4] ON [my_ns].[foo_table] ([c4])", "CREATE INDEX [index_my_ns_foo_table_c1] ON [my_ns].[foo_table] ([c1])"); } @@ -518,7 +507,7 @@ public void createTableInternal_ForSqlServer_ShouldCreateTableAndIndexes() throw public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.ORACLE, - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT,\"c8\" DATE,\"c9\" TIMESTAMP,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", "ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", @@ -532,7 +521,7 @@ public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes() throws S when(config.getOracleVariableKeyColumnSize()).thenReturn(64); createTableInternal_ForX_CreateTableAndIndexes( new RdbEngineOracle(config), - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT,\"c8\" DATE,\"c9\" TIMESTAMP,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", "ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", @@ -543,7 +532,7 @@ public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes() throws S public void createTableInternal_ForSqlite_ShouldCreateTableAndIndexes() throws SQLException { createTableInternal_ForX_CreateTableAndIndexes( RdbEngine.SQLITE, - "CREATE TABLE \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT,\"c8\" TEXT,\"c9\" TEXT,\"c10\" TEXT,\"c11\" TEXT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns$foo_table\" (\"c4\")", "CREATE INDEX \"index_my_ns_foo_table_c1\" ON \"my_ns$foo_table\" (\"c1\")"); } @@ -571,10 +560,6 @@ private void createTableInternal_ForX_CreateTableAndIndexes( .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -605,7 +590,7 @@ public void createTableInternal_IfNotExistsForMysql_ShouldCreateTableAndIndexesI throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.MYSQL, - "CREATE TABLE IF NOT EXISTS `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL,`c8` DATE,`c9` TIME,`c10` DATETIME,`c11` DATETIME, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", + "CREATE TABLE IF NOT EXISTS `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(128),`c4` VARBINARY(128),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))", "CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)", "CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)"); } @@ -615,7 +600,7 @@ public void createTableInternal_IfNotExistsForPostgresql_ShouldCreateTableAndInd throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.POSTGRESQL, - "CREATE TABLE IF NOT EXISTS \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL,\"c8\" DATE,\"c9\" TIME,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE IF NOT EXISTS \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE UNIQUE INDEX IF NOT EXISTS \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c1\" ON \"my_ns\".\"foo_table\" (\"c1\")"); @@ -626,7 +611,8 @@ public void createTableInternal_IfNotExistsForSqlServer_ShouldCreateTableAndInde throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.SQL_SERVER, - "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000),[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24),[c8] DATE,[c9] TIME,[c10] DATETIME2,[c11] DATETIMEOFFSET, PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", + "CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000)," + + "[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3] ASC,[c1] DESC,[c4] ASC))", "CREATE INDEX [index_my_ns_foo_table_c4] ON [my_ns].[foo_table] ([c4])", "CREATE INDEX [index_my_ns_foo_table_c1] ON [my_ns].[foo_table] ([c1])"); } @@ -636,7 +622,7 @@ public void createTableInternal_IfNotExistsForOracle_ShouldCreateTableAndIndexes throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.ORACLE, - "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT,\"c8\" DATE,\"c9\" TIMESTAMP,\"c10\" TIMESTAMP,\"c11\" TIMESTAMP WITH TIME ZONE, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", + "CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(128),\"c4\" RAW(128),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES", "ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255", "CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)", "CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")", @@ -648,7 +634,7 @@ public void createTableInternal_IfNotExistsForSqlite_ShouldCreateTableAndIndexes throws SQLException { createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists( RdbEngine.SQLITE, - "CREATE TABLE IF NOT EXISTS \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT,\"c8\" TEXT,\"c9\" TEXT,\"c10\" TEXT,\"c11\" TEXT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", + "CREATE TABLE IF NOT EXISTS \"my_ns$foo_table\"(\"c3\" BOOLEAN,\"c1\" TEXT,\"c4\" BLOB,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE,\"c7\" FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c4\" ON \"my_ns$foo_table\" (\"c4\")", "CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c1\" ON \"my_ns$foo_table\" (\"c1\")"); } @@ -677,10 +663,6 @@ private void createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExist .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -1018,11 +1000,7 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForMysql_Should + "`.`metadata` VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,false,6)", "INSERT INTO `" + METADATA_SCHEMA - + "`.`metadata` VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)", - "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,false,8)", - "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,false,9)", - "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,false,10)", - "INSERT INTO `scalardb`.`metadata` VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,false,11)"); + + "`.`metadata` VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)"); } @Test @@ -1063,11 +1041,7 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForMysql_Should + "\".\"metadata\" VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,false,6)", "INSERT INTO \"" + METADATA_SCHEMA - + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,false,8)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,false,9)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,false,10)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,false,11)"); + + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,false,7)"); } @Test @@ -1107,11 +1081,7 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForSqlServer_Sh + "].[metadata] VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,0,6)", "INSERT INTO [" + METADATA_SCHEMA - + "].[metadata] VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)", - "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,0,8)", - "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,0,9)", - "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,0,10)", - "INSERT INTO [scalardb].[metadata] VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,0,11)"); + + "].[metadata] VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)"); } @Test @@ -1144,11 +1114,7 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForOracle_Shoul + "\".\"metadata\" VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,0,6)", "INSERT INTO \"" + METADATA_SCHEMA - + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,0,8)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,0,9)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,0,10)", - "INSERT INTO \"scalardb\".\"metadata\" VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,0,11)"); + + "\".\"metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,0,7)"); } @Test @@ -1187,11 +1153,7 @@ public void addTableMetadata_ifNotExistsAndDoNotOverwriteMetadataForSqlite_Shoul + "$metadata\" VALUES ('my_ns.foo_table','c6','DOUBLE',NULL,NULL,FALSE,6)", "INSERT INTO \"" + METADATA_SCHEMA - + "$metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,FALSE,7)", - "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c8','DATE',NULL,NULL,FALSE,8)", - "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c9','TIME',NULL,NULL,FALSE,9)", - "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c10','TIMESTAMP',NULL,NULL,FALSE,10)", - "INSERT INTO \"scalardb$metadata\" VALUES ('my_ns.foo_table','c11','TIMESTAMPTZ',NULL,NULL,FALSE,11)"); + + "$metadata\" VALUES ('my_ns.foo_table','c7','FLOAT',NULL,NULL,FALSE,7)"); } private void addTableMetadata_createMetadataTableIfNotExistsForX_ShouldWorkProperly( @@ -1211,10 +1173,6 @@ private void addTableMetadata_createMetadataTableIfNotExistsForX_ShouldWorkPrope .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -1259,10 +1217,6 @@ public void createTable_ShouldCallCreateTableAndAddTableMetadataCorrectly(RdbEng .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); @@ -1298,10 +1252,6 @@ public void repairTable_ShouldCallCreateTableAndAddTableMetadataCorrectly(RdbEng .addColumn("c5", DataType.INT) .addColumn("c6", DataType.DOUBLE) .addColumn("c7", DataType.FLOAT) - .addColumn("c8", DataType.DATE) - .addColumn("c9", DataType.TIME) - .addColumn("c10", DataType.TIMESTAMP) - .addColumn("c11", DataType.TIMESTAMPTZ) .addSecondaryIndex("c1") .addSecondaryIndex("c4") .build(); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java index c768c66d91..705c78e0ad 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java @@ -50,10 +50,6 @@ public abstract class DistributedStorageAdminIntegrationTestBase { private static final String COL_NAME9 = "c9"; private static final String COL_NAME10 = "c10"; private static final String COL_NAME11 = "c11"; - private static final String COL_NAME12 = "c12"; - private static final String COL_NAME13 = "c13"; - private static final String COL_NAME14 = "c14"; - private static final String COL_NAME15 = "c15"; private static final TableMetadata TABLE_METADATA = TableMetadata.newBuilder() @@ -68,9 +64,6 @@ public abstract class DistributedStorageAdminIntegrationTestBase { .addColumn(COL_NAME9, DataType.DOUBLE) .addColumn(COL_NAME10, DataType.BOOLEAN) .addColumn(COL_NAME11, DataType.BLOB) - .addColumn(COL_NAME12, DataType.DATE) - .addColumn(COL_NAME13, DataType.TIME) - .addColumn(COL_NAME14, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME2) .addPartitionKey(COL_NAME1) .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) @@ -160,9 +153,6 @@ private void dropTables() throws ExecutionException { public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() throws ExecutionException { // Arrange - if (isTimestampTypeSupported()) { - admin.addNewColumnToTable(namespace1, TABLE1, COL_NAME15, DataType.TIMESTAMP); - } // Act TableMetadata tableMetadata = admin.getTableMetadata(namespace1, TABLE1); @@ -180,12 +170,7 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(iterator.next()).isEqualTo(COL_NAME4); assertThat(iterator.next()).isEqualTo(COL_NAME3); - if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnNames().size()).isEqualTo(15); - } else { - assertThat(tableMetadata.getColumnNames().size()).isEqualTo(14); - } - + assertThat(tableMetadata.getColumnNames().size()).isEqualTo(11); assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue(); @@ -197,12 +182,6 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnNames().contains(COL_NAME9)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME10)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME11)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME12)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME13)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME14)).isTrue(); - if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnNames().contains(COL_NAME15)).isTrue(); - } assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT); assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT); @@ -215,12 +194,6 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnDataType(COL_NAME9)).isEqualTo(DataType.DOUBLE); assertThat(tableMetadata.getColumnDataType(COL_NAME10)).isEqualTo(DataType.BOOLEAN); assertThat(tableMetadata.getColumnDataType(COL_NAME11)).isEqualTo(DataType.BLOB); - assertThat(tableMetadata.getColumnDataType(COL_NAME12)).isEqualTo(DataType.DATE); - assertThat(tableMetadata.getColumnDataType(COL_NAME13)).isEqualTo(DataType.TIME); - assertThat(tableMetadata.getColumnDataType(COL_NAME14)).isEqualTo(DataType.TIMESTAMPTZ); - if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnDataType(COL_NAME15)).isEqualTo(DataType.TIMESTAMP); - } assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull(); @@ -233,10 +206,6 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getClusteringOrder(COL_NAME9)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME10)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME11)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME12)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME13)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME14)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME15)).isNull(); assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue(); @@ -437,7 +406,6 @@ public void truncateTable_ShouldTruncateProperly() throws ExecutionException, IO .withValue(COL_NAME9, 1.0d) .withValue(COL_NAME10, true) .withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)) - // TODO add put values for date, time, timestamp and timestamptz .forNamespace(namespace1) .forTable(TABLE1)); @@ -504,7 +472,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre try { // Arrange Map options = getCreationOptions(); - TableMetadata.Builder metadataBuilder = + TableMetadata metadata = TableMetadata.newBuilder() .addColumn(COL_NAME1, DataType.INT) .addColumn(COL_NAME2, DataType.INT) @@ -515,15 +483,9 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .addColumn(COL_NAME7, DataType.BOOLEAN) .addColumn(COL_NAME8, DataType.BLOB) .addColumn(COL_NAME9, DataType.TEXT) - .addColumn(COL_NAME10, DataType.DATE) - .addColumn(COL_NAME11, DataType.TIME) - .addColumn(COL_NAME12, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME9); - if (isTimestampTypeSupported()) { - metadataBuilder = metadataBuilder.addColumn(COL_NAME13, DataType.TIMESTAMP); - } - TableMetadata metadata = metadataBuilder.build(); + .addSecondaryIndex(COL_NAME9) + .build(); admin.createTable(namespace1, TABLE4, metadata, options); storage = storageFactory.getStorage(); storage.put( @@ -539,7 +501,6 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") - // TODO add put values for date, time, timestamp and timestamptz .build()); // Act admin.createIndex(namespace1, TABLE4, COL_NAME2, options); @@ -551,12 +512,6 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre admin.createIndex(namespace1, TABLE4, COL_NAME7, options); } admin.createIndex(namespace1, TABLE4, COL_NAME8, options); - admin.createIndex(namespace1, TABLE4, COL_NAME10, options); - admin.createIndex(namespace1, TABLE4, COL_NAME11, options); - admin.createIndex(namespace1, TABLE4, COL_NAME12, options); - if (isTimestampTypeSupported()) { - admin.createIndex(namespace1, TABLE4, COL_NAME13, options); - } // Assert assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).isTrue(); @@ -568,39 +523,16 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME7)).isTrue(); } assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME9)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME10)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME11)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME12)).isTrue(); - if (isTimestampTypeSupported()) { - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME13)).isTrue(); - } - - Set actualSecondaryIndexNames = - admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames(); - assertThat(actualSecondaryIndexNames) - .contains( - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME8, - COL_NAME9, - COL_NAME10, - COL_NAME11, - COL_NAME12); - int indexCount = 10; if (isIndexOnBooleanColumnSupported()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME7); - indexCount++; - } - if (isTimestampTypeSupported()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME13); - indexCount++; + assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) + .containsOnly( + COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7, COL_NAME8, + COL_NAME9); + } else { + assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) + .containsOnly( + COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME8, COL_NAME9); } - assertThat(actualSecondaryIndexNames).hasSize(indexCount); - } finally { admin.dropTable(namespace1, TABLE4, true); if (storage != null) { @@ -726,7 +658,6 @@ public void dropIndex_ForAllDataTypesWithExistingData_ShouldDropIndexCorrectly() .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") - // TODO add put values for date, time, timestamp and timestamptz .build()); // Act @@ -879,8 +810,4 @@ public void addNewColumnToTable_ForAlreadyExistingColumn_ShouldThrowIllegalArgum protected boolean isIndexOnBooleanColumnSupported() { return true; } - - protected boolean isTimestampTypeSupported() { - return true; - } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java index f916896910..c1d051aa29 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminRepairIntegrationTestBase.java @@ -37,46 +37,32 @@ public abstract class DistributedStorageAdminRepairIntegrationTestBase { private static final String COL_NAME9 = "c9"; private static final String COL_NAME10 = "c10"; private static final String COL_NAME11 = "c11"; - private static final String COL_NAME12 = "c12"; - private static final String COL_NAME13 = "c13"; - private static final String COL_NAME14 = "c14"; - private static final String COL_NAME15 = "c15"; + + protected static final TableMetadata TABLE_METADATA = + TableMetadata.newBuilder() + .addColumn(COL_NAME1, DataType.INT) + .addColumn(COL_NAME2, DataType.TEXT) + .addColumn(COL_NAME3, DataType.TEXT) + .addColumn(COL_NAME4, DataType.INT) + .addColumn(COL_NAME5, DataType.INT) + .addColumn(COL_NAME6, DataType.TEXT) + .addColumn(COL_NAME7, DataType.BIGINT) + .addColumn(COL_NAME8, DataType.FLOAT) + .addColumn(COL_NAME9, DataType.DOUBLE) + .addColumn(COL_NAME10, DataType.BOOLEAN) + .addColumn(COL_NAME11, DataType.BLOB) + .addPartitionKey(COL_NAME2) + .addPartitionKey(COL_NAME1) + .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) + .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) + .addSecondaryIndex(COL_NAME5) + .addSecondaryIndex(COL_NAME6) + .build(); protected DistributedStorageAdmin admin; protected AdminTestUtils adminTestUtils = null; - protected TableMetadata getTableMetadata() { - TableMetadata.Builder builder = - TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.TEXT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.INT) - .addColumn(COL_NAME5, DataType.INT) - .addColumn(COL_NAME6, DataType.TEXT) - .addColumn(COL_NAME7, DataType.BIGINT) - .addColumn(COL_NAME8, DataType.FLOAT) - .addColumn(COL_NAME9, DataType.DOUBLE) - .addColumn(COL_NAME10, DataType.BOOLEAN) - .addColumn(COL_NAME11, DataType.BLOB) - .addColumn(COL_NAME12, DataType.DATE) - .addColumn(COL_NAME13, DataType.TIME) - .addColumn(COL_NAME14, DataType.TIMESTAMPTZ); - if (isTimestampTypeSupported()) { - builder.addColumn(COL_NAME15, DataType.TIMESTAMP); - } - builder - .addPartitionKey(COL_NAME2) - .addPartitionKey(COL_NAME1) - .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) - .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) - .build(); - return builder.build(); - } - @BeforeAll public void beforeAll() throws Exception { initialize(TEST_NAME); @@ -119,7 +105,7 @@ protected String getTable() { private void createTable() throws ExecutionException { Map options = getCreationOptions(); admin.createNamespace(getNamespace(), options); - admin.createTable(getNamespace(), getTable(), getTableMetadata(), options); + admin.createTable(getNamespace(), getTable(), TABLE_METADATA, options); } protected Map getCreationOptions() { @@ -149,11 +135,11 @@ protected void waitForDifferentSessionDdl() { @Test public void repairTable_ForExistingTableAndMetadata_ShouldDoNothing() throws Exception { // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); } @Test @@ -163,12 +149,12 @@ public void repairTable_ForDeletedMetadataTable_ShouldRepairProperly() throws Ex // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); } @Test @@ -177,11 +163,11 @@ public void repairTable_ForTruncatedMetadataTable_ShouldRepairProperly() throws adminTestUtils.truncateMetadataTable(); // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); } @Test @@ -190,11 +176,11 @@ public void repairTable_ForCorruptedMetadataTable_ShouldRepairProperly() throws adminTestUtils.corruptMetadata(getNamespace(), getTable()); // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); } @Test @@ -205,12 +191,12 @@ public void repairTable_ForNonExistingTableButExistingMetadata_ShouldCreateTable // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); } @Test @@ -286,8 +272,4 @@ public void repairNamespace_ForNonExistingNamespaceAndMetadata_ShouldCreateNames assertThat(adminTestUtils.namespaceExists(getNamespace())).isTrue(); assertThat(admin.namespaceExists(getNamespace())).isTrue(); } - - protected boolean isTimestampTypeSupported() { - return true; - } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java index 0870c7b752..21b87ba2d5 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java @@ -163,7 +163,7 @@ protected List getOperatorAndDataTypeListForTest() { List ret = new ArrayList<>(); for (Operator operator : Operator.values()) { if (operator != Operator.LIKE && operator != Operator.NOT_LIKE) { - for (DataType dataType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType dataType : DataType.values()) { ret.add(new OperatorAndDataType(operator, dataType)); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java index 3fdf68eebd..6d9499726c 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCrossPartitionScanIntegrationTestBase.java @@ -195,8 +195,8 @@ private String getTableName(DataType firstColumnType, DataType secondColumnType) private ListMultimap getColumnTypes() { ListMultimap columnTypes = ArrayListMultimap.create(); - for (DataType firstColumnType : DataType.valuesWithoutTimesRelatedTypes()) { - for (DataType secondColumnType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType firstColumnType : DataType.values()) { + for (DataType secondColumnType : DataType.values()) { columnTypes.put(firstColumnType, secondColumnType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java index a1837383c1..66676a5002 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultipleClusteringKeyScanIntegrationTestBase.java @@ -102,8 +102,8 @@ protected String getNamespaceBaseName() { protected ListMultimap getClusteringKeyTypes() { ListMultimap clusteringKeyTypes = ArrayListMultimap.create(); - for (DataType firstClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { - for (DataType secondClusteringKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType firstClusteringKeyType : DataType.values()) { + for (DataType secondClusteringKeyType : DataType.values()) { clusteringKeyTypes.put(firstClusteringKeyType, secondClusteringKeyType); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java index d111a9e02a..f61f901fff 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageMultiplePartitionKeyIntegrationTestBase.java @@ -84,13 +84,13 @@ protected String getNamespaceBaseName() { protected ListMultimap getPartitionKeyTypes() { ListMultimap partitionKeyTypes = ArrayListMultimap.create(); - for (DataType firstPartitionKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType firstPartitionKeyType : DataType.values()) { if (!isFloatTypeKeySupported() && (firstPartitionKeyType == DataType.FLOAT || firstPartitionKeyType == DataType.DOUBLE)) { continue; } - for (DataType secondPartitionKeyType : DataType.valuesWithoutTimesRelatedTypes()) { + for (DataType secondPartitionKeyType : DataType.values()) { if (!isFloatTypeKeySupported() && (secondPartitionKeyType == DataType.FLOAT || secondPartitionKeyType == DataType.DOUBLE)) { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java index 57f0330390..c90f8c3d3d 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSecondaryIndexIntegrationTestBase.java @@ -69,7 +69,7 @@ protected String getNamespace() { } protected Set getSecondaryIndexTypes() { - return new HashSet<>(Arrays.asList(DataType.valuesWithoutTimesRelatedTypes())); + return new HashSet<>(Arrays.asList(DataType.values())); } private void createTables() throws ExecutionException { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java index 7b6e7ae5ab..3cd85f8692 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSingleClusteringKeyScanIntegrationTestBase.java @@ -80,7 +80,7 @@ protected String getNamespace() { } protected Set getClusteringKeyTypes() { - return new HashSet<>(Arrays.asList(DataType.valuesWithoutTimesRelatedTypes())); + return new HashSet<>(Arrays.asList(DataType.values())); } private void createTables() throws ExecutionException { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java index 50c4c1144e..9d59295801 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageSinglePartitionKeyIntegrationTestBase.java @@ -70,7 +70,7 @@ protected String getNamespace() { } protected Set getPartitionKeyTypes() { - return new HashSet<>(Arrays.asList(DataType.valuesWithoutTimesRelatedTypes())); + return new HashSet<>(Arrays.asList(DataType.values())); } protected boolean isFloatTypeKeySupported() { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java index 33734b9165..579205ceaa 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java @@ -48,10 +48,6 @@ public abstract class DistributedTransactionAdminIntegrationTestBase { protected static final String COL_NAME9 = "c9"; protected static final String COL_NAME10 = "c10"; protected static final String COL_NAME11 = "c11"; - private static final String COL_NAME12 = "c12"; - private static final String COL_NAME13 = "c13"; - private static final String COL_NAME14 = "c14"; - private static final String COL_NAME15 = "c15"; protected static final TableMetadata TABLE_METADATA = TableMetadata.newBuilder() @@ -66,9 +62,6 @@ public abstract class DistributedTransactionAdminIntegrationTestBase { .addColumn(COL_NAME9, DataType.DOUBLE) .addColumn(COL_NAME10, DataType.BOOLEAN) .addColumn(COL_NAME11, DataType.BLOB) - .addColumn(COL_NAME12, DataType.DATE) - .addColumn(COL_NAME13, DataType.TIME) - .addColumn(COL_NAME14, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME2) .addPartitionKey(COL_NAME1) .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) @@ -155,9 +148,6 @@ private void dropTables() throws ExecutionException { public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() throws ExecutionException { // Arrange - if (isTimestampTypeSupported()) { - admin.addNewColumnToTable(namespace1, TABLE1, COL_NAME15, DataType.TIMESTAMP); - } // Act TableMetadata tableMetadata = admin.getTableMetadata(namespace1, TABLE1); @@ -175,11 +165,7 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(iterator.next()).isEqualTo(COL_NAME4); assertThat(iterator.next()).isEqualTo(COL_NAME3); - if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnNames().size()).isEqualTo(15); - } else { - assertThat(tableMetadata.getColumnNames().size()).isEqualTo(14); - } + assertThat(tableMetadata.getColumnNames().size()).isEqualTo(11); assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue(); @@ -191,12 +177,6 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnNames().contains(COL_NAME9)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME10)).isTrue(); assertThat(tableMetadata.getColumnNames().contains(COL_NAME11)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME12)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME13)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME14)).isTrue(); - if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnNames().contains(COL_NAME15)).isTrue(); - } assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT); assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT); @@ -209,12 +189,6 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnDataType(COL_NAME9)).isEqualTo(DataType.DOUBLE); assertThat(tableMetadata.getColumnDataType(COL_NAME10)).isEqualTo(DataType.BOOLEAN); assertThat(tableMetadata.getColumnDataType(COL_NAME11)).isEqualTo(DataType.BLOB); - assertThat(tableMetadata.getColumnDataType(COL_NAME12)).isEqualTo(DataType.DATE); - assertThat(tableMetadata.getColumnDataType(COL_NAME13)).isEqualTo(DataType.TIME); - assertThat(tableMetadata.getColumnDataType(COL_NAME14)).isEqualTo(DataType.TIMESTAMPTZ); - if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnDataType(COL_NAME15)).isEqualTo(DataType.TIMESTAMP); - } assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull(); @@ -227,10 +201,6 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getClusteringOrder(COL_NAME9)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME10)).isNull(); assertThat(tableMetadata.getClusteringOrder(COL_NAME11)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME12)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME13)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME14)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME15)).isNull(); assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue(); @@ -432,7 +402,6 @@ public void truncateTable_ShouldTruncateProperly() .withValue(COL_NAME9, 1.0d) .withValue(COL_NAME10, true) .withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)) - // TODO add put values for data, time, timestamp and timestamptz .forNamespace(namespace1) .forTable(TABLE1)); @@ -498,7 +467,7 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre try { // Arrange Map options = getCreationOptions(); - TableMetadata.Builder metadataBuilder = + TableMetadata metadata = TableMetadata.newBuilder() .addColumn(COL_NAME1, DataType.INT) .addColumn(COL_NAME2, DataType.INT) @@ -509,15 +478,9 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .addColumn(COL_NAME7, DataType.BOOLEAN) .addColumn(COL_NAME8, DataType.BLOB) .addColumn(COL_NAME9, DataType.TEXT) - .addColumn(COL_NAME10, DataType.DATE) - .addColumn(COL_NAME11, DataType.TIME) - .addColumn(COL_NAME12, DataType.TIMESTAMPTZ) .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME9); - if (isTimestampTypeSupported()) { - metadataBuilder = metadataBuilder.addColumn(COL_NAME13, DataType.TIMESTAMP); - } - TableMetadata metadata = metadataBuilder.build(); + .addSecondaryIndex(COL_NAME9) + .build(); admin.createTable(namespace1, TABLE4, metadata, options); transactionManager = transactionFactory.getTransactionManager(); transactionManager.put( @@ -533,7 +496,6 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") - // TODO add put values for date, time, timestamp and timestamptz .build()); // Act @@ -546,12 +508,6 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre admin.createIndex(namespace1, TABLE4, COL_NAME7, options); } admin.createIndex(namespace1, TABLE4, COL_NAME8, options); - admin.createIndex(namespace1, TABLE4, COL_NAME10, options); - admin.createIndex(namespace1, TABLE4, COL_NAME11, options); - admin.createIndex(namespace1, TABLE4, COL_NAME12, options); - if (isTimestampTypeSupported()) { - admin.createIndex(namespace1, TABLE4, COL_NAME13, options); - } // Assert assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).isTrue(); @@ -563,38 +519,16 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME7)).isTrue(); } assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME9)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME10)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME11)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME12)).isTrue(); - if (isTimestampTypeSupported()) { - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME13)).isTrue(); - } - - Set actualSecondaryIndexNames = - admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames(); - assertThat(actualSecondaryIndexNames) - .contains( - COL_NAME2, - COL_NAME3, - COL_NAME4, - COL_NAME5, - COL_NAME6, - COL_NAME8, - COL_NAME9, - COL_NAME10, - COL_NAME11, - COL_NAME12); - int indexCount = 10; if (isIndexOnBooleanColumnSupported()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME7); - indexCount++; - } - if (isTimestampTypeSupported()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME13); - indexCount++; + assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) + .containsOnly( + COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7, COL_NAME8, + COL_NAME9); + } else { + assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) + .containsOnly( + COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME8, COL_NAME9); } - assertThat(actualSecondaryIndexNames).hasSize(indexCount); } finally { admin.dropTable(namespace1, TABLE4, true); @@ -718,7 +652,6 @@ public void dropIndex_ForAllDataTypesWithExistingData_ShouldDropIndexCorrectly() .booleanValue(COL_NAME7, true) .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) .textValue(COL_NAME9, "9") - // TODO add put values for date, time, timestamp and timestamptz .build()); // Act @@ -950,8 +883,4 @@ public void getNamespaceNames_ShouldReturnCreatedNamespaces() throws ExecutionEx protected boolean isIndexOnBooleanColumnSupported() { return true; } - - protected boolean isTimestampTypeSupported() { - return true; - } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java index 637bb4d497..bc43a09d33 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminRepairIntegrationTestBase.java @@ -42,46 +42,32 @@ public abstract class DistributedTransactionAdminRepairIntegrationTestBase { protected static final String COL_NAME9 = "c9"; protected static final String COL_NAME10 = "c10"; protected static final String COL_NAME11 = "c11"; - private static final String COL_NAME12 = "c12"; - private static final String COL_NAME13 = "c13"; - private static final String COL_NAME14 = "c14"; - private static final String COL_NAME15 = "c15"; + + protected static final TableMetadata TABLE_METADATA = + TableMetadata.newBuilder() + .addColumn(COL_NAME1, DataType.INT) + .addColumn(COL_NAME2, DataType.TEXT) + .addColumn(COL_NAME3, DataType.TEXT) + .addColumn(COL_NAME4, DataType.INT) + .addColumn(COL_NAME5, DataType.INT) + .addColumn(COL_NAME6, DataType.TEXT) + .addColumn(COL_NAME7, DataType.BIGINT) + .addColumn(COL_NAME8, DataType.FLOAT) + .addColumn(COL_NAME9, DataType.DOUBLE) + .addColumn(COL_NAME10, DataType.BOOLEAN) + .addColumn(COL_NAME11, DataType.BLOB) + .addPartitionKey(COL_NAME2) + .addPartitionKey(COL_NAME1) + .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) + .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) + .addSecondaryIndex(COL_NAME5) + .addSecondaryIndex(COL_NAME6) + .build(); protected DistributedTransactionAdmin admin; protected DistributedStorageAdmin storageAdmin; protected AdminTestUtils adminTestUtils = null; - protected TableMetadata getTableMetadata() { - TableMetadata.Builder builder = - TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.TEXT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.INT) - .addColumn(COL_NAME5, DataType.INT) - .addColumn(COL_NAME6, DataType.TEXT) - .addColumn(COL_NAME7, DataType.BIGINT) - .addColumn(COL_NAME8, DataType.FLOAT) - .addColumn(COL_NAME9, DataType.DOUBLE) - .addColumn(COL_NAME10, DataType.BOOLEAN) - .addColumn(COL_NAME11, DataType.BLOB) - .addColumn(COL_NAME12, DataType.DATE) - .addColumn(COL_NAME13, DataType.TIME) - .addColumn(COL_NAME14, DataType.TIMESTAMPTZ); - if (isTimestampTypeSupported()) { - builder.addColumn(COL_NAME15, DataType.TIMESTAMP); - } - builder - .addPartitionKey(COL_NAME2) - .addPartitionKey(COL_NAME1) - .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) - .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) - .build(); - return builder.build(); - } - @BeforeAll public void beforeAll() throws Exception { initialize(TEST_NAME); @@ -140,7 +126,7 @@ private void createTable() throws ExecutionException { Map options = getCreationOptions(); admin.createCoordinatorTables(options); admin.createNamespace(getNamespace(), options); - admin.createTable(getNamespace(), getTable(), getTableMetadata(), options); + admin.createTable(getNamespace(), getTable(), TABLE_METADATA, options); } protected Map getCreationOptions() { @@ -166,11 +152,11 @@ protected void afterEach() throws Exception { @Test public void repairTable_ForExistingTableAndMetadata_ShouldDoNothing() throws Exception { // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); } @Test @@ -181,13 +167,13 @@ public void repairTableAndCoordinatorTables_ForDeletedMetadataTable_ShouldRepair // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); admin.repairCoordinatorTables(getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(admin.tableExists(getNamespace(), TABLE)).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(TABLE_METADATA); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -198,12 +184,12 @@ public void repairTableAndCoordinatorTables_ForTruncatedMetadataTable_ShouldRepa adminTestUtils.truncateMetadataTable(); // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); admin.repairCoordinatorTables(getCreationOptions()); // Assert assertThat(admin.tableExists(getNamespace(), TABLE)).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), TABLE)).isEqualTo(TABLE_METADATA); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -213,11 +199,11 @@ public void repairTable_ForCorruptedMetadataTable_ShouldRepairProperly() throws adminTestUtils.corruptMetadata(getNamespace(), getTable()); // Act - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert assertThat(admin.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -253,12 +239,12 @@ public void repairTable_ForNonExistingTableButExistingMetadata_ShouldCreateTable // Act waitForDifferentSessionDdl(); - admin.repairTable(getNamespace(), getTable(), getTableMetadata(), getCreationOptions()); + admin.repairTable(getNamespace(), getTable(), TABLE_METADATA, getCreationOptions()); // Assert waitForDifferentSessionDdl(); assertThat(adminTestUtils.tableExists(getNamespace(), getTable())).isTrue(); - assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(getTableMetadata()); + assertThat(admin.getTableMetadata(getNamespace(), getTable())).isEqualTo(TABLE_METADATA); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -331,8 +317,4 @@ private boolean coordinatorNamespaceMetadataExits() throws ExecutionException { .orElse(Coordinator.NAMESPACE); return storageAdmin.namespaceExists(coordinatorNamespace); } - - protected boolean isTimestampTypeSupported() { - return true; - } } diff --git a/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java index 29e7be5357..927edfaeda 100644 --- a/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderIntegrationTestBase.java @@ -51,6 +51,34 @@ public abstract class SchemaLoaderIntegrationTestBase { private static final String TABLE_1 = "test_table1"; private static final String NAMESPACE_2 = "int_test_" + TEST_NAME + "2"; private static final String TABLE_2 = "test_table2"; + private static final TableMetadata TABLE_1_METADATA = + TableMetadata.newBuilder() + .addPartitionKey("pk1") + .addClusteringKey("ck1", Order.DESC) + .addClusteringKey("ck2", Order.ASC) + .addColumn("pk1", DataType.INT) + .addColumn("ck1", DataType.INT) + .addColumn("ck2", DataType.TEXT) + .addColumn("col1", DataType.INT) + .addColumn("col2", DataType.BIGINT) + .addColumn("col3", DataType.FLOAT) + .addColumn("col4", DataType.DOUBLE) + .addColumn("col5", DataType.TEXT) + .addColumn("col6", DataType.BLOB) + .addColumn("col7", DataType.BOOLEAN) + .addSecondaryIndex("col1") + .addSecondaryIndex("col5") + .build(); + private static final TableMetadata TABLE_2_METADATA = + TableMetadata.newBuilder() + .addPartitionKey("pk1") + .addClusteringKey("ck1", Order.ASC) + .addColumn("pk1", DataType.INT) + .addColumn("ck1", DataType.INT) + .addColumn("col1", DataType.INT) + .addColumn("col2", DataType.BIGINT) + .addColumn("col3", DataType.FLOAT) + .build(); private DistributedStorageAdmin storageAdmin; private DistributedTransactionAdmin transactionAdmin; @@ -59,45 +87,6 @@ public abstract class SchemaLoaderIntegrationTestBase { private String systemNamespaceName; private AdminTestUtils adminTestUtils; - private TableMetadata getTable1Metadata() { - TableMetadata.Builder builder = - TableMetadata.newBuilder() - .addPartitionKey("pk1") - .addClusteringKey("ck1", Order.DESC) - .addClusteringKey("ck2", Order.ASC) - .addColumn("pk1", DataType.INT) - .addColumn("ck1", DataType.INT) - .addColumn("ck2", DataType.TEXT) - .addColumn("col1", DataType.INT) - .addColumn("col2", DataType.BIGINT) - .addColumn("col3", DataType.FLOAT) - .addColumn("col4", DataType.DOUBLE) - .addColumn("col5", DataType.TEXT) - .addColumn("col6", DataType.BLOB) - .addColumn("col7", DataType.BOOLEAN) - .addColumn("col8", DataType.DATE) - .addColumn("col9", DataType.TIME) - .addColumn("col10", DataType.TIMESTAMPTZ); - if (isTimestampTypeSupported()) { - builder.addColumn("col11", DataType.TIMESTAMP); - } - - builder.addSecondaryIndex("col1").addSecondaryIndex("col5"); - return builder.build(); - } - - private TableMetadata getTable2Metadata() { - return TableMetadata.newBuilder() - .addPartitionKey("pk1") - .addClusteringKey("ck1", Order.ASC) - .addColumn("pk1", DataType.INT) - .addColumn("ck1", DataType.INT) - .addColumn("col1", DataType.INT) - .addColumn("col2", DataType.BIGINT) - .addColumn("col3", DataType.FLOAT) - .build(); - } - @BeforeAll public void beforeAll() throws Exception { initialize(TEST_NAME); @@ -168,12 +157,6 @@ protected Map getSchemaJsonMap() { .put("col5", "TEXT") .put("col6", "BLOB") .put("col7", "BOOLEAN") - .put("col8", "DATE") - .put("col9", "TIME") - .putAll( - isTimestampTypeSupported() - ? ImmutableMap.of("col10", "TIMESTAMPTZ", "col11", "TIMESTAMP") - : ImmutableMap.of("col10", "TIMESTAMPTZ")) .build()) .put("secondary-index", Arrays.asList("col1", "col5")) .build(), @@ -210,16 +193,10 @@ protected Map getAlteredSchemaJsonMap() { .put("col5", "TEXT") .put("col6", "BLOB") .put("col7", "BOOLEAN") - .put("col8", "DATE") - .put("col9", "TIME") - .putAll( - isTimestampTypeSupported() - ? ImmutableMap.of("col10", "TIMESTAMPTZ", "col11", "TIMESTAMP") - : ImmutableMap.of("col10", "TIMESTAMPTZ")) - .put("col12", "TEXT") - .put("col13", "BLOB") + .put("col8", "TEXT") + .put("col9", "BLOB") .build()) - .put("secondary-index", Arrays.asList("col3", "col12")) + .put("secondary-index", Arrays.asList("col3", "col8")) .put("compaction-strategy", "LCS") .put("network-strategy", "SimpleStrategy") .put("replication-factor", "1") @@ -425,9 +402,8 @@ public void createTablesThenDropTablesThenRepairAllWithoutCoordinator_ShouldExec assertThat(storageAdmin.namespaceExists(namespace2)).isTrue(); assertThat(adminTestUtils.tableExists(namespace1, TABLE_1)).isTrue(); assertThat(adminTestUtils.tableExists(namespace2, TABLE_2)).isTrue(); - assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)) - .isEqualTo(getTable1Metadata()); - assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(getTable2Metadata()); + assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)).isEqualTo(TABLE_1_METADATA); + assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(TABLE_2_METADATA); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isFalse(); } @@ -457,9 +433,8 @@ public void createTablesThenDropTablesThenRepairAllWithCoordinator_ShouldExecute assertThat(storageAdmin.namespaceExists(namespace2)).isTrue(); assertThat(adminTestUtils.tableExists(namespace1, TABLE_1)).isTrue(); assertThat(adminTestUtils.tableExists(namespace2, TABLE_2)).isTrue(); - assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)) - .isEqualTo(getTable1Metadata()); - assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(getTable2Metadata()); + assertThat(transactionAdmin.getTableMetadata(namespace1, TABLE_1)).isEqualTo(TABLE_1_METADATA); + assertThat(storageAdmin.getTableMetadata(namespace2, TABLE_2)).isEqualTo(TABLE_2_METADATA); assertThat(adminTestUtils.areTableAndMetadataForCoordinatorTablesPresent()).isTrue(); } @@ -472,16 +447,16 @@ public void createTableThenAlterTables_ShouldExecuteProperly() throws Exception assertThat(exitCodeCreation).isZero(); TableMetadata expectedTable1Metadata = - TableMetadata.newBuilder(getTable1Metadata()) - .addColumn("col12", DataType.TEXT) - .addColumn("col13", DataType.BLOB) + TableMetadata.newBuilder(TABLE_1_METADATA) + .addColumn("col8", DataType.TEXT) + .addColumn("col9", DataType.BLOB) .removeSecondaryIndex("col1") .removeSecondaryIndex("col5") .addSecondaryIndex("col3") - .addSecondaryIndex("col12") + .addSecondaryIndex("col8") .build(); TableMetadata expectedTable2Metadata = - TableMetadata.newBuilder(getTable2Metadata()).addColumn("col4", DataType.TEXT).build(); + TableMetadata.newBuilder(TABLE_2_METADATA).addColumn("col4", DataType.TEXT).build(); // Act int exitCodeAlteration = @@ -580,8 +555,4 @@ private int executeWithArgs(List args) { protected void waitForCreationIfNecessary() { // Do nothing } - - protected boolean isTimestampTypeSupported() { - return true; - } } diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java index fb18d7e045..26ffa79330 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java @@ -35,10 +35,6 @@ public class TableSchema { .put("DOUBLE", DataType.DOUBLE) .put("TEXT", DataType.TEXT) .put("BLOB", DataType.BLOB) - .put("DATE", DataType.DATE) - .put("TIME", DataType.TIME) - .put("TIMESTAMP", DataType.TIMESTAMP) - .put("TIMESTAMPTZ", DataType.TIMESTAMPTZ) .build(); private static final ImmutableMap ORDER_MAP = ImmutableMap.builder().put("ASC", Order.ASC).put("DESC", Order.DESC).build(); diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java index 13bb5dca26..f54f2d59f9 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/TableSchemaTest.java @@ -152,13 +152,7 @@ public void buildOptions_OptionsMapFromTableDefinitionAndOptionsGiven_ShouldRetu + " \"c3\": \"BLOB\"," + " \"c4\": \"INT\"," + " \"c5\": \"BOOLEAN\"," - + " \"c6\": \"FLOAT\"," - + " \"c7\": \"DOUBLE\"," - + " \"c8\": \"BIGINT\"," - + " \"c9\": \"DATE\"," - + " \"c10\": \"TIME\"," - + " \"c11\": \"TIMESTAMP\"," - + " \"c12\": \"TIMESTAMPTZ\"" + + " \"c6\": \"INT\"" + "}," + "\"ru\": 5000," + "\"compaction-strategy\": \"LCS\"," @@ -177,13 +171,7 @@ public void buildOptions_OptionsMapFromTableDefinitionAndOptionsGiven_ShouldRetu tableBuilder.addColumn("c3", DataType.BLOB); tableBuilder.addColumn("c4", DataType.INT); tableBuilder.addColumn("c5", DataType.BOOLEAN); - tableBuilder.addColumn("c6", DataType.FLOAT); - tableBuilder.addColumn("c7", DataType.DOUBLE); - tableBuilder.addColumn("c8", DataType.BIGINT); - tableBuilder.addColumn("c9", DataType.DATE); - tableBuilder.addColumn("c10", DataType.TIME); - tableBuilder.addColumn("c11", DataType.TIMESTAMP); - tableBuilder.addColumn("c12", DataType.TIMESTAMPTZ); + tableBuilder.addColumn("c6", DataType.INT); TableMetadata expectedTableMetadata = tableBuilder.build(); // Act