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 @@ -11,6 +11,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 @@ -202,6 +203,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 @@ -424,20 +424,6 @@ public void renameTable(String namespace, String oldTableName, String newTableNa
}
}

@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 @@ -462,20 +448,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 Set<String> getNamespaceNames() throws ExecutionException {
logger.warn(
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 @@ -232,20 +232,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 @@ -614,18 +614,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 @@ -1265,18 +1265,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
58 changes: 17 additions & 41 deletions core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public JdbcAdmin(BasicDataSource dataSource, JdbcConfig config) {
@Override
public void createNamespace(String namespace, Map<String, String> options)
throws ExecutionException {
rdbEngine.throwIfInvalidNamespaceName(namespace);

String fullNamespace = enclose(namespace);
try (Connection connection = dataSource.getConnection()) {
execute(connection, rdbEngine.createNamespaceSqls(fullNamespace));
Expand All @@ -101,9 +103,7 @@ public void createNamespace(String namespace, Map<String, String> options)
public void createTable(
String namespace, String table, TableMetadata metadata, Map<String, String> options)
throws ExecutionException {
if (!rdbEngine.isValidTableName(table)) {
throw new ExecutionException("Table name is not acceptable: " + table);
}
rdbEngine.throwIfInvalidTableName(table);

try (Connection connection = dataSource.getConnection()) {
// Create the metadata schema and table first if they do not exist
Expand Down Expand Up @@ -157,7 +157,8 @@ private void createIndex(
}
}

private void addTableMetadata(
@VisibleForTesting
void addTableMetadata(
Connection connection,
String namespace,
String table,
Expand Down Expand Up @@ -465,18 +466,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 @@ -530,10 +526,15 @@ public void importTable(
Map<String, String> options,
Map<String, DataType> overrideColumnsType)
throws ExecutionException {
TableMetadata tableMetadata = getImportTableMetadata(namespace, table, overrideColumnsType);
rdbEngine.throwIfImportNotSupported();

// add ScalarDB metadata
repairTable(namespace, table, tableMetadata, options);
try (Connection connection = dataSource.getConnection()) {
TableMetadata tableMetadata = getImportTableMetadata(namespace, table, overrideColumnsType);
addTableMetadata(connection, namespace, table, tableMetadata, true);
} catch (SQLException | ExecutionException e) {
throw new ExecutionException(
String.format("Importing the %s table failed", getFullTableName(namespace, table)), e);
}
}

private String getSelectColumnsStatement() {
Expand Down Expand Up @@ -770,6 +771,8 @@ private boolean tableExistsInternal(Connection connection, String namespace, Str
public void repairTable(
String namespace, String table, TableMetadata metadata, Map<String, String> options)
throws ExecutionException {
rdbEngine.throwIfInvalidNamespaceName(table);

try (Connection connection = dataSource.getConnection()) {
if (!tableExistsInternal(connection, namespace, table)) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -951,33 +954,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 column %s to the %s.%s table failed", columnName, namespace, table),
e);
}
}

@Override
public Set<String> getNamespaceNames() throws ExecutionException {
String selectAllTableNames =
Expand Down
Loading