TAJO-1670: Refactor client errors and exceptions. Closes #621
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/5d62c409 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/5d62c409 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/5d62c409 Branch: refs/heads/master Commit: 5d62c409af47074ca2112a71e201a3127cd68878 Parents: 4bfd693 Author: Hyunsik Choi <[email protected]> Authored: Mon Jul 20 20:40:49 2015 +0900 Committer: Hyunsik Choi <[email protected]> Committed: Mon Jul 20 20:41:33 2015 +0900 ---------------------------------------------------------------------- CHANGES | 2 + .../tajo/catalog/AbstractCatalogClient.java | 565 ++++++----- .../src/main/proto/CatalogProtocol.proto | 157 ++- .../org/apache/tajo/catalog/CatalogService.java | 10 +- .../org/apache/tajo/catalog/CatalogUtil.java | 17 +- .../java/org/apache/tajo/catalog/Schema.java | 4 +- .../AlreadyExistsDatabaseException.java | 30 - .../exception/AlreadyExistsFieldException.java | 30 - .../AlreadyExistsFunctionException.java | 27 - .../exception/AlreadyExistsIndexException.java | 39 - .../AlreadyExistsPartitionException.java | 37 - .../exception/AlreadyExistsTableException.java | 35 - .../AlreadyExistsTablespaceException.java | 30 - .../exception/AmbiguousFunctionException.java | 30 + .../catalog/exception/CatalogException.java | 33 +- .../catalog/exception/CatalogExceptionUtil.java | 45 + .../ColumnNameAlreadyExistException.java | 31 - .../exception/DuplicateColumnException.java | 29 + .../exception/DuplicateDatabaseException.java | 28 + .../exception/DuplicateFunctionException.java | 32 + .../exception/DuplicateIndexException.java | 29 + .../exception/DuplicatePartitionException.java | 30 + .../exception/DuplicateTableException.java | 30 + .../exception/DuplicateTablespaceException.java | 28 + .../catalog/exception/InvalidNameException.java | 29 + .../exception/MetadataConnectionException.java | 32 + .../exception/NoPartitionedTableException.java | 2 - .../exception/NoSuchColumnException.java | 34 - .../exception/NoSuchDatabaseException.java | 30 - .../exception/NoSuchFunctionException.java | 40 - .../catalog/exception/NoSuchIndexException.java | 34 - .../catalog/exception/NoSuchTableException.java | 34 - .../exception/NoSuchTablespaceException.java | 29 - .../exception/UndefinedColumnException.java | 30 + .../exception/UndefinedDatabaseException.java | 30 + .../exception/UndefinedFunctionException.java | 44 + .../exception/UndefinedIndexException.java | 33 + .../exception/UndefinedPartitionException.java | 30 + .../exception/UndefinedTableException.java | 35 + .../exception/UndefinedTablespaceException.java | 29 + .../src/main/proto/CatalogProtos.proto | 59 +- .../org/apache/tajo/catalog/TestSchema.java | 4 +- .../tajo/catalog/store/HiveCatalogStore.java | 67 +- .../tajo/catalog/store/HiveCatalogUtil.java | 40 +- .../org/apache/tajo/catalog/CatalogServer.java | 953 +++++++++++-------- .../InfoSchemaMetadataDictionary.java | 10 +- .../tajo/catalog/store/AbstractDBStore.java | 168 ++-- .../apache/tajo/catalog/store/CatalogStore.java | 6 +- .../apache/tajo/catalog/store/DerbyStore.java | 3 +- .../org/apache/tajo/catalog/store/MemStore.java | 42 +- .../catalog/store/XMLCatalogSchemaManager.java | 39 +- .../org/apache/tajo/catalog/TestCatalog.java | 11 +- .../org/apache/tajo/cli/tools/TajoAdmin.java | 20 +- .../java/org/apache/tajo/cli/tsql/TajoCli.java | 51 +- .../tsql/commands/ConnectDatabaseCommand.java | 4 +- .../tajo/cli/tsql/commands/SetCommand.java | 9 +- .../apache/tajo/client/CatalogAdminClient.java | 43 +- .../tajo/client/CatalogAdminClientImpl.java | 198 ++-- .../org/apache/tajo/client/QueryClient.java | 72 +- .../org/apache/tajo/client/QueryClientImpl.java | 518 +++++----- .../org/apache/tajo/client/QueryStatus.java | 2 +- .../apache/tajo/client/SessionConnection.java | 202 ++-- .../java/org/apache/tajo/client/TajoClient.java | 2 +- .../org/apache/tajo/client/TajoClientImpl.java | 73 +- .../org/apache/tajo/client/TajoClientUtil.java | 9 +- .../java/org/apache/tajo/jdbc/SQLStates.java | 33 - tajo-client/src/main/proto/ClientProtos.proto | 70 +- .../main/proto/QueryMasterClientProtocol.proto | 6 +- .../main/proto/TajoMasterClientProtocol.proto | 34 +- tajo-common/pom.xml | 2 + .../exception/InvalidAddressException.java | 25 - .../exception/NotImplementedException.java | 49 - .../java/org/apache/tajo/common/type/IPv4.java | 2 +- .../apache/tajo/exception/ErrorMessages.java | 134 +++ .../org/apache/tajo/exception/ErrorUtil.java | 44 + .../apache/tajo/exception/ExceptionUtil.java | 64 ++ .../tajo/exception/InvalidAddressException.java | 25 + .../exception/InvalidDataTypeException.java | 30 + .../apache/tajo/exception/ReturnStateUtil.java | 200 ++++ .../apache/tajo/exception/SQLExceptionUtil.java | 99 ++ .../org/apache/tajo/exception/TajoError.java | 53 ++ .../apache/tajo/exception/TajoException.java | 44 + .../tajo/exception/TajoExceptionInterface.java | 33 + .../tajo/exception/TajoInternalError.java | 35 + .../tajo/exception/TajoRuntimeException.java | 51 + .../exception/UndefinedOperatorException.java | 28 + .../tajo/exception/UnimplementedException.java | 18 +- .../tajo/exception/UnsupportedException.java | 19 +- .../src/main/proto/PrimitiveProtos.proto | 24 + tajo-common/src/main/proto/errors.proto | 330 +++++++ tajo-common/src/main/proto/stacktrace.proto | 33 + .../org/apache/tajo/common/type/TestIPv4.java | 2 +- .../org/apache/tajo/benchmark/BenchmarkSet.java | 7 +- .../java/org/apache/tajo/benchmark/TPCH.java | 13 +- .../apache/tajo/engine/parser/SQLAnalyzer.java | 1 - .../tajo/engine/parser/SQLSyntaxError.java | 11 +- .../org/apache/tajo/master/GlobalEngine.java | 50 +- .../tajo/master/TajoMasterClientService.java | 379 ++++---- .../apache/tajo/master/exec/DDLExecutor.java | 69 +- .../apache/tajo/master/exec/QueryExecutor.java | 43 +- .../session/NoSuchSessionVariableException.java | 8 +- .../tajo/webapp/QueryExecutorServlet.java | 47 +- .../tajo/worker/TajoWorkerClientService.java | 9 +- .../tajo/ws/rs/resources/QueryResource.java | 7 +- .../ws/rs/resources/QueryResultResource.java | 6 +- .../tajo/ws/rs/resources/SessionsResource.java | 15 +- .../responses/GetQueryResultDataResponse.java | 8 +- .../ws/rs/responses/GetSubmitQueryResponse.java | 8 +- .../ws/rs/responses/NewSessionResponse.java | 11 +- .../apache/tajo/LocalTajoTestingUtility.java | 3 +- .../java/org/apache/tajo/QueryTestCaseBase.java | 45 +- .../org/apache/tajo/TajoTestingCluster.java | 3 +- .../org/apache/tajo/client/TestTajoClient.java | 121 +-- .../tajo/client/TestTajoClientFailures.java | 75 ++ .../apache/tajo/engine/eval/ExprTestBase.java | 12 +- .../tajo/engine/eval/TestSQLExpression.java | 8 +- .../function/TestConditionalExpressions.java | 10 +- .../tajo/engine/query/TestInnerJoinQuery.java | 3 +- .../engine/query/TestInnerJoinWithSubQuery.java | 3 +- .../query/TestJoinOnPartitionedTables.java | 3 +- .../apache/tajo/engine/query/TestJoinQuery.java | 9 +- .../engine/query/TestMultipleJoinTypes.java | 4 +- .../tajo/engine/query/TestOuterJoinQuery.java | 5 +- .../engine/query/TestOuterJoinWithSubQuery.java | 4 +- .../tajo/engine/query/TestTablePartitions.java | 9 +- .../java/org/apache/tajo/jdbc/TestSQLState.java | 91 ++ .../java/org/apache/tajo/jdbc/TestTajoJdbc.java | 2 +- .../tajo/ws/rs/resources/TestQueryResource.java | 7 +- .../rs/resources/TestQueryResultResource.java | 13 +- .../ws/rs/resources/TestTablesResource.java | 6 +- .../testAlterTableAddDropPartition.result | 2 +- .../TestTajoCli/testStopWhenError.result | 2 +- .../testStopWhenErrorDeprecated.result | 2 +- .../org/apache/tajo/jdbc/JdbcConnection.java | 40 +- .../apache/tajo/jdbc/TajoDatabaseMetaData.java | 21 +- .../org/apache/tajo/jdbc/TajoStatement.java | 43 +- .../org/apache/tajo/plan/ExprAnnotator.java | 54 +- .../org/apache/tajo/plan/ExprNormalizer.java | 4 +- .../tajo/plan/LogicalPlanPreprocessor.java | 6 +- .../org/apache/tajo/plan/LogicalPlanner.java | 20 +- .../org/apache/tajo/plan/PlanningException.java | 3 +- .../org/apache/tajo/plan/TypeDeterminant.java | 10 +- .../tajo/plan/expr/GeneralFunctionEval.java | 6 +- .../plan/logical/NoSuchColumnException.java | 34 - .../tajo/plan/nameresolver/NameResolver.java | 8 +- .../plan/nameresolver/ResolverByLegacy.java | 6 +- .../tajo/plan/nameresolver/ResolverByRels.java | 4 +- .../nameresolver/ResolverByRelsAndSubExprs.java | 4 +- .../nameresolver/ResolverBySubExprsAndRels.java | 4 +- .../rewrite/rules/PartitionedTableRewriter.java | 2 +- .../tajo/plan/serder/EvalNodeDeserializer.java | 12 +- .../tajo/plan/verifier/ExprsVerifier.java | 12 +- .../tajo/plan/verifier/LogicalPlanVerifier.java | 29 +- .../plan/verifier/PreLogicalPlanVerifier.java | 43 +- .../plan/verifier/SyntaxErrorException.java | 29 + .../tajo/plan/verifier/SyntaxErrorUtil.java | 54 ++ .../tajo/plan/verifier/VerificationState.java | 16 +- .../tajo/storage/json/JsonLineDeserializer.java | 7 +- .../tajo/storage/json/JsonLineSerializer.java | 5 +- .../tajo/storage/text/DelimitedLineReader.java | 4 +- 160 files changed, 4674 insertions(+), 2855 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 1529c08..f90ade9 100644 --- a/CHANGES +++ b/CHANGES @@ -381,6 +381,8 @@ Release 0.11.0 - unreleased SUB TASKS + TAJO-1670: Refactor client errors and exceptions. (hyunsik) + TAJO-1514: Distinguish UNION and UNION ALL. (contributed by Keuntae Park, committed by hyunsik) http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java index 766f6c2..f7f7785 100644 --- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java +++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java @@ -22,16 +22,19 @@ import com.google.protobuf.ServiceException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tajo.annotation.Nullable; -import org.apache.tajo.catalog.CatalogProtocol.CatalogProtocolService; -import org.apache.tajo.catalog.exception.NoSuchFunctionException; +import org.apache.tajo.catalog.CatalogProtocol.CatalogProtocolService.BlockingInterface; +import org.apache.tajo.catalog.CatalogProtocol.*; +import org.apache.tajo.catalog.exception.AmbiguousFunctionException; +import org.apache.tajo.catalog.exception.UndefinedFunctionException; +import org.apache.tajo.catalog.exception.UndefinedPartitionException; import org.apache.tajo.catalog.partition.PartitionMethodDesc; -import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.*; import org.apache.tajo.common.TajoDataTypes.DataType; import org.apache.tajo.conf.TajoConf; -import org.apache.tajo.exception.InvalidOperationException; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.exception.ReturnStateUtil; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.NullProto; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListResponse; import org.apache.tajo.util.ProtoUtil; import java.io.Closeable; @@ -39,6 +42,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import static org.apache.tajo.catalog.CatalogUtil.buildTableIdentifier; +import static org.apache.tajo.exception.ReturnStateUtil.*; + /** * CatalogClient provides a client API to access the catalog server. */ @@ -51,113 +57,132 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable this.conf = conf; } - abstract CatalogProtocolService.BlockingInterface getStub() throws ServiceException; + abstract BlockingInterface getStub() throws ServiceException; @Override public final Boolean createTablespace(final String tablespaceName, final String tablespaceUri) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); + final BlockingInterface stub = getStub(); + final CreateTablespaceRequest request = CreateTablespaceRequest.newBuilder() + .setTablespaceName(tablespaceName) + .setTablespaceUri(tablespaceUri) + .build(); - CreateTablespaceRequest.Builder builder = CreateTablespaceRequest.newBuilder(); - builder.setTablespaceName(tablespaceName); - builder.setTablespaceUri(tablespaceUri); - return stub.createTablespace(null, builder.build()).getValue(); - } catch (Exception e) { - LOG.error(e.getMessage(), e); - return Boolean.FALSE; + return isSuccess(stub.createTablespace(null, request)); + + } catch (ServiceException e) { + throw new RuntimeException(e); } } @Override public final Boolean dropTablespace(final String tablespaceName) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.dropTablespace(null, ProtoUtil.convertString(tablespaceName)).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.dropTablespace(null, ProtoUtil.convertString(tablespaceName))); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return Boolean.FALSE; + throw new RuntimeException(e); } } @Override public final Boolean existTablespace(final String tablespaceName) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.existTablespace(null, ProtoUtil.convertString(tablespaceName)).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.existTablespace(null, ProtoUtil.convertString(tablespaceName))); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return Boolean.FALSE; + throw new RuntimeException(e); } } @Override public final Collection<String> getAllTablespaceNames() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - PrimitiveProtos.StringListProto response = stub.getAllTablespaceNames(null, ProtoUtil.NULL_PROTO); - return ProtoUtil.convertStrings(response); + final BlockingInterface stub = getStub(); + final StringListResponse response = stub.getAllTablespaceNames(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + + return response.getValuesList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<String>(); + throw new RuntimeException(e); } } - + @Override public List<TablespaceProto> getAllTablespaces() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - CatalogProtos.GetTablespacesProto response = stub.getAllTablespaces(null, ProtoUtil.NULL_PROTO); + final BlockingInterface stub = getStub(); + final GetTablespaceListResponse response = stub.getAllTablespaces(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + return response.getTablespaceList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<TablespaceProto>(); + throw new RuntimeException(e); } } @Override public TablespaceProto getTablespace(final String tablespaceName) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.getTablespace(null, ProtoUtil.convertString(tablespaceName)); + final BlockingInterface stub = getStub(); + final GetTablespaceResponse response = stub.getTablespace(null, ProtoUtil.convertString(tablespaceName)); + ensureOk(response.getState()); + + return response.getTablespace(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return null; + throw new RuntimeException(e); } } @Override public Boolean alterTablespace(final AlterTablespaceProto alterTablespace) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.alterTablespace(null, alterTablespace).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.alterTablespace(null, alterTablespace)); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public final Boolean createDatabase(final String databaseName, @Nullable final String tablespaceName) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - CreateDatabaseRequest.Builder builder = CreateDatabaseRequest.newBuilder(); + final BlockingInterface stub = getStub(); + final CreateDatabaseRequest.Builder builder = CreateDatabaseRequest.newBuilder(); builder.setDatabaseName(databaseName); if (tablespaceName != null) { builder.setTablespaceName(tablespaceName); } - return stub.createDatabase(null, builder.build()).getValue(); + + return isSuccess(stub.createDatabase(null, builder.build())); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return Boolean.FALSE; + throw new RuntimeException(e); } } @Override public final Boolean dropDatabase(final String databaseName) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.dropDatabase(null, ProtoUtil.convertString(databaseName)).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.dropDatabase(null, ProtoUtil.convertString(databaseName))); + } catch (ServiceException e) { LOG.error(e.getMessage(), e); return Boolean.FALSE; @@ -166,191 +191,227 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable @Override public final Boolean existDatabase(final String databaseName) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.existDatabase(null, ProtoUtil.convertString(databaseName)).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.existDatabase(null, ProtoUtil.convertString(databaseName))); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return Boolean.FALSE; + throw new RuntimeException(e); } } @Override public final Collection<String> getAllDatabaseNames() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - PrimitiveProtos.StringListProto response = stub.getAllDatabaseNames(null, ProtoUtil.NULL_PROTO); - return ProtoUtil.convertStrings(response); + final BlockingInterface stub = getStub(); + final StringListResponse response = stub.getAllDatabaseNames(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + + return response.getValuesList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<String>(); + throw new RuntimeException(e); } } - + @Override public List<DatabaseProto> getAllDatabases() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetDatabasesProto response = stub.getAllDatabases(null, ProtoUtil.NULL_PROTO); + final BlockingInterface stub = getStub(); + final GetDatabasesResponse response = stub.getAllDatabases(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + return response.getDatabaseList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<DatabaseProto>(); + throw new RuntimeException(e); } } @Override public final TableDesc getTableDesc(final String databaseName, final String tableName) { + try { - TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); + final BlockingInterface stub = getStub(); + final TableIdentifierProto request = buildTableIdentifier(databaseName, tableName); + + TableResponse response = stub.getTableDesc(null, request); + ensureOk(response.getState()); + + return CatalogUtil.newTableDesc(response.getTable()); - CatalogProtocolService.BlockingInterface stub = getStub(); - return CatalogUtil.newTableDesc(stub.getTableDesc(null, builder.build())); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return null; + throw new RuntimeException(e); } } @Override public TableDesc getTableDesc(String qualifiedName) { - String [] splitted = CatalogUtil.splitFQTableName(qualifiedName); + String[] splitted = CatalogUtil.splitFQTableName(qualifiedName); return getTableDesc(splitted[0], splitted[1]); } - + @Override public List<TableDescriptorProto> getAllTables() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetTablesProto response = stub.getAllTables(null, ProtoUtil.NULL_PROTO); + final BlockingInterface stub = getStub(); + final GetTablesResponse response = stub.getAllTables(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + return response.getTableList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<TableDescriptorProto>(); + throw new RuntimeException(e); } } - + @Override public List<TableOptionProto> getAllTableOptions() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetTableOptionsProto response = stub.getAllTableOptions(null, ProtoUtil.NULL_PROTO); - return response.getTableOptionList(); + final BlockingInterface stub = getStub(); + final GetTablePropertiesResponse response = stub.getAllTableProperties(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + + return response.getPropertiesList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<TableOptionProto>(); + throw new RuntimeException(e); } } - + @Override public List<TableStatsProto> getAllTableStats() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetTableStatsProto response = stub.getAllTableStats(null, ProtoUtil.NULL_PROTO); - return response.getStatList(); + final BlockingInterface stub = getStub(); + final GetTableStatsResponse response = stub.getAllTableStats(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + + return response.getStatsList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<TableStatsProto>(); + throw new RuntimeException(e); } } - + @Override public List<ColumnProto> getAllColumns() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetColumnsProto response = stub.getAllColumns(null, ProtoUtil.NULL_PROTO); + final BlockingInterface stub = getStub(); + final GetColumnsResponse response = stub.getAllColumns(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + return response.getColumnList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<ColumnProto>(); + throw new RuntimeException(e); } } @Override public final PartitionMethodDesc getPartitionMethod(final String databaseName, final String tableName) { + try { - TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); + final BlockingInterface stub = getStub(); + final TableIdentifierProto request = buildTableIdentifier(databaseName, tableName); + final GetPartitionMethodResponse response = stub.getPartitionMethodByTableName(null, request); + ensureOk(response.getState()); + + return CatalogUtil.newPartitionMethodDesc(response.getPartition()); - CatalogProtocolService.BlockingInterface stub = getStub(); - return CatalogUtil.newPartitionMethodDesc(stub.getPartitionMethodByTableName(null, builder.build())); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return null; + throw new RuntimeException(e); } } @Override public final boolean existPartitionMethod(final String databaseName, final String tableName) { try { - TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); + final BlockingInterface stub = getStub(); + final TableIdentifierProto request = buildTableIdentifier(databaseName, tableName); + return isSuccess(stub.existPartitionMethod(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.existPartitionMethod(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public final PartitionDescProto getPartition(final String databaseName, final String tableName, - final String partitionName) { + final String partitionName) throws UndefinedPartitionException { try { - PartitionIdentifierProto.Builder builder = PartitionIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); - builder.setPartitionName(partitionName); + final BlockingInterface stub = getStub(); + final PartitionIdentifierProto request = PartitionIdentifierProto.newBuilder() + .setDatabaseName(databaseName) + .setTableName(tableName) + .setPartitionName(partitionName) + .build(); + + final GetPartitionDescResponse response = stub.getPartitionByPartitionName(null, request); + + if (ReturnStateUtil.isThisError(response.getState(), ResultCode.UNDEFINED_PARTITION)) { + throw new UndefinedPartitionException(partitionName); + } + + ensureOk(response.getState()); + + return response.getPartition(); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.getPartitionByPartitionName(null, builder.build()); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return null; + throw new RuntimeException(e); } } @Override public final List<PartitionDescProto> getPartitions(final String databaseName, final String tableName) { try { - PartitionIdentifierProto.Builder builder = PartitionIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); + final BlockingInterface stub = getStub(); + final PartitionIdentifierProto request = PartitionIdentifierProto.newBuilder() + .setDatabaseName(databaseName) + .setTableName(tableName) + .build(); + + final GetPartitionsResponse response = stub.getPartitionsByTableName(null, request); + ensureOk(response.getState()); - CatalogProtocolService.BlockingInterface stub = getStub(); - PartitionsProto response = stub.getPartitionsByTableName(null, builder.build()); return response.getPartitionList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<PartitionDescProto>(); + throw new RuntimeException(e); } } + @Override public List<TablePartitionProto> getAllPartitions() { try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetTablePartitionsProto response = stub.getAllPartitions(null, ProtoUtil.NULL_PROTO); + final BlockingInterface stub = getStub(); + final GetTablePartitionsResponse response = stub.getAllPartitions(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + return response.getPartList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<TablePartitionProto>(); + throw new RuntimeException(e); } } @Override public final Collection<String> getAllTableNames(final String databaseName) { try { - CatalogProtocolService.BlockingInterface stub = getStub(); - PrimitiveProtos.StringListProto response = stub.getAllTableNames(null, ProtoUtil.convertString(databaseName)); - return ProtoUtil.convertStrings(response); + final BlockingInterface stub = getStub(); + final StringListResponse response = stub.getAllTableNames(null, ProtoUtil.convertString(databaseName)); + ensureOk(response.getState()); + + return response.getValuesList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<String>(); + throw new RuntimeException(e); } } @@ -359,7 +420,7 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable List<FunctionDesc> list = new ArrayList<FunctionDesc>(); try { GetFunctionsResponse response; - CatalogProtocolService.BlockingInterface stub = getStub(); + BlockingInterface stub = getStub(); response = stub.getFunctions(null, NullProto.newBuilder().build()); int size = response.getFunctionDescCount(); for (int i = 0; i < size; i++) { @@ -372,38 +433,36 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable } return list; } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return list; + throw new RuntimeException(e); } } @Override public final boolean createTable(final TableDesc desc) { try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.createTable(null, desc.getProto()).getValue(); + final BlockingInterface stub = getStub(); + + return isSuccess(stub.createTable(null, desc.getProto())); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public boolean dropTable(String tableName) { - String [] splitted = CatalogUtil.splitFQTableName(tableName); + String[] splitted = CatalogUtil.splitFQTableName(tableName); final String databaseName = splitted[0]; final String simpleName = splitted[1]; try { - TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(simpleName); + final BlockingInterface stub = getStub(); + final TableIdentifierProto request = buildTableIdentifier(databaseName, simpleName); + + return isSuccess(stub.dropTable(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.dropTable(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @@ -413,47 +472,51 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable throw new IllegalArgumentException( "tableName cannot be composed of multiple parts, but it is \"" + tableName + "\""); } + try { - TableIdentifierProto.Builder builder = TableIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); + final BlockingInterface stub = getStub(); + final TableIdentifierProto request = buildTableIdentifier(databaseName, tableName); + + return isSuccess(stub.existsTable(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.existsTable(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } + @Override public final boolean existsTable(final String tableName) { - String [] splitted = CatalogUtil.splitFQTableName(tableName); + String[] splitted = CatalogUtil.splitFQTableName(tableName); return existsTable(splitted[0], splitted[1]); } @Override public final boolean createIndex(final IndexDesc index) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.createIndex(null, index.getProto()).getValue(); + final BlockingInterface stub = getStub(); + + return isSuccess(stub.createIndex(null, index.getProto())); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public final boolean existIndexByName(final String databaseName, final String indexName) { try { - IndexNameProto.Builder builder = IndexNameProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setIndexName(indexName); + final IndexNameProto request = IndexNameProto.newBuilder() + .setDatabaseName(databaseName) + .setIndexName(indexName) + .build(); + + final BlockingInterface stub = getStub(); + + return isSuccess(stub.existIndexByName(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.existIndexByName(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @@ -461,30 +524,37 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable public boolean existIndexByColumn(final String databaseName, final String tableName, final String columnName) { try { - GetIndexByColumnRequest.Builder builder = GetIndexByColumnRequest.newBuilder(); - builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName)); - builder.setColumnName(columnName); + final GetIndexByColumnRequest request = GetIndexByColumnRequest.newBuilder() + .setTableIdentifier(buildTableIdentifier(databaseName, tableName)) + .setColumnName(columnName) + .build(); + + final BlockingInterface stub = getStub(); + + return isSuccess(stub.existIndexByColumn(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.existIndexByColumn(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public final IndexDesc getIndexByName(final String databaseName, final String indexName) { + try { - IndexNameProto.Builder builder = IndexNameProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setIndexName(indexName); + final IndexNameProto request = IndexNameProto.newBuilder() + .setDatabaseName(databaseName) + .setIndexName(indexName) + .build(); + + final BlockingInterface stub = getStub(); + final GetIndexResponse response = stub.getIndexByName(null, request); + ensureOk(response.getState()); + + return new IndexDesc(response.getIndex()); - CatalogProtocolService.BlockingInterface stub = getStub(); - return new IndexDesc(stub.getIndexByName(null, builder.build())); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return null; + throw new RuntimeException(e); } } @@ -493,78 +563,93 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable final String tableName, final String columnName) { try { - GetIndexByColumnRequest.Builder builder = GetIndexByColumnRequest.newBuilder(); - builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName)); - builder.setColumnName(columnName); - CatalogProtocolService.BlockingInterface stub = getStub(); - return new IndexDesc(stub.getIndexByColumn(null, builder.build())); + final GetIndexByColumnRequest request = GetIndexByColumnRequest.newBuilder() + .setTableIdentifier(buildTableIdentifier(databaseName, tableName)) + .setColumnName(columnName) + .build(); + + final BlockingInterface stub = getStub(); + final GetIndexResponse response = stub.getIndexByColumn(null, request); + ensureOk(response.getState());; + + return new IndexDesc(response.getIndex()); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return null; + throw new RuntimeException(e); } } @Override - public boolean dropIndex(final String databaseName, - final String indexName) { + public boolean dropIndex(final String dbName, final String indexName) { try { - IndexNameProto.Builder builder = IndexNameProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setIndexName(indexName); + final IndexNameProto request = IndexNameProto.newBuilder() + .setDatabaseName(dbName) + .setIndexName(indexName) + .build(); + + final BlockingInterface stub = getStub(); + + return isSuccess(stub.dropIndex(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.dropIndex(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } - + @Override public List<IndexProto> getAllIndexes() { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - GetIndexesProto response = stub.getAllIndexes(null, ProtoUtil.NULL_PROTO); + final BlockingInterface stub = getStub(); + final GetIndexesResponse response = stub.getAllIndexes(null, ProtoUtil.NULL_PROTO); + ensureOk(response.getState()); + return response.getIndexList(); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return new ArrayList<IndexProto>(); + throw new RuntimeException(e); } } @Override public final boolean createFunction(final FunctionDesc funcDesc) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.createFunction(null, funcDesc.getProto()).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.createFunction(null, funcDesc.getProto())); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public final boolean dropFunction(final String signature) { + try { - UnregisterFunctionRequest.Builder builder = UnregisterFunctionRequest.newBuilder(); - builder.setSignature(signature); + final UnregisterFunctionRequest request = UnregisterFunctionRequest.newBuilder() + .setSignature(signature) + .build(); + + final BlockingInterface stub = getStub(); + return isSuccess(stub.dropFunction(null, request)); - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.dropFunction(null, builder.build()).getValue(); } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override - public final FunctionDesc getFunction(final String signature, DataType... paramTypes) { + public final FunctionDesc getFunction(final String signature, DataType... paramTypes) + throws UndefinedFunctionException { return getFunction(signature, null, paramTypes); } @Override - public final FunctionDesc getFunction(final String signature, FunctionType funcType, DataType... paramTypes) { + public final FunctionDesc getFunction(final String signature, FunctionType funcType, DataType... paramTypes) + throws UndefinedFunctionException { + final GetFunctionMetaRequest.Builder builder = GetFunctionMetaRequest.newBuilder(); builder.setSignature(signature); if (funcType != null) { @@ -574,25 +659,26 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable builder.addParameterTypes(type); } - FunctionDescProto descProto = null; + FunctionResponse response = null; try { - CatalogProtocolService.BlockingInterface stub = getStub(); - descProto = stub.getFunctionMeta(null, builder.build()); - } catch (NoSuchFunctionException e) { - LOG.debug(e.getMessage()); - } catch (ServiceException e) { - LOG.error(e.getMessage(), e); + final BlockingInterface stub = getStub(); + response = stub.getFunctionMeta(null, builder.build()); + } catch (ServiceException se) { + throw new RuntimeException(se); } - if (descProto == null) { - throw new NoSuchFunctionException(signature, paramTypes); + if (isThisError(response.getState(), ResultCode.UNDEFINED_FUNCTION)) { + throw new UndefinedFunctionException(signature, paramTypes); + } else if (isThisError(response.getState(), ResultCode.AMBIGUOUS_FUNCTION)) { + throw new AmbiguousFunctionException(signature, paramTypes); } + ensureOk(response.getState()); + try { - return new FunctionDesc(descProto); + return new FunctionDesc(response.getFunction()); } catch (ClassNotFoundException e) { - LOG.error(e, e); - throw new NoSuchFunctionException(signature, paramTypes); + throw new RuntimeException(e); } } @@ -603,8 +689,9 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable @Override public final boolean containFunction(final String signature, FunctionType funcType, DataType... paramTypes) { - final ContainFunctionRequest.Builder builder = - ContainFunctionRequest.newBuilder(); + + final ContainFunctionRequest.Builder builder = ContainFunctionRequest.newBuilder(); + if (funcType != null) { builder.setFunctionType(funcType); } @@ -614,35 +701,35 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable } try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.containFunction(null, builder.build()).getValue(); - } catch (InvalidOperationException e) { - LOG.error(e.getMessage()); + final BlockingInterface stub = getStub(); + return isSuccess(stub.containFunction(null, builder.build())); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); + throw new RuntimeException(e); } - return false; } @Override public final boolean alterTable(final AlterTableDesc desc) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.alterTable(null, desc.getProto()).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.alterTable(null, desc.getProto())); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } @Override public boolean updateTableStats(final UpdateTableStatsProto updateTableStatsProto) { + try { - CatalogProtocolService.BlockingInterface stub = getStub(); - return stub.updateTableStats(null, updateTableStatsProto).getValue(); + final BlockingInterface stub = getStub(); + return isSuccess(stub.updateTableStats(null, updateTableStatsProto)); + } catch (ServiceException e) { - LOG.error(e.getMessage(), e); - return false; + throw new RuntimeException(e); } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto b/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto index 5ace32e..8d0eef6 100644 --- a/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto +++ b/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto @@ -24,53 +24,118 @@ option java_generate_equals_and_hash = true; import "CatalogProtos.proto"; import "PrimitiveProtos.proto"; +message GetTablespaceListResponse { + required ReturnState state = 1; + repeated TablespaceProto tablespace = 2; +} + +message GetTablespaceResponse { + required ReturnState state = 1; + optional TablespaceProto tablespace = 2; +} + +message GetDatabasesResponse { + required ReturnState state = 1; + repeated DatabaseProto database = 2; +} + +message GetTablesResponse { + required ReturnState state = 1; + repeated TableDescriptorProto table = 2; +} + +message GetTablePropertiesResponse { + required ReturnState state = 1; + repeated TableOptionProto properties = 2; +} + +message GetTableStatsResponse { + required ReturnState state = 1; + repeated TableStatsProto stats = 2; +} + +message GetColumnsResponse { + required ReturnState state = 1; + repeated ColumnProto column = 2; +} + +message GetPartitionMethodResponse { + required ReturnState state = 1; + optional PartitionMethodProto partition = 2; +} + +message GetPartitionDescResponse { + required ReturnState state = 1; + optional PartitionDescProto partition = 2; +} + +message GetIndexResponse { + required ReturnState state = 1; + optional IndexDescProto index = 2; +} + +message GetIndexesResponse { + required ReturnState state = 1; + repeated IndexProto index = 2; +} + +message GetPartitionsResponse { + required ReturnState state = 1; + repeated PartitionDescProto partition = 2; +} + +message GetTablePartitionsResponse { + required ReturnState state = 1; + repeated TablePartitionProto part = 2; +} + service CatalogProtocolService { - rpc createTablespace(CreateTablespaceRequest) returns (BoolProto); - rpc dropTablespace(StringProto) returns (BoolProto); - rpc existTablespace(StringProto) returns (BoolProto); - rpc getAllTablespaces(NullProto) returns (GetTablespacesProto); - rpc getAllTablespaceNames(NullProto) returns (StringListProto); - rpc getTablespace(StringProto) returns (TablespaceProto); - rpc alterTablespace(AlterTablespaceProto) returns (BoolProto); - rpc alterTable(AlterTableDescProto) returns (BoolProto); - rpc updateTableStats(UpdateTableStatsProto) returns (BoolProto); - - rpc createDatabase(CreateDatabaseRequest) returns (BoolProto); - rpc dropDatabase(StringProto) returns (BoolProto); - rpc existDatabase(StringProto) returns (BoolProto); - rpc getAllDatabaseNames(NullProto) returns (StringListProto); - rpc getAllDatabases(NullProto) returns (GetDatabasesProto); - - rpc createTable(TableDescProto) returns (BoolProto); - rpc dropTable(TableIdentifierProto) returns (BoolProto); - rpc existsTable(TableIdentifierProto) returns (BoolProto); - rpc getTableDesc(TableIdentifierProto) returns (TableDescProto); - rpc getAllTableNames(StringProto) returns (StringListProto); - rpc getAllTables(NullProto) returns (GetTablesProto); - rpc getAllTableOptions(NullProto) returns (GetTableOptionsProto); - rpc getAllTableStats(NullProto) returns (GetTableStatsProto); - rpc getAllColumns(NullProto) returns (GetColumnsProto); - - rpc getPartitionMethodByTableName(TableIdentifierProto) returns (PartitionMethodProto); - rpc existPartitionMethod(TableIdentifierProto) returns (BoolProto); - rpc dropPartitionMethod(TableIdentifierProto) returns (BoolProto); - - rpc getPartitionByPartitionName(PartitionIdentifierProto) returns (PartitionDescProto); - rpc getPartitionsByTableName(PartitionIdentifierProto) returns (PartitionsProto); - rpc getAllPartitions(NullProto) returns (GetTablePartitionsProto); - - rpc createIndex(IndexDescProto) returns (BoolProto); - rpc dropIndex(IndexNameProto) returns (BoolProto); - rpc existIndexByName(IndexNameProto) returns (BoolProto); - rpc existIndexByColumn(GetIndexByColumnRequest) returns (BoolProto); - rpc getIndexByName(IndexNameProto) returns (IndexDescProto); - rpc getIndexByColumn(GetIndexByColumnRequest) returns (IndexDescProto); - rpc getAllIndexes(NullProto) returns (GetIndexesProto); - - rpc createFunction(FunctionDescProto) returns (BoolProto); - rpc dropFunction(UnregisterFunctionRequest) returns (BoolProto); + rpc createTablespace(CreateTablespaceRequest) returns (ReturnState); + rpc dropTablespace(StringProto) returns (ReturnState); + rpc existTablespace(StringProto) returns (ReturnState); + rpc getAllTablespaces(NullProto) returns (GetTablespaceListResponse); + rpc getAllTablespaceNames(NullProto) returns (StringListResponse); + rpc getTablespace(StringProto) returns (GetTablespaceResponse); + rpc alterTablespace(AlterTablespaceProto) returns (ReturnState); + rpc alterTable(AlterTableDescProto) returns (ReturnState); + rpc updateTableStats(UpdateTableStatsProto) returns (ReturnState); + + rpc createDatabase(CreateDatabaseRequest) returns (ReturnState); + rpc dropDatabase(StringProto) returns (ReturnState); + rpc existDatabase(StringProto) returns (ReturnState); + rpc getAllDatabaseNames(NullProto) returns (StringListResponse); + rpc getAllDatabases(NullProto) returns (GetDatabasesResponse); + + rpc createTable(TableDescProto) returns (ReturnState); + rpc dropTable(TableIdentifierProto) returns (ReturnState); + rpc existsTable(TableIdentifierProto) returns (ReturnState); + rpc getTableDesc(TableIdentifierProto) returns (TableResponse); + rpc getAllTableNames(StringProto) returns (StringListResponse); + rpc getAllTables(NullProto) returns (GetTablesResponse); + rpc getAllTableProperties(NullProto) returns (GetTablePropertiesResponse); + rpc getAllTableStats(NullProto) returns (GetTableStatsResponse); + rpc getAllColumns(NullProto) returns (GetColumnsResponse); + + rpc getPartitionMethodByTableName(TableIdentifierProto) returns (GetPartitionMethodResponse); + rpc existPartitionMethod(TableIdentifierProto) returns (ReturnState); + rpc dropPartitionMethod(TableIdentifierProto) returns (ReturnState); + + rpc getPartitionByPartitionName(PartitionIdentifierProto) returns (GetPartitionDescResponse); + rpc getPartitionsByTableName(PartitionIdentifierProto) returns (GetPartitionsResponse); + rpc getAllPartitions(NullProto) returns (GetTablePartitionsResponse); + + rpc createIndex(IndexDescProto) returns (ReturnState); + rpc dropIndex(IndexNameProto) returns (ReturnState); + rpc existIndexByName(IndexNameProto) returns (ReturnState); + rpc existIndexByColumn(GetIndexByColumnRequest) returns (ReturnState); + rpc getIndexByName(IndexNameProto) returns (GetIndexResponse); + rpc getIndexByColumn(GetIndexByColumnRequest) returns (GetIndexResponse); + rpc getAllIndexes(NullProto) returns (GetIndexesResponse); + + rpc createFunction(FunctionDescProto) returns (ReturnState); + rpc dropFunction(UnregisterFunctionRequest) returns (ReturnState); rpc getFunctions(NullProto) returns (GetFunctionsResponse); - rpc getFunctionMeta(GetFunctionMetaRequest) returns (FunctionDescProto); - rpc containFunction(ContainFunctionRequest) returns (BoolProto); + rpc getFunctionMeta(GetFunctionMetaRequest) returns (FunctionResponse); + rpc containFunction(ContainFunctionRequest) returns (ReturnState); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java index 86b773b..5dc5412 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java @@ -18,6 +18,8 @@ package org.apache.tajo.catalog; +import org.apache.tajo.catalog.exception.UndefinedFunctionException; +import org.apache.tajo.catalog.exception.UndefinedPartitionException; import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.ColumnProto; @@ -29,6 +31,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.TablePartitionProto; import org.apache.tajo.catalog.proto.CatalogProtos.TableStatsProto; import org.apache.tajo.common.TajoDataTypes.DataType; +import java.sql.SQLException; import java.util.Collection; import java.util.List; @@ -185,7 +188,8 @@ public interface CatalogService { boolean existPartitionMethod(String databaseName, String tableName); - CatalogProtos.PartitionDescProto getPartition(String databaseName, String tableName, String partitionName); + CatalogProtos.PartitionDescProto getPartition(String databaseName, String tableName, String partitionName) + throws UndefinedPartitionException; List<CatalogProtos.PartitionDescProto> getPartitions(String databaseName, String tableName); @@ -209,9 +213,9 @@ public interface CatalogService { boolean dropFunction(String signature); - FunctionDesc getFunction(String signature, DataType... paramTypes); + FunctionDesc getFunction(String signature, DataType... paramTypes) throws UndefinedFunctionException; - FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes); + FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws UndefinedFunctionException; boolean containFunction(String signature, DataType... paramTypes); http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java index ecf8890..87bd972 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java @@ -28,6 +28,7 @@ import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto; import org.apache.tajo.catalog.proto.CatalogProtos.TableDescProto; +import org.apache.tajo.catalog.proto.CatalogProtos.TableIdentifierProto; import org.apache.tajo.catalog.proto.CatalogProtos.PartitionKeyProto; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.common.TajoDataTypes.DataType; @@ -42,7 +43,10 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import static org.apache.tajo.catalog.proto.CatalogProtos.StoreType; import static org.apache.tajo.common.TajoDataTypes.Type; @@ -50,6 +54,7 @@ import static org.apache.tajo.common.TajoDataTypes.Type; public class CatalogUtil { public static final String TEXTFILE_NAME = "TEXT"; + /** * Normalize an identifier. Normalization means a translation from a identifier to be a refined identifier name. * @@ -688,11 +693,11 @@ public class CatalogUtil { return widest; } - public static CatalogProtos.TableIdentifierProto buildTableIdentifier(String databaseName, String tableName) { - CatalogProtos.TableIdentifierProto.Builder builder = CatalogProtos.TableIdentifierProto.newBuilder(); - builder.setDatabaseName(databaseName); - builder.setTableName(tableName); - return builder.build(); + public static TableIdentifierProto buildTableIdentifier(String databaseName, String tableName) { + return TableIdentifierProto.newBuilder() + .setDatabaseName(databaseName) + .setTableName(tableName) + .build(); } public static void closeQuietly(Connection conn) { http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java index 80c4d83..424861b 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java @@ -24,7 +24,7 @@ import com.google.gson.annotations.Expose; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tajo.catalog.SchemaUtil.ColumnVisitor; -import org.apache.tajo.catalog.exception.AlreadyExistsFieldException; +import org.apache.tajo.catalog.exception.DuplicateColumnException; import org.apache.tajo.catalog.json.CatalogGsonHelper; import org.apache.tajo.catalog.proto.CatalogProtos.ColumnProto; import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto; @@ -420,7 +420,7 @@ public class Schema implements ProtoObject<SchemaProto>, Cloneable, GsonObject { String normalized = name; if(fieldsByQualifiedName.containsKey(normalized)) { LOG.error("Already exists column " + normalized); - throw new AlreadyExistsFieldException(normalized); + throw new DuplicateColumnException(normalized); } Column newCol = new Column(normalized, typeDesc); http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java deleted file mode 100644 index f811689..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsDatabaseException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - - -public class AlreadyExistsDatabaseException extends CatalogException { - - public AlreadyExistsDatabaseException() { - } - - public AlreadyExistsDatabaseException(String dbName) { - super(String.format("Already exists database \"%s\"", dbName)); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFieldException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFieldException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFieldException.java deleted file mode 100644 index ee90278..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFieldException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - -public class AlreadyExistsFieldException extends CatalogException { - private static final long serialVersionUID = 6766228091940775275L; - - public AlreadyExistsFieldException() { - } - - public AlreadyExistsFieldException(String fieldName) { - super("Already Exists Field: "+fieldName); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFunctionException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFunctionException.java deleted file mode 100644 index 4bf70ae..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsFunctionException.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - -public class AlreadyExistsFunctionException extends CatalogException { - private static final long serialVersionUID = 3224521585413794703L; - - public AlreadyExistsFunctionException(String funcName) { - super("Already Exists Function: "+funcName); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java deleted file mode 100644 index 22c8172..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsIndexException.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - -import org.apache.tajo.annotation.Nullable; - -public class AlreadyExistsIndexException extends CatalogException { - private static final long serialVersionUID = 3705839985189534673L; - - /** - * - */ - public AlreadyExistsIndexException() { - } - - public AlreadyExistsIndexException(String databaseName, @Nullable String namespace, String indexName) { - super(String.format("index \" %s \" already exists in %s.%s", indexName, databaseName, namespace)); - } - - public AlreadyExistsIndexException(String indexName) { - super("index \"" + indexName + "\" exists table"); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsPartitionException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsPartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsPartitionException.java deleted file mode 100644 index a7f0d87..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsPartitionException.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - -public class AlreadyExistsPartitionException extends RuntimeException { - - private static final long serialVersionUID = 277182608283894930L; - - public AlreadyExistsPartitionException(String message) { - super(message); - } - - public AlreadyExistsPartitionException(String tableName, String partitionName) { - super(String.format("ERROR: partition \"%s already exist in \"%s\"", partitionName, tableName)); - } - - public AlreadyExistsPartitionException(String databaseName, String tableName, String partitionName) { - super(String.format("ERROR: partition \"%s already exist in \"%s.%s\"", partitionName, databaseName, tableName)); - } - -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java deleted file mode 100644 index ec4cf67..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTableException.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - - -public class AlreadyExistsTableException extends CatalogException { - private static final long serialVersionUID = -641623770742392865L; - - public AlreadyExistsTableException() { - } - - public AlreadyExistsTableException(String databaseName, String relName) { - super(String.format("relation \" %s \" already exists in %s", relName, databaseName)); - } - - public AlreadyExistsTableException(String tableName) { - super("relation \"" + tableName + "\" exists table"); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java deleted file mode 100644 index 49c5bf9..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AlreadyExistsTablespaceException.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.catalog.exception; - - -public class AlreadyExistsTablespaceException extends CatalogException { - - public AlreadyExistsTablespaceException() { - } - - public AlreadyExistsTablespaceException(String dbName) { - super(String.format("Already exists tablespace \"%s\"", dbName)); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java new file mode 100644 index 0000000..d1f17fd --- /dev/null +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.catalog.exception; + +import org.apache.tajo.common.TajoDataTypes.DataType; +import org.apache.tajo.error.Errors; + +import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature; + +public class AmbiguousFunctionException extends CatalogException { + public AmbiguousFunctionException(String funcName, DataType[] parameters) { + super(Errors.ResultCode.AMBIGUOUS_FUNCTION, buildSimpleFunctionSignature(funcName, parameters)); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java index 760bb71..7098800 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java @@ -18,34 +18,13 @@ package org.apache.tajo.catalog.exception; -public class CatalogException extends RuntimeException { - private static final long serialVersionUID = -26362412527118618L; - - /** - * - */ - public CatalogException() { - } +import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.exception.TajoRuntimeException; - /** - * @param message - */ - public CatalogException(String message) { - super(message); - } - - /** - * @param cause - */ - public CatalogException(Throwable cause) { - super(cause); - } +public class CatalogException extends TajoRuntimeException { + private static final long serialVersionUID = -26362412527118618L; - /** - * @param message - * @param cause - */ - public CatalogException(String message, Throwable cause) { - super(message, cause); + public CatalogException(ResultCode code, String...args) { + super(code, args); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogExceptionUtil.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogExceptionUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogExceptionUtil.java new file mode 100644 index 0000000..182a3f5 --- /dev/null +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogExceptionUtil.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.catalog.exception; + +import org.apache.tajo.common.TajoDataTypes; +import org.apache.tajo.error.Errors; +import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.function.FunctionUtil; + +import java.util.Collection; + +public class CatalogExceptionUtil { + + public static CatalogException makeUndefinedTable(String tbName) { + return new CatalogException(ResultCode.UNDEFINED_TABLE, tbName); + } + + public static CatalogException makeDuplicateTable(String tbName) { + return new CatalogException(ResultCode.DUPLICATE_TABLE, tbName); + } + + public static CatalogException makeCatalogUpgrade() { + return new CatalogException(ResultCode.CAT_UPGRADE_REQUIRED); + } + + public static CatalogException makeMDCNoMatchedDataType(String dataType) { + return new CatalogException(ResultCode.MDC_NO_MATCHED_DATATYPE, dataType); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java deleted file mode 100644 index 1c026d7..0000000 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tajo.catalog.exception; - - -public class ColumnNameAlreadyExistException extends CatalogException { - - private static final long serialVersionUID = -4863862140874083282L; - - public ColumnNameAlreadyExistException() { - } - - public ColumnNameAlreadyExistException(String columnName) { - super("Column already exists : " + columnName); - } -} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java new file mode 100644 index 0000000..121a289 --- /dev/null +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.catalog.exception; + +import org.apache.tajo.error.Errors; + +public class DuplicateColumnException extends CatalogException { + private static final long serialVersionUID = 6766228091940775275L; + + public DuplicateColumnException(String columnName) { + super(Errors.ResultCode.DUPLICATE_COLUMN, columnName); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java new file mode 100644 index 0000000..69e37d3 --- /dev/null +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.catalog.exception; + + +import org.apache.tajo.error.Errors; + +public class DuplicateDatabaseException extends CatalogException { + public DuplicateDatabaseException(String dbName) { + super(Errors.ResultCode.DUPLICATE_DATABASE, dbName); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateFunctionException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateFunctionException.java new file mode 100644 index 0000000..b5cde13 --- /dev/null +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateFunctionException.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.catalog.exception; + +import org.apache.tajo.common.TajoDataTypes.DataType; +import org.apache.tajo.error.Errors; + +import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature; + +public class DuplicateFunctionException extends CatalogException { + private static final long serialVersionUID = 3224521585413794703L; + + public DuplicateFunctionException(String funcName, DataType[] parameters) { + super(Errors.ResultCode.DUPLICATE_FUNCTION, buildSimpleFunctionSignature(funcName, parameters)); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java new file mode 100644 index 0000000..c510b16 --- /dev/null +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tajo.catalog.exception; + +import org.apache.tajo.error.Errors; + +public class DuplicateIndexException extends CatalogException { + private static final long serialVersionUID = 3705839985189534673L; + + public DuplicateIndexException(String indexName) { + super(Errors.ResultCode.DUPLICATE_INDEX, indexName); + } +}
