http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java index a3eb0c3..cd8dcb6 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java @@ -22,29 +22,31 @@ package org.apache.tajo.catalog.store; import com.google.protobuf.InvalidProtocolBufferException; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.tajo.annotation.Nullable; -import org.apache.tajo.catalog.*; -import org.apache.tajo.catalog.exception.*; +import org.apache.tajo.catalog.CatalogConstants; +import org.apache.tajo.catalog.CatalogUtil; +import org.apache.tajo.catalog.FunctionDesc; +import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.*; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.common.TajoDataTypes.Type; import org.apache.tajo.conf.TajoConf; -import org.apache.tajo.exception.InternalException; -import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.exception.*; import org.apache.tajo.util.FileUtil; import org.apache.tajo.util.Pair; import org.apache.tajo.util.TUtil; import java.io.IOException; import java.sql.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; -import static org.apache.tajo.catalog.exception.CatalogExceptionUtil.makeCatalogUpgrade; import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand; import static org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto; import static org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueSetProto; @@ -85,19 +87,18 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo protected abstract Connection createConnection(final Configuration conf) throws SQLException; - protected void createDatabaseDependants() throws CatalogException { - + protected void createDatabaseDependants() { } - protected boolean isInitialized() throws CatalogException { + protected boolean isInitialized() { return catalogSchemaManager.isInitialized(getConnection()); } - protected boolean catalogAlreadyExists() throws CatalogException { + protected boolean catalogAlreadyExists() { return catalogSchemaManager.catalogAlreadyExists(getConnection()); } - protected void createBaseTable() throws CatalogException { + protected void createBaseTable() { createDatabaseDependants(); catalogSchemaManager.createBaseSchema(getConnection()); @@ -105,11 +106,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo insertSchemaVersion(); } - protected void dropBaseTable() throws CatalogException { + protected void dropBaseTable() { catalogSchemaManager.dropBaseSchema(getConnection()); } - public AbstractDBStore(Configuration conf) throws InternalException { + public AbstractDBStore(Configuration conf) { this.conf = conf; if (conf.get(CatalogConstants.DEPRECATED_CATALOG_URI) != null) { @@ -169,9 +170,9 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo try { createBaseTable(); LOG.info("The base tables of CatalogServer are created."); - } catch (CatalogException ce) { + } catch (Throwable e) { dropBaseTable(); - throw ce; + throw e; } } } @@ -184,7 +185,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo return catalogSchemaManager.getCatalogStore().getSchema().getVersion(); } - public String readSchemaFile(String path) throws CatalogException { + public String readSchemaFile(String path) { try { return FileUtil.readTextFileFromResource("schemas/" + path); } catch (IOException e) { @@ -248,7 +249,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo return schemaVersion; } - private void verifySchemaVersion() throws CatalogException { + private void verifySchemaVersion() throws CatalogUpgradeRequiredException { int schemaVersion = -1; schemaVersion = getSchemaVersion(); @@ -264,7 +265,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo LOG.error("| In order to learn how to migration Apache Tajo instance, |"); LOG.error("| please refer http://tajo.apache.org/docs/current/backup_and_restore/catalog.html |"); LOG.error("========================================================================="); - throw makeCatalogUpgrade(); + throw new CatalogUpgradeRequiredException(); } LOG.info(String.format("The compatibility of the catalog schema (version: %d) has been verified.", @@ -274,7 +275,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo /** * Insert the version of the current catalog schema */ - protected void insertSchemaVersion() throws CatalogException { + protected void insertSchemaVersion() { Connection conn; PreparedStatement pstmt = null; try { @@ -290,7 +291,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void createTablespace(String spaceName, String spaceUri) throws CatalogException { + public void createTablespace(String spaceName, String spaceUri) { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -325,7 +326,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public boolean existTablespace(String tableSpaceName) throws CatalogException { + public boolean existTablespace(String tableSpaceName) { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -353,8 +354,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void dropTablespace(String tableSpaceName) throws CatalogException { - + public void dropTablespace(String tableSpaceName) throws UndefinedTablespaceException { Connection conn = null; PreparedStatement pstmt = null; @@ -366,7 +366,12 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo conn.setAutoCommit(false); for (String databaseName : databaseNames) { - dropDatabase(databaseName); + try { + dropDatabase(databaseName); + } catch (UndefinedDatabaseException e) { + LOG.warn(e); + continue; + } } String sql = "DELETE FROM " + TB_SPACES + " WHERE " + COL_TABLESPACE_PK + "= ?"; @@ -389,11 +394,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public Collection<String> getAllTablespaceNames() throws CatalogException { + public Collection<String> getAllTablespaceNames() { return getAllTablespaceNamesInternal(null); } - private Collection<String> getAllTablespaceNamesInternal(@Nullable String whereCondition) throws CatalogException { + private Collection<String> getAllTablespaceNamesInternal(@Nullable String whereCondition) { Connection conn = null; PreparedStatement pstmt = null; ResultSet resultSet = null; @@ -423,7 +428,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<TablespaceProto> getTablespaces() throws CatalogException { + public List<TablespaceProto> getTablespaces() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -454,7 +459,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public TablespaceProto getTablespace(String spaceName) throws CatalogException { + public TablespaceProto getTablespace(String spaceName) throws UndefinedTablespaceException { Connection conn = null; PreparedStatement pstmt = null; ResultSet resultSet = null; @@ -486,7 +491,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void alterTablespace(AlterTablespaceProto alterProto) throws CatalogException { + public void alterTablespace(AlterTablespaceProto alterProto) { Connection conn; PreparedStatement pstmt = null; @@ -512,11 +517,17 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void createDatabase(String databaseName, String tablespaceName) throws CatalogException { + public void createDatabase(String databaseName, String tablespaceName) + throws UndefinedTablespaceException, DuplicateDatabaseException { + Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; + if (existDatabase(databaseName)) { + throw new DuplicateDatabaseException(databaseName); + } + try { TableSpaceInternal spaceInfo = getTableSpaceInfo(tablespaceName); @@ -549,7 +560,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public boolean existDatabase(String databaseName) throws CatalogException { + public boolean existDatabase(String databaseName) { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -577,7 +588,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void dropDatabase(String databaseName) throws CatalogException { + public void dropDatabase(String databaseName) throws UndefinedDatabaseException { Collection<String> tableNames = getAllTableNames(databaseName); Connection conn = null; @@ -587,7 +598,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo conn.setAutoCommit(false); for (String tableName : tableNames) { - dropTableInternal(conn, databaseName, tableName); + try { + dropTableInternal(conn, databaseName, tableName); + } catch (UndefinedTableException e) { + LOG.warn(e); + } } String sql = "DELETE FROM " + TB_DATABASES + " WHERE DB_NAME = ?"; @@ -610,11 +625,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public Collection<String> getAllDatabaseNames() throws CatalogException { + public Collection<String> getAllDatabaseNames() { return getAllDatabaseNamesInternal(null); } - private Collection<String> getAllDatabaseNamesInternal(@Nullable String whereCondition) throws CatalogException { + private Collection<String> getAllDatabaseNamesInternal(@Nullable String whereCondition) { Connection conn = null; PreparedStatement pstmt = null; ResultSet resultSet = null; @@ -644,7 +659,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<DatabaseProto> getAllDatabases() throws CatalogException { + public List<DatabaseProto> getAllDatabases() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -711,17 +726,17 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt.setString(1, spaceName); res = pstmt.executeQuery(); if (!res.next()) { - throw new TajoInternalError("There is no SPACE_ID matched to the space name '" + spaceName + "'"); + throw new UndefinedTablespaceException(spaceName); } return new TableSpaceInternal(res.getInt(1), res.getString(2), res.getString(3)); } catch (SQLException se) { - throw new UndefinedTablespaceException(spaceName); + throw new TajoInternalError(se); } finally { CatalogUtil.closeQuietly(pstmt, res); } } - private int getTableId(int databaseId, String databaseName, String tableName) { + private int getTableId(int databaseId, String databaseName, String tableName) throws UndefinedTableException { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -734,7 +749,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt.setString(2, tableName); res = pstmt.executeQuery(); if (!res.next()) { - throw new TajoInternalError("There is no tid matched to '" + tableName + "'"); + throw new UndefinedTableException(databaseName, tableName); } return res.getInt(1); } catch (SQLException se) { @@ -750,25 +765,30 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void createTable(final CatalogProtos.TableDescProto table) throws CatalogException { + public void createTable(final CatalogProtos.TableDescProto table) + throws UndefinedDatabaseException, DuplicateTableException { + Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; + String[] splitted = CatalogUtil.splitTableName(table.getTableName()); + if (splitted.length == 1) { + throw new TajoInternalError( + "createTable() requires a qualified table name, but it is '" + table.getTableName() + "'"); + } + final String databaseName = splitted[0]; + final String tableName = splitted[1]; + + if (existTable(databaseName, tableName)) { + throw new DuplicateTableException(tableName); + } + final int dbid = getDatabaseId(databaseName); + try { conn = getConnection(); conn.setAutoCommit(false); - String[] splitted = CatalogUtil.splitTableName(table.getTableName()); - if (splitted.length == 1) { - throw new TajoInternalError( - "createTable() requires a qualified table name, but it is '" + table.getTableName() + "'"); - } - String databaseName = splitted[0]; - String tableName = splitted[1]; - - int dbid = getDatabaseId(databaseName); - String sql = "INSERT INTO TABLES (DB_ID, " + COL_TABLES_NAME + ", TABLE_TYPE, PATH, STORE_TYPE) VALUES(?, ?, ?, ?, ?) "; @@ -900,26 +920,26 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void updateTableStats(final CatalogProtos.UpdateTableStatsProto statsProto) throws - CatalogException { + public void updateTableStats(final CatalogProtos.UpdateTableStatsProto statsProto) + throws UndefinedDatabaseException, UndefinedTableException { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; + String[] splitted = CatalogUtil.splitTableName(statsProto.getTableName()); + if (splitted.length == 1) { + throw new IllegalArgumentException("updateTableStats() requires a qualified table name, but it is \"" + + statsProto.getTableName() + "\"."); + } + final String databaseName = splitted[0]; + final String tableName = splitted[1]; + + final int dbid = getDatabaseId(databaseName); + try { conn = getConnection(); conn.setAutoCommit(false); - String[] splitted = CatalogUtil.splitTableName(statsProto.getTableName()); - if (splitted.length == 1) { - throw new IllegalArgumentException("updateTableStats() requires a qualified table name, but it is \"" - + statsProto.getTableName() + "\"."); - } - String databaseName = splitted[0]; - String tableName = splitted[1]; - - int dbid = getDatabaseId(databaseName); - String tidSql = "SELECT TID from " + TB_TABLES + " WHERE " + COL_DATABASES_PK + "=? AND " + COL_TABLES_NAME + "=?"; pstmt = conn.prepareStatement(tidSql); @@ -928,7 +948,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo res = pstmt.executeQuery(); if (!res.next()) { - throw new TajoInternalError("There is no TID matched to '" + statsProto.getTableName() + "'"); + throw new UndefinedTableException(statsProto.getTableName()); } int tableId = res.getInt("TID"); @@ -968,66 +988,66 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException { + public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) + throws UndefinedDatabaseException, DuplicateTableException, DuplicateColumnException, + DuplicatePartitionException, UndefinedPartitionException, UndefinedColumnException, UndefinedTableException, + UndefinedPartitionMethodException { String[] splitted = CatalogUtil.splitTableName(alterTableDescProto.getTableName()); if (splitted.length == 1) { throw new IllegalArgumentException("alterTable() requires a qualified table name, but it is \"" + alterTableDescProto.getTableName() + "\"."); } - String databaseName = splitted[0]; - String tableName = splitted[1]; + final String databaseName = splitted[0]; + final String tableName = splitted[1]; String partitionName = null; CatalogProtos.PartitionDescProto partitionDesc = null; - try { - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - - switch (alterTableDescProto.getAlterTableType()) { - case RENAME_TABLE: - if (existTable(databaseName,alterTableDescProto.getNewTableName())) { - throw new DuplicateTableException(alterTableDescProto.getNewTableName()); - } - renameTable(tableId, alterTableDescProto.getNewTableName()); - break; - case RENAME_COLUMN: - if (existColumn(tableId, alterTableDescProto.getAlterColumnName().getNewColumnName())) { - throw new DuplicateColumnException(alterTableDescProto.getAlterColumnName().getNewColumnName()); - } - renameColumn(tableId, alterTableDescProto.getAlterColumnName()); - break; - case ADD_COLUMN: - if (existColumn(tableId, alterTableDescProto.getAddColumn().getName())) { - throw new DuplicateColumnException(alterTableDescProto.getAddColumn().getName()); - } - addNewColumn(tableId, alterTableDescProto.getAddColumn()); - break; - case ADD_PARTITION: - partitionName = alterTableDescProto.getPartitionDesc().getPartitionName(); - partitionDesc = getPartition(databaseName, tableName, partitionName); - if(partitionDesc != null) { - throw new DuplicatePartitionException(partitionName); - } - addPartition(tableId, alterTableDescProto.getPartitionDesc()); - break; - case DROP_PARTITION: - partitionName = alterTableDescProto.getPartitionDesc().getPartitionName(); - partitionDesc = getPartition(databaseName, tableName, partitionName); - if(partitionDesc == null) { - throw new UndefinedPartitionException(partitionName); - } - dropPartition(partitionDesc.getId()); - break; - case SET_PROPERTY: - setProperties(tableId, alterTableDescProto.getParams()); - break; - default: + int databaseId = getDatabaseId(databaseName); + int tableId = getTableId(databaseId, databaseName, tableName); + + switch (alterTableDescProto.getAlterTableType()) { + case RENAME_TABLE: + if (existTable(databaseName, alterTableDescProto.getNewTableName())) { + throw new DuplicateTableException(alterTableDescProto.getNewTableName()); + } + renameTable(tableId, alterTableDescProto.getNewTableName()); + break; + case RENAME_COLUMN: + if (existColumn(tableId, alterTableDescProto.getAlterColumnName().getNewColumnName())) { + throw new DuplicateColumnException(alterTableDescProto.getAlterColumnName().getNewColumnName()); + } + renameColumn(tableId, alterTableDescProto.getAlterColumnName()); + break; + case ADD_COLUMN: + if (existColumn(tableId, alterTableDescProto.getAddColumn().getName())) { + throw new DuplicateColumnException(alterTableDescProto.getAddColumn().getName()); + } + addNewColumn(tableId, alterTableDescProto.getAddColumn()); + break; + case ADD_PARTITION: + partitionName = alterTableDescProto.getPartitionDesc().getPartitionName(); + try { + // check if it exists + getPartition(databaseName, tableName, partitionName); + throw new DuplicatePartitionException(partitionName); + } catch (UndefinedPartitionException e) { } - } catch (SQLException sqlException) { - throw new TajoInternalError(sqlException); + addPartition(tableId, alterTableDescProto.getPartitionDesc()); + break; + case DROP_PARTITION: + partitionName = alterTableDescProto.getPartitionDesc().getPartitionName(); + partitionDesc = getPartition(databaseName, tableName, partitionName); + if (partitionDesc == null) { + throw new UndefinedPartitionException(partitionName); + } + dropPartition(partitionDesc.getId()); + break; + case SET_PROPERTY: + setProperties(tableId, alterTableDescProto.getParams()); + break; + default: } - } private Map<String, String> getTableOptions(final int tableId) { @@ -1099,7 +1119,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } } - private void renameTable(final int tableId, final String tableName) throws CatalogException { + private void renameTable(final int tableId, final String tableName) { final String updtaeRenameTableSql = "UPDATE " + TB_TABLES + " SET " + COL_TABLES_NAME + " = ? " + " WHERE TID = ?"; @@ -1126,7 +1146,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } private void renameColumn(final int tableId, final CatalogProtos.AlterColumnProto alterColumnProto) - throws CatalogException { + throws UndefinedColumnException { final String selectColumnSql = "SELECT COLUMN_NAME, DATA_TYPE, TYPE_LENGTH, ORDINAL_POSITION, NESTED_FIELD_NUM from " + TB_COLUMNS + @@ -1203,7 +1223,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } } - private void addNewColumn(int tableId, CatalogProtos.ColumnProto columnProto) throws CatalogException { + private void addNewColumn(int tableId, CatalogProtos.ColumnProto columnProto) { final String insertNewColumnSql = "INSERT INTO " + TB_COLUMNS + @@ -1251,7 +1271,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } } - public void addPartition(int tableId, CatalogProtos.PartitionDescProto partition) throws CatalogException { + private void addPartition(int tableId, CatalogProtos.PartitionDescProto partition) { Connection conn = null; PreparedStatement pstmt1 = null, pstmt2 = null; @@ -1297,7 +1317,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } } - private void dropPartition(int partitionId) throws CatalogException { + private void dropPartition(int partitionId) { Connection conn = null; PreparedStatement pstmt1 = null, pstmt2 = null; @@ -1331,7 +1351,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } } - private int getDatabaseId(String databaseName) throws SQLException, UndefinedDatabaseException { + private int getDatabaseId(String databaseName) throws UndefinedDatabaseException { String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES); if (LOG.isDebugEnabled()) { @@ -1352,13 +1372,15 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } return res.getInt("DB_ID"); + } catch (SQLException e) { + throw new TajoInternalError(e); } finally { CatalogUtil.closeQuietly(pstmt, res); } } @Override - public boolean existTable(String databaseName, final String tableName) throws CatalogException { + public boolean existTable(String databaseName, final String tableName) throws UndefinedDatabaseException { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -1390,7 +1412,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } public void dropTableInternal(Connection conn, String databaseName, final String tableName) - throws SQLException, UndefinedDatabaseException { + throws SQLException, UndefinedDatabaseException, UndefinedTableException { PreparedStatement pstmt = null; @@ -1485,7 +1507,9 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void dropTable(String databaseName, final String tableName) throws CatalogException { + public void dropTable(String databaseName, final String tableName) + throws UndefinedDatabaseException, UndefinedTableException { + Connection conn = null; try { conn = getConnection(); @@ -1503,8 +1527,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } } - public Pair<Integer, String> getDatabaseIdAndUri(String databaseName) - throws SQLException, UndefinedDatabaseException { + public Pair<Integer, String> getDatabaseIdAndUri(String databaseName) throws UndefinedDatabaseException { String sql = "SELECT DB_ID, SPACE_URI from " + TB_DATABASES + " natural join " + TB_SPACES + " WHERE db_name = ?"; @@ -1526,7 +1549,9 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo throw new UndefinedDatabaseException(databaseName); } - return new Pair<Integer, String>(res.getInt(1), res.getString(2) + "/" + databaseName); + return new Pair<>(res.getInt(1), res.getString(2) + "/" + databaseName); + } catch (SQLException e) { + throw new TajoInternalError(e); } finally { CatalogUtil.closeQuietly(pstmt, res); } @@ -1534,19 +1559,19 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo @Override public CatalogProtos.TableDescProto getTable(String databaseName, String tableName) - throws CatalogException { - Connection conn = null; + throws UndefinedDatabaseException, UndefinedTableException { + + Connection conn; ResultSet res = null; PreparedStatement pstmt = null; - CatalogProtos.TableDescProto.Builder tableBuilder = null; String storeType; + Pair<Integer, String> databaseIdAndUri = getDatabaseIdAndUri(databaseName); + try { tableBuilder = CatalogProtos.TableDescProto.newBuilder(); - Pair<Integer, String> databaseIdAndUri = getDatabaseIdAndUri(databaseName); - ////////////////////////////////////////// // Geting Table Description ////////////////////////////////////////// @@ -1554,7 +1579,6 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo "SELECT TID, " + COL_TABLES_NAME + ", TABLE_TYPE, PATH, STORE_TYPE FROM TABLES " + "WHERE DB_ID = ? AND " + COL_TABLES_NAME + "=?"; - if (LOG.isDebugEnabled()) { LOG.debug(sql); } @@ -1566,7 +1590,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo res = pstmt.executeQuery(); if (!res.next()) { // there is no table of the given name. - return null; + throw new UndefinedTableException(tableName); } int tableId = res.getInt(1); @@ -1666,7 +1690,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo if (res.next()) { tableBuilder.setPartition(resultToPartitionMethodProto(databaseName, tableName, res)); } - } catch (Throwable se) { + } catch (SQLException se) { throw new TajoInternalError(se); } finally { CatalogUtil.closeQuietly(pstmt, res); @@ -1685,7 +1709,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<String> getAllTableNames(String databaseName) throws CatalogException { + public List<String> getAllTableNames(String databaseName) throws UndefinedDatabaseException { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -1718,7 +1742,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<TableDescriptorProto> getAllTables() throws CatalogException { + public List<TableDescriptorProto> getAllTables() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -1767,7 +1791,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<TableOptionProto> getAllTableProperties() throws CatalogException { + public List<TableOptionProto> getAllTableProperties() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -1802,7 +1826,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<TableStatsProto> getAllTableStats() throws CatalogException { + public List<TableStatsProto> getAllTableStats() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -1834,7 +1858,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<ColumnProto> getAllColumns() throws CatalogException { + public List<ColumnProto> getAllColumns() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -1880,74 +1904,55 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void addPartitionMethod(CatalogProtos.PartitionMethodProto proto) throws CatalogException { + public CatalogProtos.PartitionMethodProto getPartitionMethod(String databaseName, String tableName) throws + UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionMethodException { + Connection conn = null; + ResultSet res = null; PreparedStatement pstmt = null; + final int databaseId = getDatabaseId(databaseName); + final int tableId = getTableId(databaseId, databaseName, tableName); + ensurePartitionTable(tableName, tableId); + try { - String sql = "INSERT INTO " + TB_PARTITION_METHODS - + " (" + COL_TABLES_PK + ", PARTITION_TYPE, EXPRESSION, EXPRESSION_SCHEMA) VALUES (?,?,?,?)"; + String sql = "SELECT partition_type, expression, expression_schema FROM " + TB_PARTITION_METHODS + + " WHERE " + COL_TABLES_PK + " = ? "; if (LOG.isDebugEnabled()) { LOG.debug(sql); } - String databaseName = proto.getTableIdentifier().getDatabaseName(); - String tableName = proto.getTableIdentifier().getTableName(); - - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - conn = getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, tableId); - pstmt.setString(2, proto.getPartitionType().name()); - pstmt.setString(3, proto.getExpression()); - pstmt.setBytes(4, proto.getExpressionSchema().toByteArray()); - pstmt.executeUpdate(); - } catch (SQLException se) { - throw new TajoInternalError(se); - } finally { - CatalogUtil.closeQuietly(pstmt); - } - } - - @Override - public void dropPartitionMethod(String databaseName, String tableName) throws CatalogException { - Connection conn = null; - PreparedStatement pstmt = null; - - try { - String sql = "DELETE FROM " + TB_PARTITION_METHODS + " WHERE " + COL_TABLES_PK + " = ? "; + res = pstmt.executeQuery(); - if (LOG.isDebugEnabled()) { - LOG.debug(sql); + if (res.next()) { + return resultToPartitionMethodProto(databaseName, tableName, res); + } else { + throw new UndefinedPartitionMethodException(tableName); } - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - - conn = getConnection(); - pstmt = conn.prepareStatement(sql); - pstmt.setInt(1, tableId); - pstmt.executeUpdate(); - } catch (SQLException se) { + } catch (Throwable se) { throw new TajoInternalError(se); } finally { - CatalogUtil.closeQuietly(pstmt); + CatalogUtil.closeQuietly(pstmt, res); } } @Override - public CatalogProtos.PartitionMethodProto getPartitionMethod(String databaseName, String tableName) - throws CatalogException { + public boolean existPartitionMethod(String databaseName, String tableName) + throws UndefinedDatabaseException, UndefinedTableException { + Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; + boolean exist = false; try { String sql = "SELECT partition_type, expression, expression_schema FROM " + TB_PARTITION_METHODS + - " WHERE " + COL_TABLES_PK + " = ? "; + " WHERE " + COL_TABLES_PK + "= ?"; if (LOG.isDebugEnabled()) { LOG.debug(sql); @@ -1961,23 +1966,30 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt.setInt(1, tableId); res = pstmt.executeQuery(); - if (res.next()) { - return resultToPartitionMethodProto(databaseName, tableName, res); - } - } catch (Throwable se) { + exist = res.next(); + } catch (SQLException se) { throw new TajoInternalError(se); } finally { CatalogUtil.closeQuietly(pstmt, res); } - return null; + return exist; } - @Override - public boolean existPartitionMethod(String databaseName, String tableName) throws CatalogException { - Connection conn = null; + /** + * Ensure if the table is partitioned table. + * + * @param tbName Table name + * @param tableId Table id + * @throws UndefinedTableException + * @throws UndefinedDatabaseException + * @throws UndefinedPartitionMethodException + */ + private void ensurePartitionTable(String tbName, int tableId) + throws UndefinedTableException, UndefinedDatabaseException, UndefinedPartitionMethodException { + + Connection conn; ResultSet res = null; PreparedStatement pstmt = null; - boolean exist = false; try { String sql = "SELECT partition_type, expression, expression_schema FROM " + TB_PARTITION_METHODS + @@ -1987,26 +1999,31 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo LOG.debug(sql); } - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - conn = getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, tableId); res = pstmt.executeQuery(); - exist = res.next(); + if (!res.next()) { + throw new UndefinedPartitionMethodException(tbName); + } } catch (SQLException se) { throw new TajoInternalError(se); } finally { CatalogUtil.closeQuietly(pstmt, res); } - return exist; } @Override public CatalogProtos.PartitionDescProto getPartition(String databaseName, String tableName, - String partitionName) throws CatalogException { + String partitionName) + throws UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionMethodException, + UndefinedPartitionException { + + final int databaseId = getDatabaseId(databaseName); + final int tableId = getTableId(databaseId, databaseName, tableName); + ensurePartitionTable(tableName, tableId); + Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; @@ -2020,9 +2037,6 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo LOG.debug(sql); } - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - conn = getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, tableId); @@ -2036,7 +2050,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo builder.setPartitionName(partitionName); setPartitionKeys(res.getInt(COL_PARTITIONS_PK), builder); } else { - return null; + throw new UndefinedPartitionException(partitionName); } } catch (SQLException se) { throw new TajoInternalError(se); @@ -2046,8 +2060,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo return builder.build(); } - private void setPartitionKeys(int pid, PartitionDescProto.Builder partitionDesc) throws - CatalogException { + private void setPartitionKeys(int pid, PartitionDescProto.Builder partitionDesc) { Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; @@ -2075,13 +2088,19 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<PartitionDescProto> getPartitions(String databaseName, String tableName) throws CatalogException { + public List<PartitionDescProto> getPartitions(String databaseName, String tableName) + throws UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionMethodException { + Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; PartitionDescProto.Builder builder = null; List<PartitionDescProto> partitions = new ArrayList<PartitionDescProto>(); + final int databaseId = getDatabaseId(databaseName); + final int tableId = getTableId(databaseId, databaseName, tableName); + ensurePartitionTable(tableName, tableId); + try { String sql = "SELECT PATH, PARTITION_NAME, " + COL_PARTITIONS_PK + " FROM " + TB_PARTTIONS +" WHERE " + COL_TABLES_PK + " = ? "; @@ -2090,9 +2109,6 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo LOG.debug(sql); } - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - conn = getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setInt(1, tableId); @@ -2114,7 +2130,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<TablePartitionProto> getAllPartitions() throws CatalogException { + public List<TablePartitionProto> getAllPartitions() { Connection conn = null; Statement stmt = null; ResultSet resultSet = null; @@ -2149,9 +2165,15 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo @Override public void addPartitions(String databaseName, String tableName, List<CatalogProtos.PartitionDescProto> partitions - , boolean ifNotExists) throws CatalogException { - Connection conn = null; + , boolean ifNotExists) throws UndefinedDatabaseException, UndefinedTableException, + UndefinedPartitionMethodException { + + final int databaseId = getDatabaseId(databaseName); + final int tableId = getTableId(databaseId, databaseName, tableName); + ensurePartitionTable(tableName, tableId); + + Connection conn = null; // To delete existing partition keys PreparedStatement pstmt1 = null; // To delete existing partition; @@ -2164,9 +2186,6 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo PartitionDescProto partitionDesc = null; try { - int databaseId = getDatabaseId(databaseName); - int tableId = getTableId(databaseId, databaseName, tableName); - conn = getConnection(); conn.setAutoCommit(false); @@ -2181,11 +2200,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo int batchSize = conf.getInt(TajoConf.ConfVars.PARTITION_DYNAMIC_BULK_INSERT_BATCH_SIZE.varname, 1000); for(currentIndex = 0; currentIndex < partitions.size(); currentIndex++) { PartitionDescProto partition = partitions.get(currentIndex); - partitionDesc = getPartition(databaseName, tableName, partition.getPartitionName()); - // Delete existing partition and partition keys - if (partitionDesc != null) { - if(ifNotExists) { + try { + partitionDesc = getPartition(databaseName, tableName, partition.getPartitionName()); + // Delete existing partition and partition keys + if (ifNotExists) { pstmt1.setInt(1, partitionDesc.getId()); pstmt1.addBatch(); pstmt1.clearParameters(); @@ -2193,9 +2212,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt2.setInt(1, partitionDesc.getId()); pstmt2.addBatch(); pstmt2.clearParameters(); - } else { - throw new DuplicatePartitionException(partition.getPartitionName()); } + } catch (UndefinedPartitionException e) { } // Insert partition @@ -2261,7 +2279,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void createIndex(final IndexDescProto proto) throws CatalogException { + public void createIndex(final IndexDescProto proto) throws UndefinedDatabaseException, UndefinedTableException { Connection conn = null; PreparedStatement pstmt = null; @@ -2324,7 +2342,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public void dropIndex(String databaseName, final String indexName) throws CatalogException { + public void dropIndex(String databaseName, final String indexName) throws UndefinedDatabaseException { Connection conn = null; PreparedStatement pstmt = null; @@ -2358,7 +2376,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt.setInt(1, tableId); res = pstmt.executeQuery(); if (!res.next()) { - throw new TajoInternalError("Cannot get any table name from TID"); + throw new TajoInternalError("Inconsistent data: no table corresponding to TID " + tableId); } return res.getString(1); } finally { @@ -2371,7 +2389,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo @Override public IndexDescProto getIndexByName(String databaseName, final String indexName) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedIndexException { + Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; @@ -2392,13 +2411,20 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt.setString(2, indexName); res = pstmt.executeQuery(); if (!res.next()) { - throw new TajoInternalError("There is no index matched to " + indexName); + throw new UndefinedIndexException(indexName); } IndexDescProto.Builder builder = IndexDescProto.newBuilder(); resultToIndexDescProtoBuilder(builder, res); String tableName = getTableName(conn, res.getInt(COL_TABLES_PK)); builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName)); - builder.setTargetRelationSchema(getTable(databaseName, tableName).getSchema()); + + try { + builder.setTargetRelationSchema(getTable(databaseName, tableName).getSchema()); + } catch (UndefinedTableException e) { + throw new TajoInternalError( + "Inconsistent table and index information: table " + tableName + " does not exists."); + } + proto = builder.build(); } catch (SQLException se) { throw new TajoInternalError(se); @@ -2411,7 +2437,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo @Override public IndexDescProto getIndexByColumns(String databaseName, String tableName, String[] columnNames) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedTableException, UndefinedIndexException { + Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; @@ -2441,7 +2468,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo pstmt.setString(3, unifiedName); res = pstmt.executeQuery(); if (!res.next()) { - throw new TajoInternalError("ERROR: there is no index matched to " + unifiedName); + throw new UndefinedIndexException(unifiedName); } IndexDescProto.Builder builder = IndexDescProto.newBuilder(); @@ -2459,7 +2486,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public boolean existIndexByName(String databaseName, final String indexName) throws CatalogException { + public boolean existIndexByName(String databaseName, final String indexName) throws UndefinedDatabaseException { Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; @@ -2493,7 +2520,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo @Override public boolean existIndexByColumns(String databaseName, String tableName, String[] columnNames) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedTableException { + Connection conn = null; ResultSet res = null; PreparedStatement pstmt = null; @@ -2535,7 +2563,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo @Override public List<String> getAllIndexNamesByTable(final String databaseName, final String tableName) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedTableException { + ResultSet res = null; PreparedStatement pstmt = null; final List<String> indexNames = new ArrayList<String>(); @@ -2569,10 +2598,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public boolean existIndexesByTable(String databaseName, String tableName) throws CatalogException { + public boolean existIndexesByTable(String databaseName, String tableName) + throws UndefinedDatabaseException, UndefinedTableException { + ResultSet res = null; PreparedStatement pstmt = null; - final List<String> indexNames = new ArrayList<String>(); try { final int databaseId = getDatabaseId(databaseName); @@ -2599,12 +2629,18 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public List<IndexDescProto> getAllIndexes() throws CatalogException { + public List<IndexDescProto> getAllIndexes() throws UndefinedDatabaseException { List<IndexDescProto> indexDescProtos = TUtil.newList(); for (String databaseName : getAllDatabaseNames()) { for (String tableName : getAllTableNames(databaseName)) { - for (String indexName: getAllIndexNamesByTable(databaseName, tableName)) { - indexDescProtos.add(getIndexByName(databaseName, indexName)); + try { + for (String indexName: getAllIndexNamesByTable(databaseName, tableName)) { + indexDescProtos.add(getIndexByName(databaseName, indexName)); + } + } catch (UndefinedTableException e) { + LOG.warn(e); + } catch (UndefinedIndexException e) { + throw new TajoInternalError(e); } } } @@ -2634,19 +2670,6 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo builder.setIsClustered(res.getBoolean("is_clustered")); } - /** - * INDEXS table doesn't store type_length, so we need another resultToColumnProto method - */ - private ColumnProto indexResultToColumnProto(final ResultSet res) throws SQLException { - ColumnProto.Builder builder = ColumnProto.newBuilder(); - builder.setName(res.getString("column_name").trim()); - - Type type = getDataType(res.getString("data_type").trim()); - builder.setDataType(CatalogUtil.newSimpleDataType(type)); - - return builder.build(); - } - private ColumnProto resultToColumnProto(final ResultSet res) throws SQLException { ColumnProto.Builder builder = ColumnProto.newBuilder(); builder.setName(res.getString("column_name").trim()); @@ -2692,12 +2715,18 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo private CatalogProtos.PartitionMethodProto resultToPartitionMethodProto(final String databaseName, final String tableName, final ResultSet res) - throws SQLException, InvalidProtocolBufferException { - CatalogProtos.PartitionMethodProto.Builder partBuilder = CatalogProtos.PartitionMethodProto.newBuilder(); - partBuilder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName)); - partBuilder.setPartitionType(CatalogProtos.PartitionType.valueOf(res.getString("partition_type"))); - partBuilder.setExpression(res.getString("expression")); - partBuilder.setExpressionSchema(SchemaProto.parseFrom(res.getBytes("expression_schema"))); + throws SQLException { + + CatalogProtos.PartitionMethodProto.Builder partBuilder; + try { + partBuilder = CatalogProtos.PartitionMethodProto.newBuilder(); + partBuilder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName)); + partBuilder.setPartitionType(CatalogProtos.PartitionType.valueOf(res.getString("partition_type"))); + partBuilder.setExpression(res.getString("expression")); + partBuilder.setExpressionSchema(SchemaProto.parseFrom(res.getBytes("expression_schema"))); + } catch (InvalidProtocolBufferException e) { + throw new TajoInternalError(e); + } return partBuilder.build(); } @@ -2708,27 +2737,27 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo } @Override - public final void addFunction(final FunctionDesc func) throws CatalogException { + public final void addFunction(final FunctionDesc func) { // TODO - not implemented yet } @Override - public final void deleteFunction(final FunctionDesc func) throws CatalogException { + public final void deleteFunction(final FunctionDesc func) { // TODO - not implemented yet } @Override - public final void existFunction(final FunctionDesc func) throws CatalogException { + public final void existFunction(final FunctionDesc func) { // TODO - not implemented yet } @Override - public final List<String> getAllFunctionNames() throws CatalogException { + public final List<String> getAllFunctionNames() { // TODO - not implemented yet return null; } - private boolean existColumn(final int tableId, final String columnName) throws CatalogException { + private boolean existColumn(final int tableId, final String columnName) { Connection conn ; PreparedStatement pstmt = null; ResultSet res = null;
http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java index ef9ddd0..64a0e86 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,126 +18,134 @@ package org.apache.tajo.catalog.store; +import com.google.protobuf.InvalidProtocolBufferException; import org.apache.tajo.catalog.FunctionDesc; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.*; +import org.apache.tajo.exception.*; import java.io.Closeable; - -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto; - +import java.sql.SQLException; import java.util.Collection; import java.util.List; public interface CatalogStore extends Closeable { /*************************** Tablespace ******************************/ - void createTablespace(String spaceName, String spaceUri) throws CatalogException; + void createTablespace(String spaceName, String spaceUri) throws DuplicateTablespaceException; + + boolean existTablespace(String spaceName); - boolean existTablespace(String spaceName) throws CatalogException; + void dropTablespace(String spaceName) throws UndefinedTablespaceException, UndefinedTableException; - void dropTablespace(String spaceName) throws CatalogException; + Collection<String> getAllTablespaceNames(); - Collection<String> getAllTablespaceNames() throws CatalogException; - - List<TablespaceProto> getTablespaces() throws CatalogException; + List<TablespaceProto> getTablespaces(); - TablespaceProto getTablespace(String spaceName) throws CatalogException; + TablespaceProto getTablespace(String spaceName) throws UndefinedTablespaceException; - void alterTablespace(AlterTablespaceProto alterProto) throws CatalogException; + void alterTablespace(AlterTablespaceProto alterProto) throws UndefinedTablespaceException; /*************************** Database ******************************/ - void createDatabase(String databaseName, String tablespaceName) throws CatalogException; + void createDatabase(String databaseName, String tablespaceName) throws UndefinedTablespaceException, + DuplicateDatabaseException; - boolean existDatabase(String databaseName) throws CatalogException; + boolean existDatabase(String databaseName); - void dropDatabase(String databaseName) throws CatalogException; + void dropDatabase(String databaseName) throws UndefinedDatabaseException, UndefinedTableException; - Collection<String> getAllDatabaseNames() throws CatalogException; - - List<DatabaseProto> getAllDatabases() throws CatalogException; + Collection<String> getAllDatabaseNames(); + + List<DatabaseProto> getAllDatabases(); /*************************** TABLE ******************************/ - void createTable(CatalogProtos.TableDescProto desc) throws CatalogException; - - boolean existTable(String databaseName, String tableName) throws CatalogException; - - void dropTable(String databaseName, String tableName) throws CatalogException; - - CatalogProtos.TableDescProto getTable(String databaseName, String tableName) throws CatalogException; - - List<String> getAllTableNames(String databaseName) throws CatalogException; - - void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException; - - List<TableDescriptorProto> getAllTables() throws CatalogException; - - List<TableOptionProto> getAllTableProperties() throws CatalogException; - - List<TableStatsProto> getAllTableStats() throws CatalogException; - - List<ColumnProto> getAllColumns() throws CatalogException; - - void updateTableStats(CatalogProtos.UpdateTableStatsProto statsProto) throws CatalogException; + void createTable(CatalogProtos.TableDescProto desc) throws UndefinedDatabaseException, DuplicateTableException; - /************************ PARTITION METHOD **************************/ - void addPartitionMethod(PartitionMethodProto partitionMethodProto) throws CatalogException; + boolean existTable(String databaseName, String tableName) throws UndefinedDatabaseException; + + void dropTable(String databaseName, String tableName) throws UndefinedDatabaseException, UndefinedTableException; + + CatalogProtos.TableDescProto getTable(String databaseName, String tableName) throws UndefinedDatabaseException, + UndefinedTableException; + + List<String> getAllTableNames(String databaseName) throws UndefinedDatabaseException; + + void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws UndefinedDatabaseException, + DuplicateTableException, DuplicateColumnException, DuplicatePartitionException, UndefinedPartitionException, + UndefinedTableException, UndefinedColumnException, UndefinedPartitionMethodException; + + List<TableDescriptorProto> getAllTables(); - PartitionMethodProto getPartitionMethod(String databaseName, String tableName) - throws CatalogException; + List<TableOptionProto> getAllTableProperties(); - boolean existPartitionMethod(String databaseName, String tableName) throws CatalogException; + List<TableStatsProto> getAllTableStats(); - void dropPartitionMethod(String dbName, String tableName) throws CatalogException; + List<ColumnProto> getAllColumns(); + void updateTableStats(CatalogProtos.UpdateTableStatsProto statsProto) throws UndefinedDatabaseException, UndefinedTableException; + + /************************ PARTITION METHOD **************************/ + PartitionMethodProto getPartitionMethod(String databaseName, String tableName) throws UndefinedDatabaseException, + UndefinedTableException, UndefinedPartitionMethodException; + + boolean existPartitionMethod(String databaseName, String tableName) throws UndefinedDatabaseException, + UndefinedTableException; /************************** PARTITIONS *****************************/ /** * Get all partitions of a table * @param tableName the table name * @return - * @throws CatalogException + * @throws TajoException */ - List<CatalogProtos.PartitionDescProto> getPartitions(String databaseName, String tableName) throws CatalogException; + List<CatalogProtos.PartitionDescProto> getPartitions(String databaseName, String tableName) throws + UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionMethodException; CatalogProtos.PartitionDescProto getPartition(String databaseName, String tableName, - String partitionName) throws CatalogException; + String partitionName) + throws UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionException, + UndefinedPartitionMethodException; - List<TablePartitionProto> getAllPartitions() throws CatalogException; + List<TablePartitionProto> getAllPartitions(); void addPartitions(String databaseName, String tableName, List<CatalogProtos.PartitionDescProto> partitions - , boolean ifNotExists) throws CatalogException; + , boolean ifNotExists) throws UndefinedDatabaseException, + UndefinedTableException, DuplicatePartitionException, UndefinedPartitionException, + UndefinedPartitionMethodException; /**************************** INDEX *******************************/ - void createIndex(IndexDescProto proto) throws CatalogException; - - void dropIndex(String databaseName, String indexName) throws CatalogException; - - IndexDescProto getIndexByName(String databaseName, String indexName) throws CatalogException; + void createIndex(IndexDescProto proto) throws UndefinedDatabaseException, UndefinedTableException, + DuplicateIndexException; + + void dropIndex(String databaseName, String indexName) throws UndefinedDatabaseException, + UndefinedTableException, UndefinedIndexException; + + IndexDescProto getIndexByName(String databaseName, String indexName) throws UndefinedDatabaseException, + UndefinedIndexException; - IndexDescProto getIndexByColumns(String databaseName, String tableName, String[] columnNames) - throws CatalogException; - - boolean existIndexByName(String databaseName, String indexName) throws CatalogException; + IndexDescProto getIndexByColumns(String databaseName, String tableName, String[] columnNames) throws + UndefinedDatabaseException, UndefinedTableException, UndefinedIndexException + ; - boolean existIndexByColumns(String databaseName, String tableName, String[] columnNames) - throws CatalogException; + boolean existIndexByName(String databaseName, String indexName) throws UndefinedDatabaseException; - List<String> getAllIndexNamesByTable(String databaseName, String tableName) throws CatalogException; + boolean existIndexByColumns(String databaseName, String tableName, String[] columnNames) throws + UndefinedDatabaseException, UndefinedTableException; - boolean existIndexesByTable(String databaseName, String tableName) throws CatalogException; + List<String> getAllIndexNamesByTable(String databaseName, String tableName) throws UndefinedDatabaseException, UndefinedTableException; - List<IndexDescProto> getAllIndexes() throws CatalogException; + boolean existIndexesByTable(String databaseName, String tableName) + throws UndefinedDatabaseException, UndefinedTableException; + + List<IndexDescProto> getAllIndexes() throws UndefinedDatabaseException; /************************** FUNCTION *****************************/ - - void addFunction(FunctionDesc func) throws CatalogException; - - void deleteFunction(FunctionDesc func) throws CatalogException; - - void existFunction(FunctionDesc func) throws CatalogException; - - List<String> getAllFunctionNames() throws CatalogException; + + void addFunction(FunctionDesc func); + + void deleteFunction(FunctionDesc func); + + void existFunction(FunctionDesc func); + + List<String> getAllFunctionNames(); } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java index d9ec3d3..19a4f13 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java @@ -23,11 +23,12 @@ package org.apache.tajo.catalog.store; import org.apache.hadoop.conf.Configuration; import org.apache.tajo.catalog.CatalogUtil; -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.exception.InternalException; import org.apache.tajo.exception.TajoInternalError; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; public class DerbyStore extends AbstractDBStore { @@ -37,7 +38,7 @@ public class DerbyStore extends AbstractDBStore { return CATALOG_DRIVER; } - public DerbyStore(final Configuration conf) throws InternalException { + public DerbyStore(final Configuration conf) { super(conf); } @@ -46,7 +47,7 @@ public class DerbyStore extends AbstractDBStore { } @Override - public String readSchemaFile(String filename) throws CatalogException { + public String readSchemaFile(String filename) { return super.readSchemaFile("derby/" + filename); } @@ -72,7 +73,7 @@ public class DerbyStore extends AbstractDBStore { } @Override - protected void createDatabaseDependants() throws CatalogException { + protected void createDatabaseDependants() { String schemaName = catalogSchemaManager.getCatalogStore().getSchema().getSchemaName(); Statement stmt = null; http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java index cb661ac..8275e62 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MariaDBStore.java @@ -22,8 +22,6 @@ package org.apache.tajo.catalog.store; import org.apache.hadoop.conf.Configuration; -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.exception.InternalException; import java.sql.Connection; import java.sql.DriverManager; @@ -32,7 +30,7 @@ import java.sql.SQLException; public class MariaDBStore extends AbstractDBStore { private static final String CATALOG_DRIVER = "org.mariadb.jdbc.Driver"; - public MariaDBStore(Configuration conf) throws InternalException { + public MariaDBStore(Configuration conf) { super(conf); } @@ -52,6 +50,6 @@ public class MariaDBStore extends AbstractDBStore { } @Override - protected void createDatabaseDependants() throws CatalogException { + protected void createDatabaseDependants() { } } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java index c822482..7227366 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java @@ -26,9 +26,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.tajo.TajoConstants; import org.apache.tajo.catalog.*; -import org.apache.tajo.catalog.exception.*; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.*; +import org.apache.tajo.exception.*; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto; import org.apache.tajo.util.KeyValueSet; import org.apache.tajo.util.TUtil; @@ -37,7 +37,6 @@ import java.io.IOException; import java.util.*; import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceType; -import static org.apache.tajo.catalog.proto.CatalogProtos.*; /** * CatalogServer guarantees that all operations are thread-safe. @@ -62,7 +61,7 @@ public class MemStore implements CatalogStore { } @Override - public void createTablespace(String spaceName, String spaceUri) throws CatalogException { + public void createTablespace(String spaceName, String spaceUri) throws DuplicateTablespaceException { if (tablespaces.containsKey(spaceName)) { throw new DuplicateTablespaceException(spaceName); } @@ -71,12 +70,12 @@ public class MemStore implements CatalogStore { } @Override - public boolean existTablespace(String spaceName) throws CatalogException { + public boolean existTablespace(String spaceName) { return tablespaces.containsKey(spaceName); } @Override - public void dropTablespace(String spaceName) throws CatalogException { + public void dropTablespace(String spaceName) throws UndefinedTablespaceException { if (!tablespaces.containsKey(spaceName)) { throw new UndefinedTablespaceException(spaceName); } @@ -84,12 +83,12 @@ public class MemStore implements CatalogStore { } @Override - public Collection<String> getAllTablespaceNames() throws CatalogException { + public Collection<String> getAllTablespaceNames() { return tablespaces.keySet(); } @Override - public List<TablespaceProto> getTablespaces() throws CatalogException { + public List<TablespaceProto> getTablespaces() { List<TablespaceProto> tablespaceList = TUtil.newList(); int tablespaceId = 0; @@ -105,7 +104,7 @@ public class MemStore implements CatalogStore { } @Override - public TablespaceProto getTablespace(String spaceName) throws CatalogException { + public TablespaceProto getTablespace(String spaceName) throws UndefinedTablespaceException { if (!tablespaces.containsKey(spaceName)) { throw new UndefinedTablespaceException(spaceName); } @@ -117,7 +116,7 @@ public class MemStore implements CatalogStore { } @Override - public void alterTablespace(CatalogProtos.AlterTablespaceProto alterProto) throws CatalogException { + public void alterTablespace(CatalogProtos.AlterTablespaceProto alterProto) throws UndefinedTablespaceException { if (!tablespaces.containsKey(alterProto.getSpaceName())) { throw new UndefinedTablespaceException(alterProto.getSpaceName()); } @@ -133,7 +132,7 @@ public class MemStore implements CatalogStore { } @Override - public void createDatabase(String databaseName, String tablespaceName) throws CatalogException { + public void createDatabase(String databaseName, String tablespaceName) throws DuplicateDatabaseException { if (databases.containsKey(databaseName)) { throw new DuplicateDatabaseException(databaseName); } @@ -144,12 +143,12 @@ public class MemStore implements CatalogStore { } @Override - public boolean existDatabase(String databaseName) throws CatalogException { + public boolean existDatabase(String databaseName) { return databases.containsKey(databaseName); } @Override - public void dropDatabase(String databaseName) throws CatalogException { + public void dropDatabase(String databaseName) throws UndefinedDatabaseException { if (!databases.containsKey(databaseName)) { throw new UndefinedDatabaseException(databaseName); } @@ -159,12 +158,12 @@ public class MemStore implements CatalogStore { } @Override - public Collection<String> getAllDatabaseNames() throws CatalogException { + public Collection<String> getAllDatabaseNames() { return databases.keySet(); } @Override - public List<DatabaseProto> getAllDatabases() throws CatalogException { + public List<DatabaseProto> getAllDatabases() { List<DatabaseProto> databaseList = new ArrayList<DatabaseProto>(); int dbId = 0; @@ -194,7 +193,9 @@ public class MemStore implements CatalogStore { } @Override - public void createTable(CatalogProtos.TableDescProto request) throws CatalogException { + public void createTable(CatalogProtos.TableDescProto request) + throws UndefinedDatabaseException, DuplicateTableException { + String [] splitted = CatalogUtil.splitTableName(request.getTableName()); if (splitted.length == 1) { throw new IllegalArgumentException("createTable() requires a qualified table name, but it is \"" @@ -213,7 +214,7 @@ public class MemStore implements CatalogStore { } @Override - public void updateTableStats(CatalogProtos.UpdateTableStatsProto request) throws CatalogException { + public void updateTableStats(CatalogProtos.UpdateTableStatsProto request) throws UndefinedDatabaseException { String [] splitted = CatalogUtil.splitTableName(request.getTableName()); if (splitted.length == 1) { throw new IllegalArgumentException("createTable() requires a qualified table name, but it is \"" @@ -230,14 +231,14 @@ public class MemStore implements CatalogStore { } @Override - public boolean existTable(String dbName, String tbName) throws CatalogException { + public boolean existTable(String dbName, String tbName) throws UndefinedDatabaseException { Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, dbName); return database.containsKey(tbName); } @Override - public void dropTable(String dbName, String tbName) throws CatalogException { + public void dropTable(String dbName, String tbName) throws UndefinedDatabaseException, UndefinedTableException { Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, dbName); if (database.containsKey(tbName)) { @@ -251,7 +252,8 @@ public class MemStore implements CatalogStore { * @see CatalogStore#alterTable(AlterTableDesc) */ @Override - public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException { + public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) + throws UndefinedDatabaseException, DuplicateTableException, DuplicatePartitionException, UndefinedPartitionException { String[] split = CatalogUtil.splitTableName(alterTableDescProto.getTableName()); if (split.length == 1) { @@ -383,7 +385,8 @@ public class MemStore implements CatalogStore { */ @Override public CatalogProtos.TableDescProto getTable(String databaseName, String tableName) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedTableException { + Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, databaseName); if (database.containsKey(tableName)) { @@ -403,13 +406,13 @@ public class MemStore implements CatalogStore { * @see CatalogStore#getAllTableNames() */ @Override - public List<String> getAllTableNames(String databaseName) throws CatalogException { + public List<String> getAllTableNames(String databaseName) throws UndefinedDatabaseException { Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, databaseName); return new ArrayList<String>(database.keySet()); } @Override - public List<TableDescriptorProto> getAllTables() throws CatalogException { + public List<TableDescriptorProto> getAllTables() { List<TableDescriptorProto> tableList = new ArrayList<CatalogProtos.TableDescriptorProto>(); int dbId = 0, tableId = 0; @@ -439,7 +442,7 @@ public class MemStore implements CatalogStore { } @Override - public List<TableOptionProto> getAllTableProperties() throws CatalogException { + public List<TableOptionProto> getAllTableProperties() { List<TableOptionProto> optionList = new ArrayList<CatalogProtos.TableOptionProto>(); int tid = 0; @@ -468,7 +471,7 @@ public class MemStore implements CatalogStore { } @Override - public List<TableStatsProto> getAllTableStats() throws CatalogException { + public List<TableStatsProto> getAllTableStats() { List<TableStatsProto> statList = new ArrayList<CatalogProtos.TableStatsProto>(); int tid = 0; @@ -494,7 +497,7 @@ public class MemStore implements CatalogStore { } @Override - public List<ColumnProto> getAllColumns() throws CatalogException { + public List<ColumnProto> getAllColumns() { List<ColumnProto> columnList = new ArrayList<CatalogProtos.ColumnProto>(); int tid = 0; @@ -521,13 +524,9 @@ public class MemStore implements CatalogStore { } @Override - public void addPartitionMethod(CatalogProtos.PartitionMethodProto partitionMethodProto) throws CatalogException { - throw new RuntimeException("not supported!"); - } - - @Override public CatalogProtos.PartitionMethodProto getPartitionMethod(String databaseName, String tableName) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedTableException { + Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, databaseName); if (database.containsKey(tableName)) { @@ -540,7 +539,8 @@ public class MemStore implements CatalogStore { @Override public boolean existPartitionMethod(String databaseName, String tableName) - throws CatalogException { + throws UndefinedDatabaseException, UndefinedTableException { + Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, databaseName); if (database.containsKey(tableName)) { @@ -552,12 +552,7 @@ public class MemStore implements CatalogStore { } @Override - public void dropPartitionMethod(String databaseName, String tableName) throws CatalogException { - throw new RuntimeException("not supported!"); - } - - @Override - public List<CatalogProtos.PartitionDescProto> getPartitions(String databaseName, String tableName) throws CatalogException { + public List<CatalogProtos.PartitionDescProto> getPartitions(String databaseName, String tableName) { List<CatalogProtos.PartitionDescProto> protos = new ArrayList<CatalogProtos.PartitionDescProto>(); if (partitions.containsKey(tableName)) { @@ -570,7 +565,7 @@ public class MemStore implements CatalogStore { @Override public CatalogProtos.PartitionDescProto getPartition(String databaseName, String tableName, - String partitionName) throws CatalogException { + String partitionName) throws UndefinedPartitionException { if (partitions.containsKey(tableName) && partitions.get(tableName).containsKey(partitionName)) { return partitions.get(tableName).get(partitionName); } else { @@ -578,7 +573,7 @@ public class MemStore implements CatalogStore { } } - public List<TablePartitionProto> getAllPartitions() throws CatalogException { + public List<TablePartitionProto> getAllPartitions() { List<TablePartitionProto> protos = new ArrayList<TablePartitionProto>(); Set<String> tables = partitions.keySet(); for (String table : tables) { @@ -604,14 +599,19 @@ public class MemStore implements CatalogStore { } @Override - public void addPartitions(String databaseName, String tableName, List<CatalogProtos.PartitionDescProto> partitions - , boolean ifNotExists) throws CatalogException { + public void addPartitions(String databaseName, String tableName, List<CatalogProtos.PartitionDescProto> partitions, + boolean ifNotExists) throws DuplicatePartitionException { + for(CatalogProtos.PartitionDescProto partition: partitions) { String partitionName = partition.getPartitionName(); if (this.partitions.containsKey(tableName) && this.partitions.get(tableName).containsKey(partitionName)) { if (ifNotExists) { - dropPartition(databaseName, tableName, partitionName); + try { + dropPartition(databaseName, tableName, partitionName); + } catch (UndefinedPartitionException e) { + // ignore + } } else { throw new DuplicatePartitionException(partitionName); } @@ -624,13 +624,14 @@ public class MemStore implements CatalogStore { * @see CatalogStore#createIndex(nta.catalog.proto.CatalogProtos.IndexDescProto) */ @Override - public void createIndex(IndexDescProto proto) throws CatalogException { + public void createIndex(IndexDescProto proto) throws UndefinedDatabaseException, UndefinedTableException, + DuplicateIndexException { + final String databaseName = proto.getTableIdentifier().getDatabaseName(); final String tableName = CatalogUtil.extractSimpleName(proto.getTableIdentifier().getTableName()); - + getTable(databaseName, tableName); Map<String, IndexDescProto> index = checkAndGetDatabaseNS(indexes, databaseName); Map<String, IndexDescProto> indexByColumn = checkAndGetDatabaseNS(indexesByColumn, databaseName); - TableDescProto tableDescProto = getTable(databaseName, tableName); if (index.containsKey(proto.getIndexName())) { throw new DuplicateIndexException(proto.getIndexName()); @@ -649,7 +650,9 @@ public class MemStore implements CatalogStore { * @see CatalogStore#dropIndex(java.lang.String) */ @Override - public void dropIndex(String databaseName, String indexName) throws CatalogException { + public void dropIndex(String databaseName, String indexName) throws UndefinedDatabaseException, + UndefinedIndexException, UndefinedTableException { + Map<String, IndexDescProto> index = checkAndGetDatabaseNS(indexes, databaseName); Map<String, IndexDescProto> indexByColumn = checkAndGetDatabaseNS(indexesByColumn, databaseName); if (!index.containsKey(indexName)) { @@ -657,7 +660,7 @@ public class MemStore implements CatalogStore { } IndexDescProto proto = index.get(indexName); final String tableName = CatalogUtil.extractSimpleName(proto.getTableIdentifier().getTableName()); - TableDescProto tableDescProto = getTable(databaseName, tableName); + getTable(databaseName, tableName); index.remove(indexName); String originalTableName = proto.getTableIdentifier().getTableName(); String simpleTableName = CatalogUtil.extractSimpleName(originalTableName); @@ -670,7 +673,9 @@ public class MemStore implements CatalogStore { * @see CatalogStore#getIndexByName(java.lang.String) */ @Override - public IndexDescProto getIndexByName(String databaseName, String indexName) throws CatalogException { + public IndexDescProto getIndexByName(String databaseName, String indexName) + throws UndefinedDatabaseException, UndefinedIndexException { + Map<String, IndexDescProto> index = checkAndGetDatabaseNS(indexes, databaseName); if (!index.containsKey(indexName)) { throw new UndefinedIndexException(indexName); @@ -680,7 +685,9 @@ public class MemStore implements CatalogStore { } @Override - public IndexDescProto getIndexByColumns(String databaseName, String tableName, String[] columnNames) throws CatalogException { + public IndexDescProto getIndexByColumns(String databaseName, String tableName, String[] columnNames) + throws UndefinedDatabaseException, UndefinedTableException, UndefinedIndexException { + Map<String, IndexDescProto> indexByColumn = checkAndGetDatabaseNS(indexesByColumn, databaseName); String simpleTableName = CatalogUtil.extractSimpleName(tableName); TableDescProto tableDescProto = getTable(databaseName, simpleTableName); @@ -694,13 +701,15 @@ public class MemStore implements CatalogStore { } @Override - public boolean existIndexByName(String databaseName, String indexName) throws CatalogException { + public boolean existIndexByName(String databaseName, String indexName) throws UndefinedDatabaseException { Map<String, IndexDescProto> index = checkAndGetDatabaseNS(indexes, databaseName); return index.containsKey(indexName); } @Override - public boolean existIndexByColumns(String databaseName, String tableName, String[] columnNames) throws CatalogException { + public boolean existIndexByColumns(String databaseName, String tableName, String[] columnNames) + throws UndefinedDatabaseException, UndefinedTableException { + Map<String, IndexDescProto> indexByColumn = checkAndGetDatabaseNS(indexesByColumn, databaseName); TableDescProto tableDescProto = getTable(databaseName, tableName); return indexByColumn.containsKey( @@ -709,7 +718,7 @@ public class MemStore implements CatalogStore { } @Override - public List<String> getAllIndexNamesByTable(String databaseName, String tableName) throws CatalogException { + public List<String> getAllIndexNamesByTable(String databaseName, String tableName) throws UndefinedDatabaseException { List<String> indexNames = new ArrayList<String>(); Map<String, IndexDescProto> indexByColumn = checkAndGetDatabaseNS(indexesByColumn, databaseName); String simpleTableName = CatalogUtil.extractSimpleName(tableName); @@ -723,7 +732,7 @@ public class MemStore implements CatalogStore { } @Override - public boolean existIndexesByTable(String databaseName, String tableName) throws CatalogException { + public boolean existIndexesByTable(String databaseName, String tableName) throws UndefinedDatabaseException { Map<String, IndexDescProto> indexByColumn = checkAndGetDatabaseNS(indexesByColumn, databaseName); String simpleTableName = CatalogUtil.extractSimpleName(tableName); for (IndexDescProto proto : indexByColumn.values()) { @@ -735,7 +744,7 @@ public class MemStore implements CatalogStore { } @Override - public List<IndexDescProto> getAllIndexes() throws CatalogException { + public List<IndexDescProto> getAllIndexes() { List<IndexDescProto> indexDescProtos = TUtil.newList(); for (Map<String,IndexDescProto> indexMap : indexes.values()) { indexDescProtos.addAll(indexMap.values()); @@ -744,22 +753,22 @@ public class MemStore implements CatalogStore { } @Override - public void addFunction(FunctionDesc func) throws CatalogException { + public void addFunction(FunctionDesc func) { // to be implemented } @Override - public void deleteFunction(FunctionDesc func) throws CatalogException { + public void deleteFunction(FunctionDesc func) { // to be implemented } @Override - public void existFunction(FunctionDesc func) throws CatalogException { + public void existFunction(FunctionDesc func) { // to be implemented } @Override - public List<String> getAllFunctionNames() throws CatalogException { + public List<String> getAllFunctionNames() { // to be implemented return null; } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java index d6e902a..bd1ce3c 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java @@ -22,8 +22,6 @@ package org.apache.tajo.catalog.store; import org.apache.hadoop.conf.Configuration; -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.exception.InternalException; import java.sql.Connection; import java.sql.DriverManager; @@ -32,7 +30,7 @@ import java.sql.SQLException; public class MySQLStore extends AbstractDBStore { private static final String CATALOG_DRIVER = "com.mysql.jdbc.Driver"; - public MySQLStore(Configuration conf) throws InternalException { + public MySQLStore(Configuration conf) { super(conf); } @@ -52,6 +50,6 @@ public class MySQLStore extends AbstractDBStore { } @Override - protected void createDatabaseDependants() throws CatalogException { + protected void createDatabaseDependants() { } }
