Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,6 @@ protected void waitForTableDeletion() {
}
}

@Test
@Override
@Disabled("Import-related functionality is not supported in Cassandra")
public void getImportTableMetadata_WithSufficientPermission_ShouldSucceed() {}

@Test
@Override
@Disabled("Import-related functionality is not supported in Cassandra")
public void addRawColumnToTable_WithSufficientPermission_ShouldSucceed() {}

@Test
@Override
@Disabled("Import-related functionality is not supported in Cassandra")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ protected void sleepBetweenTests() {
Uninterruptibles.sleepUninterruptibly(SLEEP_BETWEEN_TESTS_SECONDS, TimeUnit.SECONDS);
}

@Test
@Override
@Disabled("Import-related functionality is not supported in DynamoDB")
public void getImportTableMetadata_WithSufficientPermission_ShouldSucceed() {}

@Test
@Override
@Disabled("Import-related functionality is not supported in DynamoDB")
public void addRawColumnToTable_WithSufficientPermission_ShouldSucceed() {}

@Test
@Override
@Disabled("Import-related functionality is not supported in DynamoDB")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
import org.slf4j.Logger;
Expand Down Expand Up @@ -191,6 +192,7 @@ public void importTables_ImportableTablesAndNonRelatedSameNameTableGiven_ShouldI
super.importTables_ImportableTablesAndNonRelatedSameNameTableGiven_ShouldImportProperly();
}

@AfterAll
@Override
public void afterAll() {
try {
Expand Down
47 changes: 0 additions & 47 deletions core/src/main/java/com/scalar/db/api/DistributedStorageAdmin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.scalar.db.api;

import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.io.DataType;
import java.util.Collections;
import java.util.Map;

/**
* An administrative interface for distributed storage implementations. The user can execute
Expand Down Expand Up @@ -44,50 +41,6 @@
*/
public interface DistributedStorageAdmin extends Admin, AutoCloseable {

/**
* Get import table metadata in the ScalarDB format.
*
* @param namespace namespace name of import table
* @param table import table name
* @throws IllegalArgumentException if the table does not exist
* @throws IllegalStateException if the table does not meet the requirement of ScalarDB table
* @throws ExecutionException if the operation fails
* @return import table metadata in the ScalarDB format
*/
default TableMetadata getImportTableMetadata(String namespace, String table)
throws ExecutionException {
return getImportTableMetadata(namespace, table, Collections.emptyMap());
}

/**
* Get import table metadata in the ScalarDB format.
*
* @param namespace namespace name of import table
* @param table import table name
* @param overrideColumnsType a map of column data type by column name. Only set the column for
* which you want to override the default data type mapping.
* @throws IllegalArgumentException if the table does not exist
* @throws IllegalStateException if the table does not meet the requirement of ScalarDB table
* @throws ExecutionException if the operation fails
* @return import table metadata in the ScalarDB format
*/
TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType)
throws ExecutionException;

/**
* Add a column in the table without updating the metadata table in ScalarDB.
*
* @param namespace namespace name of import table
* @param table import table name
* @param columnName name of the column to be added
* @param columnType type of the column to be added
* @throws IllegalArgumentException if the table does not exist
* @throws ExecutionException if the operation fails
*/
void addRawColumnToTable(String namespace, String table, String columnName, DataType columnType)
throws ExecutionException;

/**
* Returns the storage information.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,20 +451,6 @@ public Set<String> getNamespaceNames() throws ExecutionException {
}
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType)
throws ExecutionException {
try {
return admin.getImportTableMetadata(namespace, table, overrideColumnsType);
} catch (ExecutionException e) {
throw new ExecutionException(
CoreError.GETTING_IMPORT_TABLE_METADATA_FAILED.buildMessage(
ScalarDbUtils.getFullTableName(namespace, table)),
e);
}
}

@Override
public void importTable(
String namespace,
Expand All @@ -489,20 +475,6 @@ public void importTable(
}
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType)
throws ExecutionException {
try {
admin.addRawColumnToTable(namespace, table, columnName, columnType);
} catch (ExecutionException e) {
throw new ExecutionException(
CoreError.ADDING_RAW_COLUMN_TO_TABLE_FAILED.buildMessage(
ScalarDbUtils.getFullTableName(namespace, table), columnName, columnType),
e);
}
}

@Override
public void upgrade(Map<String, String> options) throws ExecutionException {
try {
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/com/scalar/db/common/CoreError.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,16 @@ public enum CoreError implements ScalarDbError {
""),
MULTI_STORAGE_STORAGE_NOT_FOUND(
Category.USER_ERROR, "0084", "Storage not found. Storage: %s", "", ""),
JDBC_NAMESPACE_NAME_NOT_ACCEPTABLE(
Category.USER_ERROR, "0085", "The namespace name is not acceptable. Namespace: %s", "", ""),
JDBC_TABLE_NAME_NOT_ACCEPTABLE(
Category.USER_ERROR, "0086", "The table name is not acceptable. Table: %s", "", ""),
JDBC_IMPORT_NOT_SUPPORTED(
JDBC_SQLITE_NAMESPACE_NAME_NOT_ACCEPTABLE(
Category.USER_ERROR,
"0087",
"Importing tables is not allowed in the RDB engine. RDB engine: %s",
"0085",
"The namespace name is not acceptable in SQLite. Namespace: %s",
"",
""),
JDBC_SQLITE_TABLE_NAME_NOT_ACCEPTABLE(
Category.USER_ERROR, "0086", "The table name is not acceptable in SQLite. Table: %s", "", ""),
JDBC_SQLITE_IMPORT_NOT_SUPPORTED(
Category.USER_ERROR, "0087", "Importing tables is not allowed in SQLite", "", ""),
JDBC_IMPORT_TABLE_WITHOUT_PRIMARY_KEY(
Category.USER_ERROR, "0088", "The %s table must have a primary key", "", ""),
JDBC_RDB_ENGINE_NOT_SUPPORTED(
Expand Down
14 changes: 0 additions & 14 deletions core/src/main/java/com/scalar/db/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,6 @@ public void renameTable(String namespace, String oldTableName, String newTableNa
admin.renameTable(namespace, oldTableName, newTableName);
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType)
throws ExecutionException {
return admin.getImportTableMetadata(namespace, table, overrideColumnsType);
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType)
throws ExecutionException {
admin.addRawColumnToTable(namespace, table, columnName, columnType);
}

@Override
public void importTable(
String namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,6 @@ private TableMetadata createTableMetadata(com.datastax.driver.core.TableMetadata
return builder.build();
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType) {
throw new UnsupportedOperationException(
CoreError.CASSANDRA_IMPORT_NOT_SUPPORTED.buildMessage());
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType) {
throw new UnsupportedOperationException(
CoreError.CASSANDRA_IMPORT_NOT_SUPPORTED.buildMessage());
}

@Override
public void importTable(
String namespace,
Expand Down
12 changes: 0 additions & 12 deletions core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,6 @@ public void renameTable(String namespace, String oldTableName, String newTableNa
CoreError.COSMOS_RENAME_TABLE_NOT_SUPPORTED.buildMessage());
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType) {
throw new UnsupportedOperationException(CoreError.COSMOS_IMPORT_NOT_SUPPORTED.buildMessage());
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType) {
throw new UnsupportedOperationException(CoreError.COSMOS_IMPORT_NOT_SUPPORTED.buildMessage());
}

@Override
public void importTable(
String namespace,
Expand Down
12 changes: 0 additions & 12 deletions core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1466,18 +1466,6 @@ public void renameTable(String namespace, String oldTableName, String newTableNa
CoreError.DYNAMO_RENAME_TABLE_NOT_SUPPORTED.buildMessage());
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType) {
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType) {
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
}

@Override
public void importTable(
String namespace,
Expand Down
59 changes: 12 additions & 47 deletions core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ static void execute(
@Override
public void createNamespace(String namespace, Map<String, String> options)
throws ExecutionException {
if (!rdbEngine.isValidNamespaceOrTableName(namespace)) {
throw new IllegalArgumentException(
CoreError.JDBC_NAMESPACE_NAME_NOT_ACCEPTABLE.buildMessage(namespace));
}
rdbEngine.throwIfInvalidNamespaceName(namespace);

try (Connection connection = dataSource.getConnection()) {
execute(connection, rdbEngine.createSchemaSqls(namespace));
createNamespacesTableIfNotExists(connection);
Expand Down Expand Up @@ -182,10 +180,8 @@ void createTableInternal(
TableMetadata metadata,
boolean ifNotExists)
throws SQLException {
if (!rdbEngine.isValidNamespaceOrTableName(table)) {
throw new IllegalArgumentException(
CoreError.JDBC_TABLE_NAME_NOT_ACCEPTABLE.buildMessage(table));
}
rdbEngine.throwIfInvalidTableName(table);

String createTableStatement = "CREATE TABLE " + encloseFullTableName(schema, table) + "(";
// Order the columns for their creation by (partition keys >> clustering keys >> other columns)
LinkedHashSet<String> sortedColumnNames =
Expand Down Expand Up @@ -571,18 +567,13 @@ public TableMetadata getTableMetadata(String namespace, String table) throws Exe
return builder.build();
}

@Override
public TableMetadata getImportTableMetadata(
@VisibleForTesting
TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType)
throws ExecutionException {
TableMetadata.Builder builder = TableMetadata.newBuilder();
boolean primaryKeyExists = false;

if (!rdbEngine.isImportable()) {
throw new UnsupportedOperationException(
CoreError.JDBC_IMPORT_NOT_SUPPORTED.buildMessage(rdbEngine.getClass().getName()));
}

try (Connection connection = dataSource.getConnection()) {
rdbEngine.setConnectionToReadOnly(connection, true);

Expand Down Expand Up @@ -640,6 +631,8 @@ public void importTable(
Map<String, String> options,
Map<String, DataType> overrideColumnsType)
throws ExecutionException {
rdbEngine.throwIfImportNotSupported();

try (Connection connection = dataSource.getConnection()) {
TableMetadata tableMetadata = getImportTableMetadata(namespace, table, overrideColumnsType);
createNamespacesTableIfNotExists(connection);
Expand Down Expand Up @@ -876,10 +869,8 @@ private boolean tableExistsInternal(Connection connection, String namespace, Str
@Override
public void repairNamespace(String namespace, Map<String, String> options)
throws ExecutionException {
if (!rdbEngine.isValidNamespaceOrTableName(namespace)) {
throw new IllegalArgumentException(
CoreError.JDBC_NAMESPACE_NAME_NOT_ACCEPTABLE.buildMessage(namespace));
}
rdbEngine.throwIfInvalidNamespaceName(namespace);

try (Connection connection = dataSource.getConnection()) {
createSchemaIfNotExists(connection, namespace);
createNamespacesTableIfNotExists(connection);
Expand All @@ -893,6 +884,8 @@ public void repairNamespace(String namespace, Map<String, String> options)
public void repairTable(
String namespace, String table, TableMetadata metadata, Map<String, String> options)
throws ExecutionException {
rdbEngine.throwIfInvalidNamespaceName(table);

try (Connection connection = dataSource.getConnection()) {
createTableInternal(connection, namespace, table, metadata, true);
addTableMetadata(connection, namespace, table, metadata, true, true);
Expand Down Expand Up @@ -1060,34 +1053,6 @@ public void renameTable(String namespace, String oldTableName, String newTableNa
}
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType)
throws ExecutionException {
try (Connection connection = dataSource.getConnection()) {
if (!tableExistsInternal(connection, namespace, table)) {
throw new IllegalArgumentException(
CoreError.TABLE_NOT_FOUND.buildMessage(getFullTableName(namespace, table)));
}

String addNewColumnStatement =
"ALTER TABLE "
+ encloseFullTableName(namespace, table)
+ " ADD "
+ enclose(columnName)
+ " "
+ rdbEngine.getDataTypeForEngine(columnType);

execute(connection, addNewColumnStatement);
} catch (SQLException e) {
throw new ExecutionException(
String.format(
"Adding the new %s column to the %s table failed",
columnName, getFullTableName(namespace, table)),
e);
}
}

@VisibleForTesting
void createIndex(
Connection connection, String schema, String table, String indexedColumn, boolean ifNotExists)
Expand Down
Loading