From 4597561198cf1d55fcd39cb76fc142facb0e9d34 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Tue, 28 Jul 2015 01:23:28 +0900 Subject: [PATCH 1/8] Add initial design for client API v2. --- tajo-client/pom.xml | 4 +- .../client/InvalidClientSessionException.java | 9 +- .../apache/tajo/client/SessionConnection.java | 38 +-- .../apache/tajo/client/v2/ClientDelegate.java | 38 +++ .../tajo/client/v2/ClientDeligateFactory.java | 26 ++ .../tajo/client/v2/LegacyClientDelegate.java | 247 ++++++++++++++++++ .../tajo/client/v2/QueryEventListener.java | 33 +++ .../apache/tajo/client/v2/QueryFuture.java | 54 ++++ .../apache/tajo/client/v2/QueryHandler.java | 41 +++ .../org/apache/tajo/client/v2/QueryState.java | 27 ++ .../tajo/client/v2/ServiceDiscovery.java | 22 ++ .../org/apache/tajo/client/v2/TajoClient.java | 139 ++++++++++ .../exception/ClientConnectionException.java | 28 ++ .../ClientUnableToConnectException.java | 28 ++ .../apache/tajo/exception/ErrorMessages.java | 3 + .../tajo/exception/ReturnStateUtil.java | 3 +- .../apache/tajo/exception/TajoException.java | 5 + .../tajo/session/InvalidSessionException.java | 7 +- 18 files changed, 727 insertions(+), 25 deletions(-) create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java diff --git a/tajo-client/pom.xml b/tajo-client/pom.xml index e6be476d4d..1044d289bd 100644 --- a/tajo-client/pom.xml +++ b/tajo-client/pom.xml @@ -51,8 +51,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 ${project.build.sourceEncoding} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java b/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java index acbc33f0ba..48ba5f68a0 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java @@ -18,10 +18,11 @@ package org.apache.tajo.client; -import com.google.protobuf.ServiceException; +import org.apache.tajo.error.Errors; +import org.apache.tajo.exception.TajoRuntimeException; -public class InvalidClientSessionException extends ServiceException { - public InvalidClientSessionException(String message) { - super(message); +public class InvalidClientSessionException extends TajoRuntimeException { + public InvalidClientSessionException(String sessionId) { + super(Errors.ResultCode.INVALID_SESSION, sessionId); } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java index f875335d8f..fe017a2a6e 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java @@ -26,6 +26,8 @@ import org.apache.tajo.annotation.NotNull; import org.apache.tajo.annotation.Nullable; import org.apache.tajo.auth.UserRoleInfo; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.client.v2.exception.ClientConnectionException; import org.apache.tajo.exception.SQLExceptionUtil; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.ClientProtos.SessionUpdateResponse; @@ -36,7 +38,6 @@ import org.apache.tajo.rpc.RpcChannelFactory; import org.apache.tajo.rpc.RpcClientManager; import org.apache.tajo.rpc.RpcConstants; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueSetResponse; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringResponse; @@ -57,14 +58,12 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.apache.tajo.error.Errors.ResultCode.NO_SUCH_SESSION_VARIABLE; -import static org.apache.tajo.exception.ReturnStateUtil.isError; -import static org.apache.tajo.exception.ReturnStateUtil.isSuccess; -import static org.apache.tajo.exception.ReturnStateUtil.isThisError; -import static org.apache.tajo.exception.SQLExceptionUtil.toSQLException; +import static org.apache.tajo.error.Errors.ResultCode.UNDEFINED_DATABASE; +import static org.apache.tajo.exception.ReturnStateUtil.*; import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError; +import static org.apache.tajo.exception.SQLExceptionUtil.toSQLException; import static org.apache.tajo.ipc.ClientProtos.CreateSessionRequest; import static org.apache.tajo.ipc.ClientProtos.CreateSessionResponse; -import static org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService; public class SessionConnection implements Closeable { @@ -117,7 +116,7 @@ public Map getClientSideSessionVars() { return Collections.unmodifiableMap(sessionVarsCache); } - public synchronized NettyClientBase getTajoMasterConnection() throws SQLException { + public synchronized NettyClientBase getTajoMasterConnection() { if (client != null && client.isConnected()) { return client; @@ -138,14 +137,14 @@ public synchronized NettyClientBase getTajoMasterConnection() throws SQLExceptio connections.incrementAndGet(); } catch (Throwable t) { - throw SQLExceptionUtil.makeUnableToEstablishConnection(t); + throw new ClientConnectionException(t); } return client; } } - protected BlockingInterface getTMStub() throws SQLException { + protected BlockingInterface getTMStub() { NettyClientBase tmClient; tmClient = getTajoMasterConnection(); BlockingInterface stub = tmClient.getStub(); @@ -185,7 +184,7 @@ public UserRoleInfo getUserInfo() { return userInfo; } - public String getCurrentDatabase() throws SQLException { + public String getCurrentDatabase() { NettyClientBase client = getTajoMasterConnection(); checkSessionAndGet(client); @@ -198,7 +197,7 @@ public String getCurrentDatabase() throws SQLException { throw new RuntimeException(e); } - throwIfError(response.getState()); + ensureOk(response.getState()); return response.getValue(); } @@ -315,18 +314,25 @@ public Map getAllSessionVariables() throws SQLException { return ProtoUtil.convertToMap(response.getValue()); } - public Boolean selectDatabase(final String databaseName) throws SQLException { + public Boolean selectDatabase(final String dbName) throws UndefinedDatabaseException { BlockingInterface stub = getTMStub(); boolean selected; try { - selected = isSuccess(stub.selectDatabase(null, getSessionedString(databaseName))); + ReturnState state = stub.selectDatabase(null, getSessionedString(dbName)); + + if (isThisError(state, UNDEFINED_DATABASE)) { + throw new UndefinedDatabaseException(dbName); + } + + selected = ensureOk(state); + } catch (ServiceException e) { throw new RuntimeException(e); } if (selected) { - this.baseDatabase = databaseName; + this.baseDatabase = dbName; } return selected; } @@ -362,7 +368,7 @@ protected InetSocketAddress getTajoMasterAddr() { return serviceTracker.getClientServiceAddress(); } - protected void checkSessionAndGet(NettyClientBase client) throws SQLException { + protected void checkSessionAndGet(NettyClientBase client) { if (sessionId == null) { @@ -391,7 +397,7 @@ protected void checkSessionAndGet(NettyClientBase client) throws SQLException { LOG.debug(String.format("Got session %s as a user '%s'.", sessionId.getId(), userInfo.getUserName())); } } else { - throw SQLExceptionUtil.toSQLException(response.getState()); + throw new InvalidClientSessionException(sessionId.getId()); } } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java new file mode 100644 index 0000000000..bdf10c31f1 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java @@ -0,0 +1,38 @@ +/** + * 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.client.v2; + +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.exception.TajoException; + +import java.sql.ResultSet; + +/** + * ClientDelegate is a delegate for various wired protocols like protocol buffer, rest API, and proxy. + */ +public interface ClientDelegate { + + QueryHandler executeSQL(String sql) throws TajoException; + + QueryFuture executeSQLAsync(String sql) throws TajoException; + + String currentDB(); + + void selectDB(String db) throws UndefinedDatabaseException; +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java new file mode 100644 index 0000000000..784add0e86 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java @@ -0,0 +1,26 @@ +/** + * 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.client.v2; + +public class ClientDeligateFactory { + + public static ClientDelegate newDefaultDeligate() { + return null; + } +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java new file mode 100644 index 0000000000..f08c6170f8 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java @@ -0,0 +1,247 @@ +/** + * 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.client.v2; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tajo.QueryId; +import org.apache.tajo.annotation.Nullable; +import org.apache.tajo.annotation.ThreadSafe; +import org.apache.tajo.catalog.Schema; +import org.apache.tajo.catalog.TableDesc; +import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.catalog.partition.PartitionMethodDesc; +import org.apache.tajo.client.*; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.ipc.ClientProtos.*; +import org.apache.tajo.jdbc.TajoMemoryResultSet; +import org.apache.tajo.service.ServiceTracker; +import org.apache.tajo.util.KeyValueSet; + +import java.net.InetSocketAddress; +import java.net.URI; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +@ThreadSafe +public class LegacyClientDelegate extends SessionConnection implements ClientDelegate { + + QueryClient queryClient; + CatalogAdminClient catalogClient; + + /** + * Connect to TajoMaster + * + * @param tracker ServiceTracker to discovery Tajo Client RPC + * @param baseDatabase The base database name. It is case sensitive. If it is null, + * the 'default' database will be used. + * @param properties configurations + * @throws java.io.IOException + */ + public LegacyClientDelegate(ServiceTracker tracker, @Nullable String baseDatabase, KeyValueSet properties) + throws SQLException { + + super(tracker, baseDatabase, properties); + + this.queryClient = new QueryClientImpl(this); + this.catalogClient = new CatalogAdminClientImpl(this); + } + + /** + * Connect to TajoMaster + * + * @param addr TajoMaster address + * @param baseDatabase The base database name. It is case sensitive. If it is null, + * the 'default' database will be used. + * @param properties configurations + * @throws java.io.IOException + */ + public LegacyClientDelegate(InetSocketAddress addr, @Nullable String baseDatabase, KeyValueSet properties) + throws SQLException { + this(new DummyServiceTracker(addr), baseDatabase, properties); + } + + public LegacyClientDelegate(ServiceTracker serviceTracker) throws SQLException { + this(serviceTracker, null); + } + + public LegacyClientDelegate(ServiceTracker serviceTracker, @Nullable String baseDatabase) throws SQLException { + this(serviceTracker, baseDatabase, new KeyValueSet()); + } + /*------------------------------------------------------------------------*/ + // QueryClient wrappers + /*------------------------------------------------------------------------*/ + + public void closeQuery(final QueryId queryId) throws SQLException { + queryClient.closeQuery(queryId); + } + + public void closeNonForwardQuery(final QueryId queryId) throws SQLException { + queryClient.closeNonForwardQuery(queryId); + } + + public SubmitQueryResponse executeQuery(final String sql) throws SQLException { + return queryClient.executeQuery(sql); + } + + public SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException { + return queryClient.executeQueryWithJson(json); + } + + public ResultSet executeQueryAndGetResult(final String sql) throws SQLException { + return queryClient.executeQueryAndGetResult(sql); + } + + public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException { + return queryClient.executeJsonQueryAndGetResult(json); + } + + public QueryStatus getQueryStatus(QueryId queryId) throws SQLException { + return queryClient.getQueryStatus(queryId); + } + + public ResultSet getQueryResult(QueryId queryId) throws SQLException { + return queryClient.getQueryResult(queryId); + } + + public ResultSet createNullResultSet(QueryId queryId) throws SQLException { + return TajoClientUtil.createNullResultSet(queryId); + } + + public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException { + return queryClient.getResultResponse(queryId); + } + + public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException { + return queryClient.fetchNextQueryResult(queryId, fetchRowNum); + } + + public boolean updateQuery(final String sql) throws SQLException { + return queryClient.updateQuery(sql); + } + + public boolean updateQueryWithJson(final String json) throws SQLException { + return queryClient.updateQueryWithJson(json); + } + + public QueryStatus killQuery(final QueryId queryId) throws SQLException { + return queryClient.killQuery(queryId); + } + + public List getRunningQueryList() throws SQLException { + return queryClient.getRunningQueryList(); + } + + public List getFinishedQueryList() throws SQLException { + return queryClient.getFinishedQueryList(); + } + + public List getClusterInfo() throws SQLException { + return queryClient.getClusterInfo(); + } + + public QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException { + return queryClient.getQueryInfo(queryId); + } + + public QueryHistoryProto getQueryHistory(final QueryId queryId) throws SQLException { + return queryClient.getQueryHistory(queryId); + } + + public void setMaxRows(int maxRows) { + queryClient.setMaxRows(maxRows); + } + + public int getMaxRows() { + return queryClient.getMaxRows(); + } + + /*------------------------------------------------------------------------*/ + // CatalogClient wrappers + /*------------------------------------------------------------------------*/ + + public boolean createDatabase(final String databaseName) throws SQLException { + return catalogClient.createDatabase(databaseName); + } + + public boolean existDatabase(final String databaseName) throws SQLException { + return catalogClient.existDatabase(databaseName); + } + + public boolean dropDatabase(final String databaseName) throws SQLException { + return catalogClient.dropDatabase(databaseName); + } + + public List getAllDatabaseNames() throws SQLException { + return catalogClient.getAllDatabaseNames(); + } + + public boolean existTable(final String tableName) throws SQLException { + return catalogClient.existTable(tableName); + } + + public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, + final TableMeta meta) throws SQLException { + return catalogClient.createExternalTable(tableName, schema, path, meta); + } + + public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, + final TableMeta meta, final PartitionMethodDesc partitionMethodDesc) + throws SQLException { + return catalogClient.createExternalTable(tableName, schema, path, meta, partitionMethodDesc); + } + + public boolean dropTable(final String tableName) throws SQLException { + return dropTable(tableName, false); + } + + public boolean dropTable(final String tableName, final boolean purge) throws SQLException { + return catalogClient.dropTable(tableName, purge); + } + + public List getTableList(@Nullable final String databaseName) throws SQLException { + return catalogClient.getTableList(databaseName); + } + + public TableDesc getTableDesc(final String tableName) throws SQLException { + return catalogClient.getTableDesc(tableName); + } + + @Override + public QueryHandler executeSQL(String sql) throws TajoException { + return null; + } + + @Override + public QueryFuture executeSQLAsync(String sql) throws TajoException { + return null; + } + + @Override + public String currentDB() { + return getCurrentDatabase(); + } + + @Override + public void selectDB(String db) throws UndefinedDatabaseException { + selectDatabase(db); + } +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java new file mode 100644 index 0000000000..27b6535f4e --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java @@ -0,0 +1,33 @@ +/** + * 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.client.v2; + +import org.apache.tajo.error.Errors.ResultCode; + +import java.sql.ResultSet; + +public interface QueryEventListener { + void onProgress(float progress); + + void onFailed(ResultCode errorCode, String message); + + void onError(ResultCode errorCode, String message); + + void onCompleted(ResultSet set); +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java new file mode 100644 index 0000000000..dd83039a47 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java @@ -0,0 +1,54 @@ +/** + * 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.client.v2; + +import org.apache.tajo.exception.TajoException; + +import java.sql.ResultSet; +import java.util.concurrent.Future; + +public interface QueryFuture extends Future { + /** + * Get a query id + * + * @return query id + */ + String getId(); + + /** + * Get a normalized progress (0 ~ 1.0f) of a query running + * + * @return progress + */ + float progress(); + + /** + * Get a query state + * + * @return query state + */ + QueryState state(); + + /** + * Get the last exception if any error occurs. + * + * @return Exception + */ + TajoException getException(); +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java new file mode 100644 index 0000000000..7331e98e7f --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java @@ -0,0 +1,41 @@ +/** + * 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.client.v2; + +public interface QueryHandler { + String queryid(); + + boolean isOk(); + + boolean isError(); + + boolean isKilled(); + + QueryState state(); + + float progress(); + + void cancel(); + + QueryFuture toFuture(); + + long startTime(); + + long finishTime(); +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java new file mode 100644 index 0000000000..eaeeeab307 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java @@ -0,0 +1,27 @@ +/** + * 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.client.v2; + +public enum QueryState { + SCHEDULED, + RUNNING, + ERROR, + FAILED, + COMPLETED +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java new file mode 100644 index 0000000000..1a3a47c655 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java @@ -0,0 +1,22 @@ +/** + * 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.client.v2; + +public class ServiceDiscovery { +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java new file mode 100644 index 0000000000..c298b526e0 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java @@ -0,0 +1,139 @@ +/** + * 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.client.v2; + +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.exception.TajoRuntimeException; + +import java.sql.ResultSet; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class TajoClient { + private final ClientDelegate delegate; + + /** + * Initialize TajoClient with a hostname and default port 26002. + * + * @param host hostname to connect + */ + public TajoClient(String host) { + delegate = ClientDeligateFactory.newDefaultDeligate(); + } + + /** + * Initialize TajoClient with a hostname and default port 26002. + * + * @param host Hostname to connect + * @param properties Connection properties + */ + public TajoClient(String host, Map properties) { + delegate = ClientDeligateFactory.newDefaultDeligate(); + } + + /** + * Initialize TajoClient with a hostname and port + * + * @param host Hostname to connect + * @param port Port number to connect + */ + public TajoClient(String host, int port) { + delegate = ClientDeligateFactory.newDefaultDeligate(); + } + + /** + * Initialize TajoClient with a hostname and port + * + * @param host Hostname to connect + * @param port Port number to connect + * @param properties Connection properties + */ + public TajoClient(String host, int port, Map properties) { + delegate = ClientDeligateFactory.newDefaultDeligate(); + } + + /** + * Initialize TajoClient via service discovery protocol + * + * @param discovery Service discovery + */ + public TajoClient(ServiceDiscovery discovery) { + delegate = ClientDeligateFactory.newDefaultDeligate(); + } + + /** + * Initialize TajoClient via service discovery protocol + * + * @param discovery Service discovery + * @param properties Connection properties + */ + public TajoClient(ServiceDiscovery discovery, Map properties) { + delegate = ClientDeligateFactory.newDefaultDeligate(); + } + + /** + * + * @param sql + * @return + */ + public QueryHandler executeSQL(String sql) throws TajoException { + return delegate.executeSQL(sql); + } + + public ResultSet waitForComplete(QueryHandler handler) throws TajoException { + try { + return handler.toFuture().get(); + } catch (TajoRuntimeException e) { + throw new TajoException(e); + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + + public ResultSet waitForComplete(QueryHandler handler, long duration, TimeUnit unit) throws TimeoutException { + try { + return handler.toFuture().get(duration, unit); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + + public ResultSet executeSQLAndWaitForComplete(String sql) throws TajoException { + try { + return waitForComplete(executeSQL(sql)); + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + + public QueryFuture executeSQLAsync(String sql) throws TajoException { + return null; + } + + public void selectDB(String database) throws UndefinedDatabaseException { + delegate.selectDB(database); + } + + public String currentDB() { + return delegate.currentDB(); + } +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java new file mode 100644 index 0000000000..a7fb08ae90 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.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.client.v2.exception; + +import org.apache.tajo.error.Errors; +import org.apache.tajo.exception.TajoRuntimeException; + +public class ClientConnectionException extends TajoRuntimeException { + public ClientConnectionException(Throwable t) { + super(Errors.ResultCode.CLIENT_CONNECTION_EXCEPTION, t.getMessage()); + } +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java new file mode 100644 index 0000000000..e567d7d586 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.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.client.v2.exception; + +import org.apache.tajo.error.Errors; +import org.apache.tajo.exception.TajoException; + +public class ClientUnableToConnectException extends TajoException { + public ClientUnableToConnectException() { + super(Errors.ResultCode.CLIENT_UNABLE_TO_ESTABLISH_CONNECTION); + } +} diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java index 088fb9103a..d84f53db2e 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java @@ -91,6 +91,9 @@ public class ErrorMessages { ADD_MESSAGE(MDC_NO_MATCHED_DATATYPE, "no matched type for %s", 1); ADD_MESSAGE(UNKNOWN_DATAFORMAT, "Unknown data format: '%s'", 1); + + ADD_MESSAGE(CLIENT_CONNECTION_EXCEPTION, "Client connection to '%s' has error: %s", 2); + ADD_MESSAGE(CLIENT_UNABLE_TO_ESTABLISH_CONNECTION, "Client is unable to establish connection to '%s'", 1); } private static void ADD_MESSAGE(ResultCode code, String msgFormat) { diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java b/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java index 862889eb04..90f785fe52 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java @@ -43,10 +43,11 @@ public class ReturnStateUtil { OK = builder.build(); } - public static void ensureOk(ReturnState state) { + public static boolean ensureOk(ReturnState state) { if (isError(state)) { throw new TajoRuntimeException(state); } + return true; } public static StringListResponse returnStringList(Collection values) { diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java index 781d1a06e6..4c411f2b01 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java @@ -27,6 +27,11 @@ public class TajoException extends Exception implements TajoExceptionInterface { private ResultCode code; + public TajoException(TajoRuntimeException e) { + super(e.getMessage()); + this.code = e.getErrorCode(); + } + public TajoException(ResultCode code) { super(ErrorMessages.getMessage(code)); this.code = code; diff --git a/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java b/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java index 54c65bf179..5aedffb17e 100644 --- a/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java +++ b/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java @@ -18,8 +18,11 @@ package org.apache.tajo.session; -public class InvalidSessionException extends Exception { +import org.apache.tajo.error.Errors; +import org.apache.tajo.exception.TajoRuntimeException; + +public class InvalidSessionException extends TajoRuntimeException { public InvalidSessionException(String sessionId) { - super("Invalid session id \"" + sessionId + "\""); + super(Errors.ResultCode.INVALID_SESSION, sessionId); } } From 3223dc68433822e16a5f1624f4474b543afacb58 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Tue, 28 Jul 2015 16:39:28 +0900 Subject: [PATCH 2/8] Complete initial version for client API v2. --- .../org/apache/tajo/cli/tools/TajoAdmin.java | 4 +- .../org/apache/tajo/client/QueryClient.java | 8 +- .../apache/tajo/client/QueryClientImpl.java | 42 +- .../apache/tajo/client/SessionConnection.java | 2 +- .../apache/tajo/client/TajoClientImpl.java | 8 +- .../apache/tajo/client/TajoClientUtil.java | 2 +- .../apache/tajo/client/v2/ClientDelegate.java | 7 +- .../tajo/client/v2/ClientDeligateFactory.java | 20 +- .../v2/{QueryHandler.java => ClientUtil.java} | 25 +- .../tajo/client/v2/LegacyClientDelegate.java | 592 ++++++++++++------ .../tajo/client/v2/QueryEventListener.java | 33 - .../apache/tajo/client/v2/QueryFuture.java | 75 ++- .../org/apache/tajo/client/v2/QueryState.java | 9 + .../tajo/client/v2/ServiceDiscovery.java | 5 +- .../org/apache/tajo/client/v2/TajoClient.java | 94 +-- .../apache/tajo/exception/TajoException.java | 6 + tajo-core/pom.xml | 4 +- .../apache/tajo/client/TestTajoClient.java | 8 +- .../org/apache/tajo/jdbc/TajoStatement.java | 1 - 19 files changed, 622 insertions(+), 323 deletions(-) rename tajo-client/src/main/java/org/apache/tajo/client/v2/{QueryHandler.java => ClientUtil.java} (75%) delete mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java index 77a70004a1..72f7f7a70a 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java @@ -416,8 +416,8 @@ public void processKill(Writer writer, String queryIdStr) } else { writer.write("ERROR:" + status.getErrorMessage()); } - } catch (SQLException e) { - writer.write("ERROR:" + e.getMessage()); + } catch (Throwable t) { + writer.write("ERROR:" + t.getMessage()); } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java index ffe3d960ad..7789d626db 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java @@ -82,7 +82,7 @@ public interface QueryClient extends Closeable { * The response only contains a query id, and submission status. * In order to get the result, you should use {@link #getQueryResult(org.apache.tajo.QueryId)}. */ - SubmitQueryResponse executeQuery(final String sql) throws SQLException; + SubmitQueryResponse executeQuery(final String sql); SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException; @@ -98,7 +98,7 @@ public interface QueryClient extends Closeable { ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException; - QueryStatus getQueryStatus(QueryId queryId) throws SQLException; + QueryStatus getQueryStatus(QueryId queryId); ResultSet getQueryResult(QueryId queryId) throws SQLException; @@ -108,7 +108,7 @@ public interface QueryClient extends Closeable { TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException; - boolean updateQuery(final String sql) throws SQLException; + boolean updateQuery(final String sql); boolean updateQueryWithJson(final String json) throws SQLException; @@ -118,7 +118,7 @@ public interface QueryClient extends Closeable { List getClusterInfo() throws SQLException; - QueryStatus killQuery(final QueryId queryId) throws SQLException; + QueryStatus killQuery(final QueryId queryId); QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java index aeca72b8e5..747cc188b0 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java @@ -45,6 +45,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import static org.apache.tajo.exception.ReturnStateUtil.ensureOk; import static org.apache.tajo.exception.ReturnStateUtil.isSuccess; import static org.apache.tajo.exception.ReturnStateUtil.returnError; import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError; @@ -144,7 +145,7 @@ public Map getAllSessionVariables() throws SQLException { } @Override - public ClientProtos.SubmitQueryResponse executeQuery(final String sql) throws SQLException { + public ClientProtos.SubmitQueryResponse executeQuery(final String sql) { final BlockingInterface stub = conn.getTMStub(); final QueryRequest request = buildQueryRequest(sql, false); @@ -211,7 +212,7 @@ public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLExcep } } - private ResultSet getQueryResultAndWait(QueryId queryId) throws SQLException { + public ResultSet getQueryResultAndWait(QueryId queryId) { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); @@ -234,8 +235,27 @@ private ResultSet getQueryResultAndWait(QueryId queryId) throws SQLException { } } + public GetQueryStatusResponse getRawQueryStatus(QueryId queryId) { + + final BlockingInterface stub = conn.getTMStub(); + final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder() + .setSessionId(conn.sessionId) + .setQueryId(queryId.getProto()) + .build(); + + GetQueryStatusResponse res; + try { + res = stub.getQueryStatus(null, request); + } catch (ServiceException t) { + throw new RuntimeException(t); + } + + ensureOk(res.getState()); + return res; + } + @Override - public QueryStatus getQueryStatus(QueryId queryId) throws SQLException { + public QueryStatus getQueryStatus(QueryId queryId) { final BlockingInterface stub = conn.getTMStub(); final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder() @@ -250,19 +270,19 @@ public QueryStatus getQueryStatus(QueryId queryId) throws SQLException { throw new RuntimeException(t); } - throwIfError(res.getState()); + ensureOk(res.getState()); return new QueryStatus(res); } @Override - public ResultSet getQueryResult(QueryId queryId) throws SQLException { + public ResultSet getQueryResult(QueryId queryId) { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); } GetQueryResultResponse response = getResultResponse(queryId); - throwIfError(response.getState()); + ensureOk(response.getState()); TableDesc tableDesc = CatalogUtil.newTableDesc(response.getTableDesc()); return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows); } @@ -273,7 +293,7 @@ public ResultSet createNullResultSet(QueryId queryId) { } @Override - public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException { + public GetQueryResultResponse getResultResponse(QueryId queryId) { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return null; } @@ -291,7 +311,7 @@ public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLExcep throw new RuntimeException(t); } - throwIfError(response.getState()); + ensureOk(response.getState()); return response; } @@ -324,7 +344,7 @@ public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int } @Override - public boolean updateQuery(final String sql) throws SQLException { + public boolean updateQuery(final String sql) { final BlockingInterface stub = conn.getTMStub(); final QueryRequest request = buildQueryRequest(sql, false); @@ -336,7 +356,7 @@ public boolean updateQuery(final String sql) throws SQLException { throw new RuntimeException(e); } - throwIfError(response.getState()); + ensureOk(response.getState()); conn.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); return true; @@ -411,7 +431,7 @@ public List getClusterInfo() throws SQLExceptio } @Override - public QueryStatus killQuery(final QueryId queryId) throws SQLException { + public QueryStatus killQuery(final QueryId queryId) { final BlockingInterface stub = conn.getTMStub(); QueryStatus status = getQueryStatus(queryId); diff --git a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java index fe017a2a6e..59564f4ab7 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java @@ -100,7 +100,7 @@ public class SessionConnection implements Closeable { * @throws SQLException */ public SessionConnection(@NotNull ServiceTracker tracker, @Nullable String baseDatabase, - @NotNull KeyValueSet properties) throws SQLException { + @NotNull KeyValueSet properties) { this.serviceTracker = tracker; this.baseDatabase = baseDatabase; this.properties = properties; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java index c81fafcafd..5acb3eb549 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java @@ -97,7 +97,7 @@ public void closeNonForwardQuery(final QueryId queryId) throws SQLException { queryClient.closeNonForwardQuery(queryId); } - public SubmitQueryResponse executeQuery(final String sql) throws SQLException { + public SubmitQueryResponse executeQuery(final String sql) { return queryClient.executeQuery(sql); } @@ -113,7 +113,7 @@ public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLExcep return queryClient.executeJsonQueryAndGetResult(json); } - public QueryStatus getQueryStatus(QueryId queryId) throws SQLException { + public QueryStatus getQueryStatus(QueryId queryId) { return queryClient.getQueryStatus(queryId); } @@ -133,7 +133,7 @@ public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int return queryClient.fetchNextQueryResult(queryId, fetchRowNum); } - public boolean updateQuery(final String sql) throws SQLException { + public boolean updateQuery(final String sql) { return queryClient.updateQuery(sql); } @@ -141,7 +141,7 @@ public boolean updateQueryWithJson(final String json) throws SQLException { return queryClient.updateQueryWithJson(json); } - public QueryStatus killQuery(final QueryId queryId) throws SQLException { + public QueryStatus killQuery(final QueryId queryId) { return queryClient.killQuery(queryId); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java index 358f1a029c..c79b756ecb 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java @@ -58,7 +58,7 @@ public static boolean isQueryComplete(TajoProtos.QueryState state) { return !isQueryWaitingForSchedule(state) && !isQueryRunning(state); } - public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) throws SQLException { + public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) { QueryStatus status = client.getQueryStatus(queryId); while(!isQueryComplete(status.getState())) { diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java index bdf10c31f1..8dce7c4fe5 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java @@ -21,14 +21,17 @@ import org.apache.tajo.catalog.exception.UndefinedDatabaseException; import org.apache.tajo.exception.TajoException; +import java.io.Closeable; import java.sql.ResultSet; /** * ClientDelegate is a delegate for various wired protocols like protocol buffer, rest API, and proxy. */ -public interface ClientDelegate { +public interface ClientDelegate extends Closeable { - QueryHandler executeSQL(String sql) throws TajoException; + int executeUpdate(String sql) throws TajoException; + + ResultSet executeSQL(String sql) throws TajoException; QueryFuture executeSQLAsync(String sql) throws TajoException; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java index 784add0e86..656c2e33ce 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java @@ -18,9 +18,25 @@ package org.apache.tajo.client.v2; +import org.apache.tajo.annotation.Nullable; +import org.apache.tajo.client.v2.exception.ClientUnableToConnectException; + +import java.util.Map; + public class ClientDeligateFactory { - public static ClientDelegate newDefaultDeligate() { - return null; + public static ClientDelegate newDefaultDeligate(String host, + int port, + @Nullable Map props) + throws ClientUnableToConnectException { + + return new LegacyClientDelegate(host, port, props); + } + + public static ClientDelegate newDefaultDeligate(ServiceDiscovery discovery, + @Nullable Map props) + throws ClientUnableToConnectException { + + return new LegacyClientDelegate(discovery, props); } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java similarity index 75% rename from tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java rename to tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java index 7331e98e7f..b6a00e2a4b 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryHandler.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java @@ -18,24 +18,13 @@ package org.apache.tajo.client.v2; -public interface QueryHandler { - String queryid(); +public class ClientUtil { - boolean isOk(); + public static boolean isOk(QueryState state) { + return !(state == QueryState.ERROR || state == QueryState.FAILED); + } - boolean isError(); - - boolean isKilled(); - - QueryState state(); - - float progress(); - - void cancel(); - - QueryFuture toFuture(); - - long startTime(); - - long finishTime(); + public static boolean isFailed(QueryState state) { + return state == QueryState.ERROR || state == QueryState.FAILED; + } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java index f08c6170f8..12e4613b42 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java @@ -18,221 +18,88 @@ package org.apache.tajo.client.v2; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.AbstractFuture; import org.apache.tajo.QueryId; -import org.apache.tajo.annotation.Nullable; +import org.apache.tajo.TajoProtos; import org.apache.tajo.annotation.ThreadSafe; -import org.apache.tajo.catalog.Schema; -import org.apache.tajo.catalog.TableDesc; -import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.auth.UserRoleInfo; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; -import org.apache.tajo.catalog.partition.PartitionMethodDesc; -import org.apache.tajo.client.*; +import org.apache.tajo.client.DummyServiceTracker; +import org.apache.tajo.client.QueryClientImpl; +import org.apache.tajo.client.SessionConnection; +import org.apache.tajo.client.TajoClientUtil; +import org.apache.tajo.conf.TajoConf; import org.apache.tajo.exception.TajoException; -import org.apache.tajo.ipc.ClientProtos.*; -import org.apache.tajo.jdbc.TajoMemoryResultSet; +import org.apache.tajo.exception.UnimplementedException; +import org.apache.tajo.ipc.ClientProtos; +import org.apache.tajo.ipc.ClientProtos.GetQueryStatusResponse; import org.apache.tajo.service.ServiceTracker; +import org.apache.tajo.service.ServiceTrackerException; +import org.apache.tajo.service.TajoMasterInfo; import org.apache.tajo.util.KeyValueSet; +import org.apache.tajo.util.NetUtils; +import java.io.IOException; import java.net.InetSocketAddress; -import java.net.URI; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static org.apache.tajo.exception.ReturnStateUtil.ensureOk; @ThreadSafe public class LegacyClientDelegate extends SessionConnection implements ClientDelegate { - QueryClient queryClient; - CatalogAdminClient catalogClient; - - /** - * Connect to TajoMaster - * - * @param tracker ServiceTracker to discovery Tajo Client RPC - * @param baseDatabase The base database name. It is case sensitive. If it is null, - * the 'default' database will be used. - * @param properties configurations - * @throws java.io.IOException - */ - public LegacyClientDelegate(ServiceTracker tracker, @Nullable String baseDatabase, KeyValueSet properties) - throws SQLException { - - super(tracker, baseDatabase, properties); - - this.queryClient = new QueryClientImpl(this); - this.catalogClient = new CatalogAdminClientImpl(this); - } - - /** - * Connect to TajoMaster - * - * @param addr TajoMaster address - * @param baseDatabase The base database name. It is case sensitive. If it is null, - * the 'default' database will be used. - * @param properties configurations - * @throws java.io.IOException - */ - public LegacyClientDelegate(InetSocketAddress addr, @Nullable String baseDatabase, KeyValueSet properties) - throws SQLException { - this(new DummyServiceTracker(addr), baseDatabase, properties); - } - - public LegacyClientDelegate(ServiceTracker serviceTracker) throws SQLException { - this(serviceTracker, null); - } - - public LegacyClientDelegate(ServiceTracker serviceTracker, @Nullable String baseDatabase) throws SQLException { - this(serviceTracker, baseDatabase, new KeyValueSet()); - } - /*------------------------------------------------------------------------*/ - // QueryClient wrappers - /*------------------------------------------------------------------------*/ - - public void closeQuery(final QueryId queryId) throws SQLException { - queryClient.closeQuery(queryId); - } - - public void closeNonForwardQuery(final QueryId queryId) throws SQLException { - queryClient.closeNonForwardQuery(queryId); - } - - public SubmitQueryResponse executeQuery(final String sql) throws SQLException { - return queryClient.executeQuery(sql); - } - - public SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException { - return queryClient.executeQueryWithJson(json); - } - - public ResultSet executeQueryAndGetResult(final String sql) throws SQLException { - return queryClient.executeQueryAndGetResult(sql); - } - - public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException { - return queryClient.executeJsonQueryAndGetResult(json); - } - - public QueryStatus getQueryStatus(QueryId queryId) throws SQLException { - return queryClient.getQueryStatus(queryId); - } - - public ResultSet getQueryResult(QueryId queryId) throws SQLException { - return queryClient.getQueryResult(queryId); - } - - public ResultSet createNullResultSet(QueryId queryId) throws SQLException { - return TajoClientUtil.createNullResultSet(queryId); - } - - public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException { - return queryClient.getResultResponse(queryId); - } - - public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException { - return queryClient.fetchNextQueryResult(queryId, fetchRowNum); - } - - public boolean updateQuery(final String sql) throws SQLException { - return queryClient.updateQuery(sql); - } - - public boolean updateQueryWithJson(final String json) throws SQLException { - return queryClient.updateQueryWithJson(json); - } - - public QueryStatus killQuery(final QueryId queryId) throws SQLException { - return queryClient.killQuery(queryId); - } + private QueryClientImpl queryClient; + private ExecutorService executor = Executors.newFixedThreadPool(8); - public List getRunningQueryList() throws SQLException { - return queryClient.getRunningQueryList(); + public LegacyClientDelegate(String host, int port, Map props) { + super(new DummyServiceTracker(NetUtils.createSocketAddr(host, port)), null, new KeyValueSet(props)); + queryClient = new QueryClientImpl(this); } - public List getFinishedQueryList() throws SQLException { - return queryClient.getFinishedQueryList(); + public LegacyClientDelegate(ServiceDiscovery discovery, Map props) { + super(new DelegateServiceTracker(discovery), null, new KeyValueSet(props)); + queryClient = new QueryClientImpl(this); } - public List getClusterInfo() throws SQLException { - return queryClient.getClusterInfo(); - } - - public QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException { - return queryClient.getQueryInfo(queryId); - } - - public QueryHistoryProto getQueryHistory(final QueryId queryId) throws SQLException { - return queryClient.getQueryHistory(queryId); - } - - public void setMaxRows(int maxRows) { - queryClient.setMaxRows(maxRows); - } - - public int getMaxRows() { - return queryClient.getMaxRows(); - } - - /*------------------------------------------------------------------------*/ - // CatalogClient wrappers - /*------------------------------------------------------------------------*/ - - public boolean createDatabase(final String databaseName) throws SQLException { - return catalogClient.createDatabase(databaseName); - } - - public boolean existDatabase(final String databaseName) throws SQLException { - return catalogClient.existDatabase(databaseName); - } - - public boolean dropDatabase(final String databaseName) throws SQLException { - return catalogClient.dropDatabase(databaseName); - } - - public List getAllDatabaseNames() throws SQLException { - return catalogClient.getAllDatabaseNames(); - } - - public boolean existTable(final String tableName) throws SQLException { - return catalogClient.existTable(tableName); - } - - public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, - final TableMeta meta) throws SQLException { - return catalogClient.createExternalTable(tableName, schema, path, meta); - } - - public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, - final TableMeta meta, final PartitionMethodDesc partitionMethodDesc) - throws SQLException { - return catalogClient.createExternalTable(tableName, schema, path, meta, partitionMethodDesc); - } - - public boolean dropTable(final String tableName) throws SQLException { - return dropTable(tableName, false); - } - - public boolean dropTable(final String tableName, final boolean purge) throws SQLException { - return catalogClient.dropTable(tableName, purge); - } - - public List getTableList(@Nullable final String databaseName) throws SQLException { - return catalogClient.getTableList(databaseName); - } - - public TableDesc getTableDesc(final String tableName) throws SQLException { - return catalogClient.getTableDesc(tableName); + @Override + public int executeUpdate(String sql) throws TajoException { + queryClient.updateQuery(sql); + return 0; } @Override - public QueryHandler executeSQL(String sql) throws TajoException { - return null; + public ResultSet executeSQL(String sql) throws TajoException { + try { + return executeSQLAsync(sql).get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } } @Override public QueryFuture executeSQLAsync(String sql) throws TajoException { - return null; + ClientProtos.SubmitQueryResponse response = queryClient.executeQuery(sql); + ensureOk(response.getState()); + + QueryId queryId = new QueryId(response.getQueryId()); + + switch (response.getResultType()) { + case ENCLOSED: + return new QueryFutureForEnclosed(queryId, TajoClientUtil.createResultSet(this.queryClient, response, 200)); + case FETCH: + AsyncQueryFuture future = new AsyncQueryFuture(queryId); + executor.execute(future); + return future; + default: + return new QueryFutureForNoFetch(queryId); + } } @Override @@ -244,4 +111,351 @@ public String currentDB() { public void selectDB(String db) throws UndefinedDatabaseException { selectDatabase(db); } + + private class QueryFutureForNoFetch implements QueryFuture { + private final QueryId id; + private final long now = System.currentTimeMillis(); + + QueryFutureForNoFetch(QueryId id) { + this.id = id; + } + + @Override + public String id() { + return id.toString(); + } + + @Override + public String queue() { + return "default"; + } + + @Override + public QueryState state() { + return QueryState.COMPLETED; + } + + @Override + public float progress() { + return 1.0f; + } + + @Override + public boolean isOk() { + return true; + } + + @Override + public boolean isCompleted() { + return true; + } + + @Override + public boolean isFailed() { + return false; + } + + @Override + public boolean isKilled() { + return false; + } + + @Override + public UserRoleInfo user() { + return UserRoleInfo.getCurrentUser(); + } + + @Override + public void kill() { + } + + @Override + public long submitTime() { + return 0; + } + + @Override + public long startTime() { + return now; + } + + @Override + public long finishTime() { + return now; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public ResultSet get() { + return TajoClientUtil.NULL_RESULT_SET; + } + + @Override + public ResultSet get(long timeout, TimeUnit unit) { + return TajoClientUtil.NULL_RESULT_SET; + } + } + + private class QueryFutureForEnclosed extends QueryFutureForNoFetch { + private final ResultSet resultSet; + QueryFutureForEnclosed(QueryId id, ResultSet resultSet) { + super(id); + this.resultSet = resultSet; + } + + @Override + public ResultSet get() { + return resultSet; + } + + @Override + public ResultSet get(long timeout, TimeUnit unit) { + return resultSet; + } + } + + private class AsyncQueryFuture extends AbstractFuture implements QueryFuture, Runnable { + private final QueryId queryId; + private volatile QueryState lastState; + private volatile float progress; + private final long submitTime = System.currentTimeMillis(); + private volatile long startTime = 0; + private volatile long finishTime = 0; + + public AsyncQueryFuture(QueryId queryId) { + this.queryId = queryId; + } + + @Override + public String id() { + return queryId.toString(); + } + + @Override + public boolean isOk() { + return ClientUtil.isOk(lastState); + } + + @Override + public boolean isCompleted() { + return lastState == QueryState.COMPLETED; + } + + @Override + public boolean isFailed() { + return ClientUtil.isFailed(lastState); + } + + @Override + public boolean isKilled() { + return queryClient.getQueryStatus(queryId).getState() == TajoProtos.QueryState.QUERY_KILLED; + } + + @Override + public QueryState state() { + return lastState; + } + + @Override + public String queue() { + return "default"; + } + + @Override + public UserRoleInfo user() { + return UserRoleInfo.getCurrentUser(); + } + + @Override + public float progress() { + return progress; + } + + @Override + public void kill() { + queryClient.killQuery(queryId).getState(); + } + + @Override + public long submitTime() { + return submitTime; + } + + @Override + public long startTime() { + return startTime; + } + + @Override + public long finishTime() { + return finishTime; + } + + private void updateState(GetQueryStatusResponse lastState) { + this.startTime = lastState.getSubmitTime(); + this.finishTime = lastState.getFinishTime(); + this.progress = lastState.getProgress(); + this.lastState = convert(lastState.getQueryState()); + } + + GetQueryStatusResponse waitCompletion() { + GetQueryStatusResponse response = queryClient.getRawQueryStatus(queryId); + ensureOk(response.getState()); + updateState(response); + + while(!TajoClientUtil.isQueryComplete(response.getQueryState())) { + try { + Thread.sleep(500); + updateState(response); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + response = queryClient.getRawQueryStatus(queryId); + ensureOk(response.getState()); + } + return response; + } + + @Override + public void run() { + GetQueryStatusResponse finalResponse; + try { + finalResponse = waitCompletion(); + } catch (Throwable t) { + setException(t); + return; + } + + if (finalResponse.getQueryState() == TajoProtos.QueryState.QUERY_SUCCEEDED) { + if (finalResponse.hasHasResult()) { + set(queryClient.getQueryResult(queryId)); + } else { // when update + set(TajoClientUtil.NULL_RESULT_SET); + } + } else { + cancel(false); // failed + set(TajoClientUtil.NULL_RESULT_SET); + } + } + } + + private static class DelegateServiceTracker implements ServiceTracker { + + private final ServiceDiscovery discovery; + DelegateServiceTracker(ServiceDiscovery discovery) { + this.discovery = discovery; + } + + @Override + public boolean isHighAvailable() { + return false; + } + + @Override + public InetSocketAddress getUmbilicalAddress() throws ServiceTrackerException { + return null; + } + + @Override + public InetSocketAddress getClientServiceAddress() throws ServiceTrackerException { + return discovery.clientAddress(); + } + + @Override + public InetSocketAddress getResourceTrackerAddress() throws ServiceTrackerException { + throw new UnimplementedException(); + } + + @Override + public InetSocketAddress getCatalogAddress() throws ServiceTrackerException { + throw new UnimplementedException(); + } + + @Override + public InetSocketAddress getMasterHttpInfo() throws ServiceTrackerException { + throw new UnimplementedException(); + } + + @Override + public int getState(String masterName, TajoConf conf) throws ServiceTrackerException { + throw new UnimplementedException(); + } + + @Override + public int formatHA(TajoConf conf) throws ServiceTrackerException { + throw new UnimplementedException(); + } + + @Override + public List getMasters(TajoConf conf) throws ServiceTrackerException { + throw new UnimplementedException(); + } + + @Override + public void register() throws IOException { + throw new UnimplementedException(); + } + + @Override + public void delete() throws IOException { + throw new UnimplementedException(); + } + + @Override + public boolean isActiveMaster() { + throw new UnimplementedException(); + } + + @Override + public List getMasters() throws IOException { + throw new UnimplementedException(); + } + } + + public static QueryState convert(TajoProtos.QueryState state) { + switch (state) { + case QUERY_NEW: + case QUERY_INIT: + case QUERY_NOT_ASSIGNED: + return QueryState.SCHEDULED; + + case QUERY_MASTER_INIT: + case QUERY_MASTER_LAUNCHED: + case QUERY_RUNNING: + return QueryState.RUNNING; + + case QUERY_KILL_WAIT: + return QueryState.KILLING; + + case QUERY_KILLED: + return QueryState.KILLED; + + case QUERY_FAILED: + return QueryState.FAILED; + + case QUERY_ERROR: + return QueryState.ERROR; + + case QUERY_SUCCEEDED: + return QueryState.COMPLETED; + + default: + throw new RuntimeException("Unknown state:" + state.name()); + } + } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java deleted file mode 100644 index 27b6535f4e..0000000000 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryEventListener.java +++ /dev/null @@ -1,33 +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.client.v2; - -import org.apache.tajo.error.Errors.ResultCode; - -import java.sql.ResultSet; - -public interface QueryEventListener { - void onProgress(float progress); - - void onFailed(ResultCode errorCode, String message); - - void onError(ResultCode errorCode, String message); - - void onCompleted(ResultSet set); -} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java index dd83039a47..016d8a7c0d 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java @@ -18,6 +18,8 @@ package org.apache.tajo.client.v2; +import com.google.common.base.Optional; +import org.apache.tajo.auth.UserRoleInfo; import org.apache.tajo.exception.TajoException; import java.sql.ResultSet; @@ -29,7 +31,16 @@ public interface QueryFuture extends Future { * * @return query id */ - String getId(); + String id(); + + String queue(); + + /** + * Get a query state + * + * @return query state + */ + QueryState state(); /** * Get a normalized progress (0 ~ 1.0f) of a query running @@ -39,16 +50,66 @@ public interface QueryFuture extends Future { float progress(); /** - * Get a query state + * A submitted or running query state is normal * - * @return query state + * @return True if a query state is normal */ - QueryState state(); + boolean isOk(); + + /** + * Get whether the query is successfully completed or not. + * + * @return True if the query is successfully completed. + */ + boolean isCompleted(); + + /** + * Get whether the query is abort due to error. + * + * @return True if the query is abort due to error. + */ + boolean isFailed(); + + /** + * Get whether the query is killed. This is equivalent to + * @{link Future#cancel}. + * + * @return True if the query is already killed. + */ + boolean isKilled(); + + /** + * Get an user information + * + * @return UserRoleInfo + */ + UserRoleInfo user(); + + /** + * Kill this query + */ + void kill(); + + /** + * Get the time when a query is submitted. + * This time can be different from @{link QueryFuture#startTime} + * due to scheduling delay. + * + * @return Millisecond since epoch + */ + long submitTime(); + + /** + * Get the time when a query is actually launched. + * + * @return Millisecond since epoch + */ + long startTime(); /** - * Get the last exception if any error occurs. + * Get the time when a query is finished. * - * @return Exception + * @return Millisecond since epoch */ - TajoException getException(); + long finishTime(); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java index eaeeeab307..24ea386593 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java @@ -19,9 +19,18 @@ package org.apache.tajo.client.v2; public enum QueryState { + /** successfully submitted */ SCHEDULED, + /** Running */ RUNNING, + /** Error before a query execution */ ERROR, + /** Failure after a query launches */ FAILED, + /** Killed */ + KILLED, + /** Wait for completely kill */ + KILLING, + /** Successfully completed */ COMPLETED } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java index 1a3a47c655..1a87808135 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java @@ -18,5 +18,8 @@ package org.apache.tajo.client.v2; -public class ServiceDiscovery { +import java.net.InetSocketAddress; + +public interface ServiceDiscovery { + InetSocketAddress clientAddress(); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java index c298b526e0..dcd3b4e91f 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java @@ -19,16 +19,25 @@ package org.apache.tajo.client.v2; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.client.v2.exception.ClientUnableToConnectException; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoRuntimeException; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; +import java.io.Closeable; import java.sql.ResultSet; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -public class TajoClient { +public class TajoClient implements Closeable { + /** + * default client port number + */ + public static final int DEFAULT_PORT = 26002; + private final ClientDelegate delegate; /** @@ -36,8 +45,8 @@ public class TajoClient { * * @param host hostname to connect */ - public TajoClient(String host) { - delegate = ClientDeligateFactory.newDefaultDeligate(); + public TajoClient(String host) throws ClientUnableToConnectException { + delegate = ClientDeligateFactory.newDefaultDeligate(host, DEFAULT_PORT, null); } /** @@ -46,8 +55,8 @@ public TajoClient(String host) { * @param host Hostname to connect * @param properties Connection properties */ - public TajoClient(String host, Map properties) { - delegate = ClientDeligateFactory.newDefaultDeligate(); + public TajoClient(String host, Map properties) throws ClientUnableToConnectException { + delegate = ClientDeligateFactory.newDefaultDeligate(host, DEFAULT_PORT, properties); } /** @@ -56,8 +65,8 @@ public TajoClient(String host, Map properties) { * @param host Hostname to connect * @param port Port number to connect */ - public TajoClient(String host, int port) { - delegate = ClientDeligateFactory.newDefaultDeligate(); + public TajoClient(String host, int port) throws ClientUnableToConnectException { + delegate = ClientDeligateFactory.newDefaultDeligate(host, port, null); } /** @@ -67,8 +76,8 @@ public TajoClient(String host, int port) { * @param port Port number to connect * @param properties Connection properties */ - public TajoClient(String host, int port, Map properties) { - delegate = ClientDeligateFactory.newDefaultDeligate(); + public TajoClient(String host, int port, Map properties) throws ClientUnableToConnectException { + delegate = ClientDeligateFactory.newDefaultDeligate(host, port, properties); } /** @@ -76,8 +85,8 @@ public TajoClient(String host, int port, Map properties) { * * @param discovery Service discovery */ - public TajoClient(ServiceDiscovery discovery) { - delegate = ClientDeligateFactory.newDefaultDeligate(); + public TajoClient(ServiceDiscovery discovery) throws ClientUnableToConnectException { + delegate = ClientDeligateFactory.newDefaultDeligate(discovery, null); } /** @@ -86,53 +95,54 @@ public TajoClient(ServiceDiscovery discovery) { * @param discovery Service discovery * @param properties Connection properties */ - public TajoClient(ServiceDiscovery discovery, Map properties) { - delegate = ClientDeligateFactory.newDefaultDeligate(); + public TajoClient(ServiceDiscovery discovery, Map properties) throws ClientUnableToConnectException { + delegate = ClientDeligateFactory.newDefaultDeligate(discovery, properties); + } + + public int executeUpdate(String sql) throws TajoException { + return delegate.executeUpdate(sql); } /** + * Submit a SQL query statement * - * @param sql - * @return + * @param sql a SQL statement + * @return QueryHandler + * @throws TajoException */ - public QueryHandler executeSQL(String sql) throws TajoException { + public ResultSet executeQuery(String sql) throws TajoException { return delegate.executeSQL(sql); } - public ResultSet waitForComplete(QueryHandler handler) throws TajoException { - try { - return handler.toFuture().get(); - } catch (TajoRuntimeException e) { - throw new TajoException(e); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } - - public ResultSet waitForComplete(QueryHandler handler, long duration, TimeUnit unit) throws TimeoutException { - try { - return handler.toFuture().get(duration, unit); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - } - - public ResultSet executeSQLAndWaitForComplete(String sql) throws TajoException { - try { - return waitForComplete(executeSQL(sql)); - } catch (Throwable t) { - throw new RuntimeException(t); - } + /** + * Execute a SQL statement through asynchronous API + * + * @param sql + * @return + * @throws TajoException + */ + public QueryFuture executeSQLAsync(String sql) throws TajoException { + return delegate.executeSQLAsync(sql); } - public QueryFuture executeSQLAsync(String sql) throws TajoException { - return null; + public void close() { } + /** + * Select working database + * + * @param database Database name + * @throws UndefinedDatabaseException + */ public void selectDB(String database) throws UndefinedDatabaseException { delegate.selectDB(database); } + /** + * Get the current working database + * + * @return Current working database + */ public String currentDB() { return delegate.currentDB(); } diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java index 4c411f2b01..e0e2ccb7df 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java @@ -19,6 +19,7 @@ package org.apache.tajo.exception; import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; /** * TajoException contains all exceptions with any exact reason. @@ -27,6 +28,11 @@ public class TajoException extends Exception implements TajoExceptionInterface { private ResultCode code; + public TajoException(ReturnState e) { + super(e.getMessage()); + this.code = e.getReturnCode(); + } + public TajoException(TajoRuntimeException e) { super(e.getMessage()); this.code = e.getErrorCode(); diff --git a/tajo-core/pom.xml b/tajo-core/pom.xml index 748950360a..60e02a69c6 100644 --- a/tajo-core/pom.xml +++ b/tajo-core/pom.xml @@ -54,8 +54,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 ${project.build.sourceEncoding} diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java index d89bca1b45..d647db4ec3 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java @@ -35,6 +35,8 @@ import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.error.Errors; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto; import org.apache.tajo.ipc.ClientProtos.QueryInfoProto; @@ -540,7 +542,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc try { client.updateQuery(rangeSql); fail(); - } catch (SQLException se) { + } catch (TajoRuntimeException se) { assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode()); } @@ -552,7 +554,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc try { assertFalse(client.updateQuery(listSql)); fail(); - } catch (SQLException se) { + } catch (TajoRuntimeException se) { assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode()); } @@ -563,7 +565,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc try { assertFalse(client.updateQuery(hashSql)); fail(); - } catch (SQLException se) { + } catch (TajoRuntimeException se) { assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode()); } } diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java index ebb19e4f62..73035c7b90 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java @@ -149,7 +149,6 @@ public int[] executeBatch() throws SQLException { public ResultSet executeQuery(String sql) throws SQLException { checkConnection("Can't execute"); return executeSQL(sql); - } protected ResultSet executeSQL(String sql) throws SQLException { From 1bea9f7052dd1650e8e9679c32113042a4a37dfb Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Tue, 28 Jul 2015 16:53:15 +0900 Subject: [PATCH 3/8] Add testExecuteUpdate test. --- .../tajo/client/v2/LegacyClientDelegate.java | 2 +- .../apache/tajo/client/v2/TestTajoClient.java | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java index 12e4613b42..68d7c06edd 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java @@ -354,7 +354,7 @@ public void run() { } } - private static class DelegateServiceTracker implements ServiceTracker { + public static class DelegateServiceTracker implements ServiceTracker { private final ServiceDiscovery discovery; DelegateServiceTracker(ServiceDiscovery discovery) { diff --git a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java new file mode 100644 index 0000000000..89986d61e6 --- /dev/null +++ b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java @@ -0,0 +1,73 @@ +/** + * 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.client.v2; + +import net.jcip.annotations.NotThreadSafe; +import org.apache.tajo.QueryTestCaseBase; +import org.apache.tajo.TajoTestingCluster; +import org.apache.tajo.TpchTestBase; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.conf.TajoConf; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.service.ServiceTracker; +import org.apache.tajo.service.ServiceTrackerFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.net.InetSocketAddress; + +import static org.junit.Assert.fail; + +@NotThreadSafe +public class TestTajoClient extends QueryTestCaseBase { + private static TajoClient clientv2; + + @BeforeClass + public static void setUp() throws Exception { + conf = testingCluster.getConfiguration(); + + clientv2 = new TajoClient(new ServiceDiscovery() { + ServiceTracker tracker = ServiceTrackerFactory.get(conf); + @Override + public InetSocketAddress clientAddress() { + return tracker.getClientServiceAddress(); + } + }); + } + + @AfterClass + public static void tearDown() throws Exception { + clientv2.close(); + } + + @Test + public void testExecuteUpdate() throws TajoException { + clientv2.executeUpdate("create database tajoclientv2"); + clientv2.selectDB("tajoclientv2"); + clientv2.selectDB("default"); + clientv2.executeUpdate("drop database tajoclientv2"); + + try { + clientv2.selectDB("tajoclientv2"); + fail(); + } catch (UndefinedDatabaseException e) { + } + } +} From 79e2a5ba59123c1e76ae7b614ac9730937a40c86 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Wed, 29 Jul 2015 01:00:43 +0900 Subject: [PATCH 4/8] Add unit tests for 3 types SQL execution through client v2. --- .../org/apache/tajo/client/v2/TajoClient.java | 15 ++++- ...tTajoClient.java => TestTajoClientV2.java} | 62 +++++++++++++++++-- .../testExecuteQueryType1.result | 7 +++ .../testExecuteQueryType2.result | 4 ++ .../testExecuteQueryType3.result | 4 ++ 5 files changed, 84 insertions(+), 8 deletions(-) rename tajo-core/src/test/java/org/apache/tajo/client/v2/{TestTajoClient.java => TestTajoClientV2.java} (55%) create mode 100644 tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result create mode 100644 tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result create mode 100644 tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java index dcd3b4e91f..01a1c5c87b 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java @@ -26,6 +26,7 @@ import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; import java.io.Closeable; +import java.io.IOException; import java.sql.ResultSet; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -99,6 +100,15 @@ public TajoClient(ServiceDiscovery discovery, Map properties) th delegate = ClientDeligateFactory.newDefaultDeligate(discovery, properties); } + /** + * Submit and executes the given SQL statement, which may be an INSERT (INTO), + * or CREATE TABLE AS SELECT statement or anSQL statement that returns nothing, + * such as an SQL DDL statement. + * + * @param sql a SQL statement + * @return inserted row number + * @throws TajoException + */ public int executeUpdate(String sql) throws TajoException { return delegate.executeUpdate(sql); } @@ -121,11 +131,12 @@ public ResultSet executeQuery(String sql) throws TajoException { * @return * @throws TajoException */ - public QueryFuture executeSQLAsync(String sql) throws TajoException { + public QueryFuture executeQueryAsync(String sql) throws TajoException { return delegate.executeSQLAsync(sql); } - public void close() { + public void close() throws IOException { + delegate.close(); } /** diff --git a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java similarity index 55% rename from tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java rename to tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java index 89986d61e6..0e1b98d87e 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClient.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java @@ -18,12 +18,8 @@ package org.apache.tajo.client.v2; -import net.jcip.annotations.NotThreadSafe; import org.apache.tajo.QueryTestCaseBase; -import org.apache.tajo.TajoTestingCluster; -import org.apache.tajo.TpchTestBase; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; -import org.apache.tajo.conf.TajoConf; import org.apache.tajo.exception.TajoException; import org.apache.tajo.service.ServiceTracker; import org.apache.tajo.service.ServiceTrackerFactory; @@ -31,12 +27,15 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.io.IOException; import java.net.InetSocketAddress; +import java.sql.ResultSet; +import java.sql.SQLException; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -@NotThreadSafe -public class TestTajoClient extends QueryTestCaseBase { +public class TestTajoClientV2 extends QueryTestCaseBase { private static TajoClient clientv2; @BeforeClass @@ -70,4 +69,55 @@ public void testExecuteUpdate() throws TajoException { } catch (UndefinedDatabaseException e) { } } + + @Test + public void testExecuteQueryType1() throws TajoException, IOException, SQLException { + ResultSet res = null; + try { + res = clientv2.executeQuery("select * from lineitem"); + assertResultSet(res); + } finally { + if (res != null) { + res.close(); + } + } + } + + @Test + public void testExecuteQueryType2() throws TajoException, IOException, SQLException { + ResultSet res = null; + try { + res = clientv2.executeQuery("select * from lineitem where l_orderkey > 2"); + assertResultSet(res); + } finally { + if (res != null) { + res.close(); + } + } + } + + @Test + public void testExecuteQueryType3() throws TajoException, IOException, SQLException { + ResultSet res = null; + try { + clientv2.executeUpdate("create database client_v2_type3"); + clientv2.selectDB("client_v2_type3"); + clientv2.executeUpdate("create table t1 (c1 int)"); + clientv2.executeUpdate("create table t2 (c2 int)"); + + // why we shouldn't use join directly on virtual tables? Currently, join on virtual tables is not supported. + res = clientv2.executeQuery("select db_id from information_schema.databases where db_name = 'client_v2_type3'"); + assertTrue(res.next()); + int dbId = res.getInt(1); + res.close(); + + res = clientv2.executeQuery( + "select table_name from information_schema.tables where db_id = " + dbId + " order by table_name"); + assertResultSet(res); + } finally { + if (res != null) { + res.close(); + } + } + } } diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result new file mode 100644 index 0000000000..ec6b9110c3 --- /dev/null +++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result @@ -0,0 +1,7 @@ +l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment +------------------------------- +1,1,7706,1,17.0,21168.23,0.04,0.02,N,O,1996-03-13,1996-02-12,1996-03-22,DELIVER IN PERSON,TRUCK,egular courts above the +1,1,7311,2,36.0,45983.16,0.09,0.06,N,O,1996-04-12,1996-02-28,1996-04-20,TAKE BACK RETURN,MAIL,ly final dependencies: slyly bold +2,2,1191,1,38.0,44694.46,0.0,0.05,N,O,1997-01-28,1997-01-14,1997-02-02,TAKE BACK RETURN,RAIL,ven requests. deposits breach a +3,2,1798,1,45.0,54058.05,0.06,0.0,R,F,1994-02-02,1994-01-04,1994-02-23,NONE,AIR,ongside of the furiously brave acco +3,3,6540,2,49.0,46796.47,0.1,0.0,R,F,1993-11-09,1993-12-20,1993-11-24,TAKE BACK RETURN,RAIL, unusual accounts. eve \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result new file mode 100644 index 0000000000..fd799444ce --- /dev/null +++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result @@ -0,0 +1,4 @@ +l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment +------------------------------- +3,2,1798,1,45.0,54058.05,0.06,0.0,R,F,1994-02-02,1994-01-04,1994-02-23,NONE,AIR,ongside of the furiously brave acco +3,3,6540,2,49.0,46796.47,0.1,0.0,R,F,1993-11-09,1993-12-20,1993-11-24,TAKE BACK RETURN,RAIL, unusual accounts. eve \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result new file mode 100644 index 0000000000..5407d9d81d --- /dev/null +++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result @@ -0,0 +1,4 @@ +table_name +------------------------------- +t1 +t2 \ No newline at end of file From 54365db55dafc123d9aefab27da63b2bf2cba589 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Wed, 29 Jul 2015 11:12:10 +0900 Subject: [PATCH 5/8] Changed lots of SQLException to TajoException and implement ClientExceptionUtil. --- .../tajo/catalog/AbstractCatalogClient.java | 4 +- .../apache/tajo/catalog/CatalogService.java | 5 +- .../java/org/apache/tajo/catalog/Schema.java | 4 +- .../exception/AmbiguousFunctionException.java | 6 + .../catalog/exception/CatalogException.java | 9 +- .../exception/DuplicateDatabaseException.java | 5 + .../exception/DuplicateTableException.java | 5 + .../exception/UndefinedDatabaseException.java | 5 + .../exception/UndefinedFunctionException.java | 5 + .../exception/UndefinedTableException.java | 5 + .../tajo/catalog/store/HiveCatalogUtil.java | 2 +- .../apache/tajo/catalog/CatalogServer.java | 62 +++++----- .../InfoSchemaMetadataDictionary.java | 6 +- .../tajo/catalog/store/AbstractDBStore.java | 18 +-- .../apache/tajo/catalog/store/MemStore.java | 2 +- .../store/XMLCatalogSchemaManager.java | 8 +- .../org/apache/tajo/cli/tsql/TajoCli.java | 7 +- .../tsql/commands/ConnectDatabaseCommand.java | 3 +- .../tajo/cli/tsql/commands/SetCommand.java | 5 +- .../tajo/client/CatalogAdminClient.java | 27 +++-- .../tajo/client/CatalogAdminClientImpl.java | 93 +++++++++++---- .../tajo/client/ClientExceptionUtil.java | 46 ++++++++ .../org/apache/tajo/client/QueryClient.java | 31 ++--- .../apache/tajo/client/QueryClientImpl.java | 45 ++++---- .../apache/tajo/client/SessionConnection.java | 63 ++++++----- .../apache/tajo/client/TajoClientImpl.java | 42 +++---- .../tajo/client/v2/LegacyClientDelegate.java | 7 +- .../apache/tajo/exception/ExceptionUtil.java | 5 + .../NoSuchSessionVariableException.java | 33 ++++++ .../tajo/exception/SQLExceptionUtil.java | 22 ++-- .../apache/tajo/benchmark/BenchmarkSet.java | 3 +- .../java/org/apache/tajo/benchmark/TPCH.java | 5 +- .../engine/planner/global/GlobalPlanner.java | 107 +++++++++--------- .../org/apache/tajo/master/TajoMaster.java | 3 +- .../apache/tajo/master/exec/DDLExecutor.java | 26 +++-- .../tajo/webapp/QueryExecutorServlet.java | 2 +- .../apache/tajo/LocalTajoTestingUtility.java | 6 +- .../org/apache/tajo/QueryTestCaseBase.java | 10 +- .../apache/tajo/client/TestTajoClient.java | 50 ++++---- .../tajo/client/TestTajoClientFailures.java | 8 +- .../tajo/client/v2/TestTajoClientV2.java | 14 +++ .../engine/codegen/TestEvalCodeGenerator.java | 23 ++-- .../apache/tajo/engine/eval/ExprTestBase.java | 33 +++--- .../tajo/engine/eval/TestIntervalType.java | 5 +- .../tajo/engine/eval/TestPredicates.java | 39 +++---- .../engine/eval/TestSQLDateTimeTypes.java | 11 +- .../tajo/engine/eval/TestSQLExpression.java | 31 ++--- .../function/TestConditionalExpressions.java | 11 +- .../function/TestDateTimeFunctions.java | 21 ++-- .../engine/function/TestJsonFunctions.java | 5 +- .../engine/function/TestMathFunctions.java | 49 ++++---- .../TestPatternMatchingPredicates.java | 15 ++- .../engine/function/TestPythonFunctions.java | 5 +- .../TestStringOperatorsAndFunctions.java | 77 +++++++------ .../tajo/engine/query/TestJoinQuery.java | 6 +- .../org/apache/tajo/jdbc/TestTajoJdbc.java | 46 -------- .../org/apache/tajo/jdbc/JdbcConnection.java | 28 +++-- .../org/apache/tajo/jdbc/TajoStatement.java | 54 --------- .../tajo/plan/nameresolver/NameResolver.java | 6 +- .../plan/nameresolver/ResolverByLegacy.java | 3 +- .../plan/nameresolver/ResolverByRels.java | 4 +- .../ResolverByRelsAndSubExprs.java | 4 +- .../ResolverBySubExprsAndRels.java | 4 +- .../rewrite/rules/ProjectionPushDownRule.java | 11 +- .../plan/serder/EvalNodeDeserializer.java | 5 +- 65 files changed, 727 insertions(+), 583 deletions(-) create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java create mode 100644 tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.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 f7f77851dc..987220adb5 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 @@ -642,13 +642,13 @@ public final boolean dropFunction(final String signature) { @Override public final FunctionDesc getFunction(final String signature, DataType... paramTypes) - throws UndefinedFunctionException { + throws AmbiguousFunctionException , UndefinedFunctionException { return getFunction(signature, null, paramTypes); } @Override public final FunctionDesc getFunction(final String signature, FunctionType funcType, DataType... paramTypes) - throws UndefinedFunctionException { + throws AmbiguousFunctionException, UndefinedFunctionException { final GetFunctionMetaRequest.Builder builder = GetFunctionMetaRequest.newBuilder(); builder.setSignature(signature); 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 5dc54126e1..4e238f73d7 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,7 @@ package org.apache.tajo.catalog; +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; @@ -213,9 +214,9 @@ CatalogProtos.PartitionDescProto getPartition(String databaseName, String tableN boolean dropFunction(String signature); - FunctionDesc getFunction(String signature, DataType... paramTypes) throws UndefinedFunctionException; + FunctionDesc getFunction(String signature, DataType... paramTypes) throws AmbiguousFunctionException, UndefinedFunctionException; - FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws UndefinedFunctionException; + FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws AmbiguousFunctionException, UndefinedFunctionException; boolean containFunction(String signature, DataType... paramTypes); 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 424861b1bf..7bffe3a8b4 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 @@ -31,6 +31,7 @@ import org.apache.tajo.common.ProtoObject; import org.apache.tajo.common.TajoDataTypes.DataType; import org.apache.tajo.common.TajoDataTypes.Type; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.json.GsonObject; import org.apache.tajo.util.StringUtils; import org.apache.tajo.util.TUtil; @@ -419,8 +420,7 @@ public boolean containsAny(Collection columns) { public synchronized Schema addColumn(String name, TypeDesc typeDesc) { String normalized = name; if(fieldsByQualifiedName.containsKey(normalized)) { - LOG.error("Already exists column " + normalized); - throw new DuplicateColumnException(normalized); + throw new TajoRuntimeException(new DuplicateColumnException(normalized)); } Column newCol = new Column(normalized, typeDesc); 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 index d1f17fd2b8..56c11e1592 100644 --- 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 @@ -20,10 +20,16 @@ import org.apache.tajo.common.TajoDataTypes.DataType; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature; public class AmbiguousFunctionException extends CatalogException { + + public AmbiguousFunctionException(PrimitiveProtos.ReturnState state) { + super(state); + } + public AmbiguousFunctionException(String funcName, DataType[] parameters) { super(Errors.ResultCode.AMBIGUOUS_FUNCTION, buildSimpleFunctionSignature(funcName, parameters)); } 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 7098800541..e19199cb12 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 @@ -19,11 +19,16 @@ package org.apache.tajo.catalog.exception; import org.apache.tajo.error.Errors.ResultCode; -import org.apache.tajo.exception.TajoRuntimeException; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; -public class CatalogException extends TajoRuntimeException { +public class CatalogException extends TajoException { private static final long serialVersionUID = -26362412527118618L; + public CatalogException(ReturnState state) { + super(state); + } + public CatalogException(ResultCode code, String...args) { super(code, args); } 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 index 69e37d323b..5903051afa 100644 --- 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 @@ -20,8 +20,13 @@ import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; public class DuplicateDatabaseException extends CatalogException { + + public DuplicateDatabaseException(PrimitiveProtos.ReturnState state) { + super(state); + } public DuplicateDatabaseException(String dbName) { super(Errors.ResultCode.DUPLICATE_DATABASE, dbName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java index 74fa39fb2d..6833d39ceb 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java @@ -20,10 +20,15 @@ import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; public class DuplicateTableException extends CatalogException { private static final long serialVersionUID = -641623770742392865L; + public DuplicateTableException(PrimitiveProtos.ReturnState state) { + super(state); + } + public DuplicateTableException(String relName) { super(Errors.ResultCode.DUPLICATE_TABLE, relName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java index 8294addf15..76f8b43fc2 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java @@ -20,10 +20,15 @@ import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; public class UndefinedDatabaseException extends CatalogException { private static final long serialVersionUID = 277182608283894937L; + public UndefinedDatabaseException(PrimitiveProtos.ReturnState state) { + super(state); + } + public UndefinedDatabaseException(String dbName) { super(Errors.ResultCode.UNDEFINED_DATABASE, dbName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java index 175b59751b..94ce23642e 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java @@ -24,12 +24,17 @@ import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.function.FunctionUtil; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; import java.util.Collection; public class UndefinedFunctionException extends CatalogException { private static final long serialVersionUID = 5062193018697228028L; + public UndefinedFunctionException(PrimitiveProtos.ReturnState state) { + super(state); + } + public UndefinedFunctionException(String signature) { super(ResultCode.UNDEFINED_FUNCTION, signature); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java index 2513783e92..35ccb70770 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java @@ -21,10 +21,15 @@ import org.apache.tajo.catalog.CatalogUtil; import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; public class UndefinedTableException extends CatalogException { private static final long serialVersionUID = 277182608283894937L; + public UndefinedTableException(PrimitiveProtos.ReturnState state) { + super(state); + } + public UndefinedTableException(String dbName, String tbName) { super(ResultCode.UNDEFINED_TABLE, CatalogUtil.buildFQName(dbName, tbName)); } diff --git a/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java b/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java index 5ae5969cbf..39b3cb9851 100644 --- a/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java +++ b/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java @@ -47,7 +47,7 @@ public static void validateSchema(Table tblSchema) throws CatalogException { } } - public static TajoDataTypes.Type getTajoFieldType(String dataType) { + public static TajoDataTypes.Type getTajoFieldType(String dataType) throws CatalogException { Preconditions.checkNotNull(dataType); if(dataType.equalsIgnoreCase(serdeConstants.INT_TYPE_NAME)) { diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java index 6a3fc166d8..c7c7a1cbf7 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java @@ -545,20 +545,22 @@ public GetDatabasesResponse getAllDatabases(RpcController controller, NullProto @Override public TableResponse getTableDesc(RpcController controller, - TableIdentifierProto request) throws ServiceException { + TableIdentifierProto request) { String dbName = request.getDatabaseName(); String tbName = request.getTableName(); - if (metaDictionary.isSystemDatabase(dbName)) { - return TableResponse.newBuilder() - .setState(OK) - .setTable(metaDictionary.getTableDesc(tbName)) - .build(); - } else { - rlock.lock(); - try { - boolean contain; + rlock.lock(); + try { + + if (metaDictionary.isSystemDatabase(dbName)) { + + return TableResponse.newBuilder() + .setState(OK) + .setTable(metaDictionary.getTableDesc(tbName)) + .build(); + } else { + boolean contain; contain = store.existDatabase(dbName); if (contain) { @@ -578,17 +580,17 @@ public TableResponse getTableDesc(RpcController controller, .setState(errUndefinedDatabase(dbName)) .build(); } + } - } catch (Throwable t) { - printStackTraceIfError(LOG, t); + } catch (Throwable t) { + printStackTraceIfError(LOG, t); - return TableResponse.newBuilder() - .setState(returnError(t)) - .build(); + return TableResponse.newBuilder() + .setState(returnError(t)) + .build(); - } finally { - rlock.unlock(); - } + } finally { + rlock.unlock(); } } @@ -716,15 +718,15 @@ public ReturnState existsTable(RpcController controller, TableIdentifierProto re String dbName = request.getDatabaseName(); String tbName = request.getTableName(); - if (metaDictionary.isSystemDatabase(dbName)) { - return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName); + rlock.lock(); + try { - } else { - rlock.lock(); - try { + if (metaDictionary.isSystemDatabase(dbName)) { + return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName); - boolean contain = store.existDatabase(dbName); + } else { + boolean contain = store.existDatabase(dbName); if (contain) { if (store.existTable(dbName, tbName)) { return OK; @@ -734,14 +736,14 @@ public ReturnState existsTable(RpcController controller, TableIdentifierProto re } else { return errUndefinedDatabase(dbName); } + } - } catch (Throwable t) { - printStackTraceIfError(LOG, t); - return returnError(t); + } catch (Throwable t) { + printStackTraceIfError(LOG, t); + return returnError(t); - } finally { - rlock.unlock(); - } + } finally { + rlock.unlock(); } } diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java index f798c1dfc6..4f481820f9 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java @@ -91,7 +91,7 @@ public List getAllSystemTables() { return systemTableNames; } - private TableDescriptor getTableDescriptor(String tableName) { + private TableDescriptor getTableDescriptor(String tableName) throws UndefinedTableException { TableDescriptor tableDescriptor = null; if (tableName == null || tableName.isEmpty()) { @@ -110,7 +110,7 @@ private TableDescriptor getTableDescriptor(String tableName) { return tableDescriptor; } - public CatalogProtos.TableDescProto getTableDesc(String tableName) { + public CatalogProtos.TableDescProto getTableDesc(String tableName) throws UndefinedTableException { TableDescriptor tableDescriptor; tableDescriptor = getTableDescriptor(tableName); @@ -121,7 +121,7 @@ public CatalogProtos.TableDescProto getTableDesc(String tableName) { return tableDescriptor.getTableDescription(); } - public boolean existTable(String tableName) { + public boolean existTable(String tableName) throws UndefinedTableException { return getTableDescriptor(tableName) != null; } 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 c6b7d36315..ffc25277c3 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 @@ -167,7 +167,7 @@ public AbstractDBStore(Configuration conf) throws InternalException { } } } - } catch (Exception se) { + } catch (Throwable se) { throw new TajoInternalError(se); } } @@ -188,7 +188,7 @@ protected String getCatalogUri() { return catalogUri; } - protected boolean isConnValid(int timeout) throws CatalogException { + protected boolean isConnValid(int timeout) { boolean isValid = false; try { @@ -691,7 +691,7 @@ public String getHandler() { } } - private TableSpaceInternal getTableSpaceInfo(String spaceName) { + private TableSpaceInternal getTableSpaceInfo(String spaceName) throws UndefinedTablespaceException { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -730,7 +730,7 @@ private int getTableId(int databaseId, String databaseName, String tableName) { } return res.getInt(1); } catch (SQLException se) { - throw new UndefinedTableException(databaseName, tableName); + throw new TajoInternalError(se); } finally { CatalogUtil.closeQuietly(pstmt, res); } @@ -1022,7 +1022,7 @@ public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) th } - private Map getTableOptions(final int tableId) throws CatalogException { + private Map getTableOptions(final int tableId) { Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; @@ -1358,7 +1358,7 @@ private void dropPartition(int tableId, String partitionName) throws CatalogExce } } - private int getDatabaseId(String databaseName) throws SQLException { + private int getDatabaseId(String databaseName) throws SQLException, UndefinedDatabaseException { String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES); if (LOG.isDebugEnabled()) { @@ -1417,7 +1417,7 @@ public boolean existTable(String databaseName, final String tableName) throws Ca } public void dropTableInternal(Connection conn, String databaseName, final String tableName) - throws SQLException { + throws SQLException, UndefinedDatabaseException { PreparedStatement pstmt = null; @@ -1530,7 +1530,9 @@ public void dropTable(String databaseName, final String tableName) throws Catalo } } - public Pair getDatabaseIdAndUri(String databaseName) throws SQLException { + public Pair getDatabaseIdAndUri(String databaseName) + throws SQLException, UndefinedDatabaseException { + String sql = "SELECT DB_ID, SPACE_URI from " + TB_DATABASES + " natural join " + TB_SPACES + " WHERE db_name = ?"; 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 5763f31f58..1316dc4cdc 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 @@ -193,7 +193,7 @@ public List getAllDatabases() throws CatalogException { * Get a database namespace from a Map instance. */ private Map checkAndGetDatabaseNS(final Map> databaseMap, - String databaseName) { + String databaseName) throws UndefinedDatabaseException { if (databaseMap.containsKey(databaseName)) { return databaseMap.get(databaseName); } else { diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java index dd8e2a278a..9d767a06cf 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java @@ -64,15 +64,15 @@ public class XMLCatalogSchemaManager { private final Unmarshaller unmarshaller; private StoreObject catalogStore; - public XMLCatalogSchemaManager(String schemaPath) throws CatalogException { + public XMLCatalogSchemaManager(String schemaPath) { this.schemaPath = schemaPath; try { JAXBContext context = JAXBContext.newInstance(StoreObject.class); unmarshaller = context.createUnmarshaller(); loadFromXmlFiles(); - } catch (Exception e) { - throw new TajoInternalError(e); + } catch (Throwable t) { + throw new TajoInternalError(t); } } @@ -489,7 +489,7 @@ public boolean accept(File dir, String name) { return files; } - protected void mergeXmlSchemas(final List storeObjects) throws CatalogException { + protected void mergeXmlSchemas(final List storeObjects) { if (storeObjects.size() <= 0) { throw new TajoInternalError("Unable to find a schema file."); } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java index c6409f1430..eadd4dfc44 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java @@ -34,6 +34,7 @@ import org.apache.tajo.conf.TajoConf; import org.apache.tajo.conf.TajoConf.ConfVars; import org.apache.tajo.exception.ReturnStateUtil; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.service.ServiceTrackerFactory; import org.apache.tajo.util.FileUtil; @@ -296,7 +297,7 @@ private void processConfVarCommand(String[] confCommands) throws SQLException { } } - private void processSessionVarCommand(String[] confCommands) throws SQLException { + private void processSessionVarCommand(String[] confCommands) throws TajoException { for (String eachParam: confCommands) { String[] tokens = eachParam.split("="); if (tokens.length != 2) { @@ -488,7 +489,7 @@ public int executeMetaCommand(String line) throws Exception { return 0; } - private void executeJsonQuery(String json) throws SQLException { + private void executeJsonQuery(String json) throws TajoException { long startTime = System.currentTimeMillis(); ClientProtos.SubmitQueryResponse response = client.executeQueryWithJson(json); @@ -581,7 +582,7 @@ private void localQueryCompleted(ClientProtos.SubmitQueryResponse response, long } } - private void waitForQueryCompleted(QueryId queryId) throws SQLException { + private void waitForQueryCompleted(QueryId queryId) { // if query is empty string if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return; diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java index e75171d4ed..3682a74a1a 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java @@ -20,6 +20,7 @@ import com.google.protobuf.ServiceException; import org.apache.tajo.cli.tsql.TajoCli; +import org.apache.tajo.exception.TajoException; import java.sql.SQLException; @@ -51,7 +52,7 @@ public void invoke(String[] cmd) throws Exception { context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n", context.getCurrentDatabase(), client.getUserInfo().getUserName())); } - } catch (SQLException se) { + } catch (TajoException se) { if (se.getMessage() != null) { context.getOutput().write(se.getMessage()); } else { diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java index c1c286d761..0ae07d592f 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java @@ -21,6 +21,7 @@ import com.google.protobuf.ServiceException; import org.apache.tajo.SessionVars; import org.apache.tajo.cli.tsql.TajoCli; +import org.apache.tajo.exception.NoSuchSessionVariableException; import org.apache.tajo.util.StringUtils; import java.sql.SQLException; @@ -46,13 +47,13 @@ private void showAllSessionVars() throws SQLException { } } - private void updateSessionVariable(String key, String val) throws SQLException { + private void updateSessionVariable(String key, String val) throws NoSuchSessionVariableException { Map variables = new HashMap(); variables.put(key, val); client.updateSessionVariables(variables); } - public void set(String key, String val) throws SQLException { + public void set(String key, String val) throws NoSuchSessionVariableException { SessionVars sessionVar; if (SessionVars.exists(key)) { // if the variable is one of the session variables diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java index c020ef542e..b1ba9dd1d3 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java @@ -22,8 +22,10 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.catalog.exception.*; import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; +import org.apache.tajo.exception.TajoException; import java.io.Closeable; import java.net.URI; @@ -38,7 +40,7 @@ public interface CatalogAdminClient extends Closeable { * @return True if created successfully. * @throws java.sql.SQLException */ - boolean createDatabase(final String databaseName) throws SQLException; + boolean createDatabase(final String databaseName) throws DuplicateDatabaseException; /** * Does the database exist? * @@ -46,7 +48,7 @@ public interface CatalogAdminClient extends Closeable { * @return True if so. * @throws java.sql.SQLException */ - boolean existDatabase(final String databaseName) throws SQLException; + boolean existDatabase(final String databaseName); /** * Drop the database * @@ -54,9 +56,9 @@ public interface CatalogAdminClient extends Closeable { * @return True if the database is dropped successfully. * @throws java.sql.SQLException */ - boolean dropDatabase(final String databaseName) throws SQLException; + boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException; - List getAllDatabaseNames() throws SQLException; + List getAllDatabaseNames(); /** * Does the table exist? @@ -64,7 +66,7 @@ public interface CatalogAdminClient extends Closeable { * @param tableName The table name to be checked. This name is case sensitive. * @return True if so. */ - boolean existTable(final String tableName) throws SQLException; + boolean existTable(final String tableName); /** * Create an external table. @@ -78,7 +80,7 @@ public interface CatalogAdminClient extends Closeable { * @throws java.sql.SQLException */ TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, - final TableMeta meta) throws SQLException; + final TableMeta meta) throws DuplicateTableException; /** * Create an external table. @@ -94,7 +96,7 @@ TableDesc createExternalTable(final String tableName, final Schema schema, final */ TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, final TableMeta meta, final PartitionMethodDesc partitionMethodDesc) - throws SQLException; + throws DuplicateTableException; /** * Drop a table @@ -103,7 +105,7 @@ TableDesc createExternalTable(final String tableName, final Schema schema, final * @return True if the table is dropped successfully. * @throws java.sql.SQLException */ - boolean dropTable(final String tableName) throws SQLException; + boolean dropTable(final String tableName) throws UndefinedTableException; /** * Drop a table. @@ -113,7 +115,7 @@ TableDesc createExternalTable(final String tableName, final Schema schema, final * @return True if the table is dropped successfully. * @throws java.sql.SQLException */ - boolean dropTable(final String tableName, final boolean purge) throws SQLException; + boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException; /** * Get a list of table names. @@ -123,7 +125,7 @@ TableDesc createExternalTable(final String tableName, final Schema schema, final * in the current database of this session. * @throws java.sql.SQLException */ - List getTableList(@Nullable final String databaseName) throws SQLException; + List getTableList(@Nullable final String databaseName); /** * Get a table description @@ -132,7 +134,8 @@ TableDesc createExternalTable(final String tableName, final Schema schema, final * @return Table description * @throws java.sql.SQLException */ - TableDesc getTableDesc(final String tableName) throws SQLException; + TableDesc getTableDesc(final String tableName) throws UndefinedTableException; - List getFunctions(final String functionName) throws SQLException; + List getFunctions(final String functionName) + throws AmbiguousFunctionException, UndefinedFunctionException; } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java index e73a032188..a8517a1b98 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java @@ -24,14 +24,17 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.catalog.exception.*; import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.proto.CatalogProtos.FunctionDescProto; import org.apache.tajo.catalog.proto.CatalogProtos.TableResponse; +import org.apache.tajo.error.Errors; import org.apache.tajo.exception.SQLExceptionUtil; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.ClientProtos.DropTableRequest; import org.apache.tajo.rpc.NettyClientBase; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListResponse; import java.io.IOException; @@ -39,7 +42,9 @@ import java.sql.SQLException; import java.util.List; +import static org.apache.tajo.exception.ReturnStateUtil.ensureOk; import static org.apache.tajo.exception.ReturnStateUtil.isSuccess; +import static org.apache.tajo.exception.ReturnStateUtil.isThisError; import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError; import static org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface; @@ -51,19 +56,27 @@ public CatalogAdminClientImpl(SessionConnection conn) { } @Override - public boolean createDatabase(final String databaseName) throws SQLException { + public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException { final BlockingInterface stub = conn.getTMStub(); try { - return isSuccess(stub.createDatabase(null, conn.getSessionedString(databaseName))); + PrimitiveProtos.ReturnState state = stub.createDatabase(null, conn.getSessionedString(databaseName)); + + if (isThisError(state, Errors.ResultCode.DUPLICATE_DATABASE)) { + throw new DuplicateDatabaseException(state); + } + + ensureOk(state); + return true; + } catch (ServiceException e) { throw new RuntimeException(e); } } @Override - public boolean existDatabase(final String databaseName) throws SQLException { + public boolean existDatabase(final String databaseName) { final BlockingInterface stub = conn.getTMStub(); @@ -75,19 +88,24 @@ public boolean existDatabase(final String databaseName) throws SQLException { } @Override - public boolean dropDatabase(final String databaseName) throws SQLException { + public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException { final BlockingInterface stub = conn.getTMStub(); try { - return isSuccess(stub.dropDatabase(null, conn.getSessionedString(databaseName))); + PrimitiveProtos.ReturnState state = stub.dropDatabase(null, conn.getSessionedString(databaseName)); + if (isThisError(state, Errors.ResultCode.UNDEFINED_DATABASE)) { + throw new UndefinedDatabaseException(state); + } + ensureOk(state); + return true; } catch (ServiceException e) { throw new RuntimeException(e); } } @Override - public List getAllDatabaseNames() throws SQLException { + public List getAllDatabaseNames() { final BlockingInterface stub = conn.getTMStub(); @@ -98,26 +116,34 @@ public List getAllDatabaseNames() throws SQLException { } } - public boolean existTable(final String tableName) throws SQLException { + public boolean existTable(final String tableName) { final BlockingInterface stub = conn.getTMStub(); + PrimitiveProtos.ReturnState state; try { - return isSuccess(stub.existTable(null, conn.getSessionedString(tableName))); + state = stub.existTable(null, conn.getSessionedString(tableName)); } catch (ServiceException e) { throw new RuntimeException(e); } + + if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) { + return false; + } + + ensureOk(state); + return true; } @Override public TableDesc createExternalTable(String tableName, Schema schema, URI path, TableMeta meta) - throws SQLException { + throws DuplicateTableException { return createExternalTable(tableName, schema, path, meta, null); } public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, final TableMeta meta, final PartitionMethodDesc partitionMethodDesc) - throws SQLException { + throws DuplicateTableException { NettyClientBase client = conn.getTajoMasterConnection(); conn.checkSessionAndGet(client); @@ -141,20 +167,21 @@ public TableDesc createExternalTable(final String tableName, final Schema schema throw new RuntimeException(e); } - if (isSuccess(res.getState())) { - return CatalogUtil.newTableDesc(res.getTable()); - } else { - throw SQLExceptionUtil.toSQLException(res.getState()); + if (isThisError(res.getState(), Errors.ResultCode.DUPLICATE_TABLE)) { + throw new DuplicateTableException(res.getState()); } + + ensureOk(res.getState()); + return CatalogUtil.newTableDesc(res.getTable()); } @Override - public boolean dropTable(String tableName) throws SQLException { + public boolean dropTable(String tableName) throws UndefinedTableException { return dropTable(tableName, false); } @Override - public boolean dropTable(final String tableName, final boolean purge) throws SQLException { + public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException { final BlockingInterface stub = conn.getTMStub(); final DropTableRequest request = DropTableRequest.newBuilder() @@ -163,15 +190,24 @@ public boolean dropTable(final String tableName, final boolean purge) throws SQL .setPurge(purge) .build(); + + PrimitiveProtos.ReturnState state; try { - return isSuccess(stub.dropTable(null, request)); + state = stub.dropTable(null, request); } catch (ServiceException e) { throw new RuntimeException(e); } + + if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) { + throw new UndefinedTableException(state); + } + + ensureOk(state); + return true; } @Override - public List getTableList(@Nullable final String databaseName) throws SQLException { + public List getTableList(@Nullable final String databaseName) { final BlockingInterface stub = conn.getTMStub(); @@ -182,12 +218,12 @@ public List getTableList(@Nullable final String databaseName) throws SQL throw new RuntimeException(e); } - throwIfError(response.getState()); + ensureOk(response.getState()); return response.getValuesList(); } @Override - public TableDesc getTableDesc(final String tableName) throws SQLException { + public TableDesc getTableDesc(final String tableName) throws UndefinedTableException { final BlockingInterface stub = conn.getTMStub(); @@ -198,12 +234,17 @@ public TableDesc getTableDesc(final String tableName) throws SQLException { throw new RuntimeException(e); } - throwIfError(res.getState()); + if (isThisError(res.getState(), Errors.ResultCode.UNDEFINED_TABLE)) { + throw new UndefinedTableException(res.getState()); + } + + ensureOk(res.getState()); return CatalogUtil.newTableDesc(res.getTable()); } @Override - public List getFunctions(final String functionName) throws SQLException { + public List getFunctions(final String functionName) + throws AmbiguousFunctionException, UndefinedFunctionException { final BlockingInterface stub = conn.getTMStub(); @@ -215,7 +256,13 @@ public List getFunctions(final String functionName) throws SQ throw new RuntimeException(e); } - throwIfError(res.getState()); + if (isThisError(res.getState(), Errors.ResultCode.AMBIGUOUS_FUNCTION)) { + throw new AmbiguousFunctionException(res.getState()); + } else if (isThisError(res.getState(), Errors.ResultCode.UNDEFINED_FUNCTION)) { + throw new UndefinedFunctionException(res.getState()); + } + + ensureOk(res.getState()); return res.getFunctionList(); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java new file mode 100644 index 0000000000..9c74b19abf --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java @@ -0,0 +1,46 @@ +/** + * 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.client; + +import org.apache.tajo.catalog.exception.DuplicateDatabaseException; +import org.apache.tajo.catalog.exception.UndefinedTableException; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; + +import static org.apache.tajo.exception.ReturnStateUtil.isError; + +public class ClientExceptionUtil { + + public static void throwIfError(PrimitiveProtos.ReturnState state) throws TajoException { + if (isError(state)) { + throw toTajoException(state); + } + } + + public static TajoException toTajoException(PrimitiveProtos.ReturnState state) { + switch (state.getReturnCode()) { + case DUPLICATE_DATABASE: + return new DuplicateDatabaseException(state); + case UNDEFINED_TABLE: + return new UndefinedTableException(state); + default: + return new TajoException(state); + } + } +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java index 7789d626db..0847f71f28 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java @@ -21,6 +21,9 @@ import com.google.protobuf.ServiceException; import org.apache.tajo.QueryId; import org.apache.tajo.auth.UserRoleInfo; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.exception.NoSuchSessionVariableException; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto; import org.apache.tajo.ipc.ClientProtos.QueryInfoProto; @@ -59,23 +62,23 @@ public interface QueryClient extends Closeable { * Call to QueryMaster closing query resources * @param queryId */ - void closeQuery(final QueryId queryId) throws SQLException; + void closeQuery(final QueryId queryId); void closeNonForwardQuery(final QueryId queryId) throws SQLException; - String getCurrentDatabase() throws SQLException; + String getCurrentDatabase(); - Boolean selectDatabase(final String databaseName) throws SQLException; + Boolean selectDatabase(final String databaseName) throws UndefinedDatabaseException; - Map updateSessionVariables(final Map variables) throws SQLException; + Map updateSessionVariables(final Map variables) throws NoSuchSessionVariableException; - Map unsetSessionVariables(final List variables) throws SQLException; + Map unsetSessionVariables(final List variables) throws NoSuchSessionVariableException; - String getSessionVariable(final String varname) throws SQLException; + String getSessionVariable(final String varname) throws NoSuchSessionVariableException; - Boolean existSessionVariable(final String varname) throws SQLException; + Boolean existSessionVariable(final String varname); - Map getAllSessionVariables() throws SQLException; + Map getAllSessionVariables(); /** * It submits a query statement and get a response immediately. @@ -84,7 +87,7 @@ public interface QueryClient extends Closeable { */ SubmitQueryResponse executeQuery(final String sql); - SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException; + SubmitQueryResponse executeQueryWithJson(final String json); /** * It submits a query statement and get a response. @@ -94,9 +97,9 @@ public interface QueryClient extends Closeable { * * @return If failed, return null. */ - ResultSet executeQueryAndGetResult(final String sql) throws SQLException; + ResultSet executeQueryAndGetResult(final String sql) throws TajoException; - ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException; + ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException; QueryStatus getQueryStatus(QueryId queryId); @@ -108,13 +111,13 @@ public interface QueryClient extends Closeable { TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException; - boolean updateQuery(final String sql); + boolean updateQuery(final String sql) throws TajoException; - boolean updateQueryWithJson(final String json) throws SQLException; + boolean updateQueryWithJson(final String json) throws TajoException; List getRunningQueryList() throws SQLException; - List getFinishedQueryList() throws SQLException; + List getFinishedQueryList(); List getClusterInfo() throws SQLException; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java index 747cc188b0..85bd5f231c 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java @@ -27,7 +27,10 @@ import org.apache.tajo.catalog.CatalogUtil; import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.exception.NoSuchSessionVariableException; import org.apache.tajo.exception.SQLExceptionUtil; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.QueryMasterClientProtocol; import org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface; @@ -96,51 +99,51 @@ public UserRoleInfo getUserInfo() { } @Override - public void closeQuery(QueryId queryId) throws SQLException { + public void closeQuery(QueryId queryId) { closeNonForwardQuery(queryId); } @Override - public void closeNonForwardQuery(QueryId queryId) throws SQLException { + public void closeNonForwardQuery(QueryId queryId) { try { - throwIfError(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId))); + ensureOk(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId))); } catch (ServiceException e) { throw new RuntimeException(e); } } @Override - public String getCurrentDatabase() throws SQLException { + public String getCurrentDatabase() { return conn.getCurrentDatabase(); } @Override - public Boolean selectDatabase(String databaseName) throws SQLException { + public Boolean selectDatabase(String databaseName) throws UndefinedDatabaseException { return conn.selectDatabase(databaseName); } @Override - public Map updateSessionVariables(Map variables) throws SQLException { + public Map updateSessionVariables(Map variables) throws NoSuchSessionVariableException { return conn.updateSessionVariables(variables); } @Override - public Map unsetSessionVariables(List variables) throws SQLException { + public Map unsetSessionVariables(List variables) throws NoSuchSessionVariableException { return conn.unsetSessionVariables(variables); } @Override - public String getSessionVariable(String varname) throws SQLException { + public String getSessionVariable(String varname) throws NoSuchSessionVariableException { return conn.getSessionVariable(varname); } @Override - public Boolean existSessionVariable(String varname) throws SQLException { + public Boolean existSessionVariable(String varname) { return conn.existSessionVariable(varname); } @Override - public Map getAllSessionVariables() throws SQLException { + public Map getAllSessionVariables() { return conn.getAllSessionVariables(); } @@ -165,7 +168,7 @@ public ClientProtos.SubmitQueryResponse executeQuery(final String sql) { } @Override - public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException { + public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) { final BlockingInterface stub = conn.getTMStub(); final QueryRequest request = buildQueryRequest(json, true); @@ -177,10 +180,10 @@ public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) } @Override - public ResultSet executeQueryAndGetResult(String sql) throws SQLException { + public ResultSet executeQueryAndGetResult(String sql) throws TajoException { ClientProtos.SubmitQueryResponse response = executeQuery(sql); - throwIfError(response.getState()); + ensureOk(response.getState()); QueryId queryId = new QueryId(response.getQueryId()); @@ -195,10 +198,10 @@ public ResultSet executeQueryAndGetResult(String sql) throws SQLException { } @Override - public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException { + public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException { ClientProtos.SubmitQueryResponse response = executeQueryWithJson(json); - throwIfError(response.getState()); + ensureOk(response.getState()); QueryId queryId = new QueryId(response.getQueryId()); @@ -344,7 +347,7 @@ public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int } @Override - public boolean updateQuery(final String sql) { + public boolean updateQuery(final String sql) throws TajoException { final BlockingInterface stub = conn.getTMStub(); final QueryRequest request = buildQueryRequest(sql, false); @@ -356,14 +359,14 @@ public boolean updateQuery(final String sql) { throw new RuntimeException(e); } - ensureOk(response.getState()); + ClientExceptionUtil.throwIfError(response.getState()); conn.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); return true; } @Override - public boolean updateQueryWithJson(final String json) throws SQLException { + public boolean updateQueryWithJson(final String json) throws TajoException { final BlockingInterface stub = conn.getTMStub(); final QueryRequest request = buildQueryRequest(json, true); @@ -375,7 +378,7 @@ public boolean updateQueryWithJson(final String json) throws SQLException { throw new RuntimeException(e); } - throwIfError(response.getState()); + ClientExceptionUtil.throwIfError(response.getState()); return true; } @@ -396,7 +399,7 @@ public List getRunningQueryList() throws SQLExcepti } @Override - public List getFinishedQueryList() throws SQLException { + public List getFinishedQueryList() { final BlockingInterface stub = conn.getTMStub(); @@ -407,7 +410,7 @@ public List getFinishedQueryList() throws SQLExcept throw new RuntimeException(e); } - throwIfError(res.getState()); + ensureOk(res.getState()); return res.getQueryListList(); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java index 59564f4ab7..b5158e4f99 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java @@ -28,6 +28,7 @@ import org.apache.tajo.auth.UserRoleInfo; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; import org.apache.tajo.client.v2.exception.ClientConnectionException; +import org.apache.tajo.exception.NoSuchSessionVariableException; import org.apache.tajo.exception.SQLExceptionUtil; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.ClientProtos.SessionUpdateResponse; @@ -201,7 +202,7 @@ public String getCurrentDatabase() { return response.getValue(); } - public Map updateSessionVariables(final Map variables) throws SQLException { + public Map updateSessionVariables(final Map variables) { NettyClientBase client = getTajoMasterConnection(); checkSessionAndGet(client); @@ -220,15 +221,12 @@ public Map updateSessionVariables(final Map vari throw new RuntimeException(e); } - if (isSuccess(response.getState())) { - updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); - return Collections.unmodifiableMap(sessionVarsCache); - } else { - throw toSQLException(response.getState()); - } + ensureOk(response.getState()); + updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); + return Collections.unmodifiableMap(sessionVarsCache); } - public Map unsetSessionVariables(final List variables) throws SQLException { + public Map unsetSessionVariables(final List variables) throws NoSuchSessionVariableException { final BlockingInterface stub = getTMStub(); final UpdateSessionVariableRequest request = UpdateSessionVariableRequest.newBuilder() @@ -243,12 +241,13 @@ public Map unsetSessionVariables(final List variables) t throw new RuntimeException(e); } - if (isSuccess(response.getState())) { - updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); - return Collections.unmodifiableMap(sessionVarsCache); - } else { - throw toSQLException(response.getState()); + if (isThisError(response.getState(), NO_SUCH_SESSION_VARIABLE)) { + throw new NoSuchSessionVariableException(response.getState()); } + + ensureOk(response.getState()); + updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); + return Collections.unmodifiableMap(sessionVarsCache); } void updateSessionVarsCache(Map variables) { @@ -258,7 +257,7 @@ void updateSessionVarsCache(Map variables) { } } - public String getSessionVariable(final String varname) throws SQLException { + public String getSessionVariable(final String varname) throws NoSuchSessionVariableException { synchronized (sessionVarsCache) { // If a desired variable is client side one and exists in the cache, immediately return the variable. if (sessionVarsCache.containsKey(varname)) { @@ -270,35 +269,41 @@ public String getSessionVariable(final String varname) throws SQLException { checkSessionAndGet(client); BlockingInterface stub = client.getStub(); - + StringResponse response; try { - return stub.getSessionVariable(null, getSessionedString(varname)).getValue(); + response = stub.getSessionVariable(null, getSessionedString(varname)); } catch (ServiceException e) { throw new RuntimeException(e); } + + if (isThisError(response.getState(), NO_SUCH_SESSION_VARIABLE)) { + throw new NoSuchSessionVariableException(response.getState()); + } + + ensureOk(response.getState()); + return response.getValue(); } - public Boolean existSessionVariable(final String varname) throws SQLException { + public Boolean existSessionVariable(final String varname) { + ReturnState state; try { final BlockingInterface stub = getTMStub(); - ReturnState state = stub.existSessionVariable(null, getSessionedString(varname)); - - if (isThisError(state, NO_SUCH_SESSION_VARIABLE)) { - return false; - } else if (isError(state)){ - throw SQLExceptionUtil.toSQLException(state); - } - - return isSuccess(state); - + state = stub.existSessionVariable(null, getSessionedString(varname)); } catch (ServiceException e) { throw new RuntimeException(e); } + + if (isThisError(state, NO_SUCH_SESSION_VARIABLE)) { + return false; + } + + ensureOk(state); + return true; } - public Map getAllSessionVariables() throws SQLException { + public Map getAllSessionVariables() { NettyClientBase client = getTajoMasterConnection(); checkSessionAndGet(client); @@ -310,7 +315,7 @@ public Map getAllSessionVariables() throws SQLException { throw new RuntimeException(e); } - throwIfError(response.getState()); + ensureOk(response.getState()); return ProtoUtil.convertToMap(response.getValue()); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java index 5acb3eb549..ae56aec1fd 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java @@ -26,8 +26,10 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.catalog.exception.*; import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.ipc.ClientProtos.*; import org.apache.tajo.jdbc.TajoMemoryResultSet; import org.apache.tajo.service.ServiceTracker; @@ -89,7 +91,7 @@ public TajoClientImpl(ServiceTracker serviceTracker, @Nullable String baseDataba // QueryClient wrappers /*------------------------------------------------------------------------*/ - public void closeQuery(final QueryId queryId) throws SQLException { + public void closeQuery(final QueryId queryId) { queryClient.closeQuery(queryId); } @@ -101,15 +103,15 @@ public SubmitQueryResponse executeQuery(final String sql) { return queryClient.executeQuery(sql); } - public SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException { + public SubmitQueryResponse executeQueryWithJson(final String json) { return queryClient.executeQueryWithJson(json); } - public ResultSet executeQueryAndGetResult(final String sql) throws SQLException { + public ResultSet executeQueryAndGetResult(final String sql) throws TajoException { return queryClient.executeQueryAndGetResult(sql); } - public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException { + public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException { return queryClient.executeJsonQueryAndGetResult(json); } @@ -133,11 +135,11 @@ public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int return queryClient.fetchNextQueryResult(queryId, fetchRowNum); } - public boolean updateQuery(final String sql) { + public boolean updateQuery(final String sql) throws TajoException { return queryClient.updateQuery(sql); } - public boolean updateQueryWithJson(final String json) throws SQLException { + public boolean updateQueryWithJson(final String json) throws TajoException { return queryClient.updateQueryWithJson(json); } @@ -149,7 +151,7 @@ public List getRunningQueryList() throws SQLException { return queryClient.getRunningQueryList(); } - public List getFinishedQueryList() throws SQLException { + public List getFinishedQueryList() { return queryClient.getFinishedQueryList(); } @@ -177,54 +179,56 @@ public int getMaxRows() { // CatalogClient wrappers /*------------------------------------------------------------------------*/ - public boolean createDatabase(final String databaseName) throws SQLException { + public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException { return catalogClient.createDatabase(databaseName); } - public boolean existDatabase(final String databaseName) throws SQLException { + public boolean existDatabase(final String databaseName) { return catalogClient.existDatabase(databaseName); } - public boolean dropDatabase(final String databaseName) throws SQLException { + public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException { return catalogClient.dropDatabase(databaseName); } - public List getAllDatabaseNames() throws SQLException { + public List getAllDatabaseNames() { return catalogClient.getAllDatabaseNames(); } - public boolean existTable(final String tableName) throws SQLException { + public boolean existTable(final String tableName) { return catalogClient.existTable(tableName); } public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, - final TableMeta meta) throws SQLException { + final TableMeta meta) throws DuplicateTableException { return catalogClient.createExternalTable(tableName, schema, path, meta); } public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, final TableMeta meta, final PartitionMethodDesc partitionMethodDesc) - throws SQLException { + throws DuplicateTableException { return catalogClient.createExternalTable(tableName, schema, path, meta, partitionMethodDesc); } - public boolean dropTable(final String tableName) throws SQLException { + public boolean dropTable(final String tableName) throws UndefinedTableException { return dropTable(tableName, false); } - public boolean dropTable(final String tableName, final boolean purge) throws SQLException { + public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException { return catalogClient.dropTable(tableName, purge); } - public List getTableList(@Nullable final String databaseName) throws SQLException { + public List getTableList(@Nullable final String databaseName) { return catalogClient.getTableList(databaseName); } - public TableDesc getTableDesc(final String tableName) throws SQLException { + public TableDesc getTableDesc(final String tableName) throws UndefinedTableException { return catalogClient.getTableDesc(tableName); } - public List getFunctions(final String functionName) throws SQLException { + public List getFunctions(final String functionName) + throws AmbiguousFunctionException, UndefinedFunctionException { + return catalogClient.getFunctions(functionName); } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java index 68d7c06edd..0cdb68bb6e 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java @@ -25,10 +25,7 @@ import org.apache.tajo.annotation.ThreadSafe; import org.apache.tajo.auth.UserRoleInfo; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; -import org.apache.tajo.client.DummyServiceTracker; -import org.apache.tajo.client.QueryClientImpl; -import org.apache.tajo.client.SessionConnection; -import org.apache.tajo.client.TajoClientUtil; +import org.apache.tajo.client.*; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.UnimplementedException; @@ -86,7 +83,7 @@ public ResultSet executeSQL(String sql) throws TajoException { @Override public QueryFuture executeSQLAsync(String sql) throws TajoException { ClientProtos.SubmitQueryResponse response = queryClient.executeQuery(sql); - ensureOk(response.getState()); + ClientExceptionUtil.throwIfError(response.getState()); QueryId queryId = new QueryId(response.getQueryId()); diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java b/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java index bc01cb9f9d..d97c478f5b 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java @@ -21,6 +21,11 @@ import org.apache.commons.logging.Log; import org.apache.hadoop.util.StringUtils; import org.apache.tajo.common.TajoDataTypes.DataType; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; + +import java.sql.SQLException; + +import static org.apache.tajo.exception.ReturnStateUtil.isError; public class ExceptionUtil { diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java b/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java new file mode 100644 index 0000000000..c9ed78d946 --- /dev/null +++ b/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java @@ -0,0 +1,33 @@ +/** + * 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.exception; + +import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; + +public class NoSuchSessionVariableException extends TajoException { + + public NoSuchSessionVariableException(PrimitiveProtos.ReturnState state) { + super(state); + } + + public NoSuchSessionVariableException(String variableName) { + super(Errors.ResultCode.NO_SUCH_SESSION_VARIABLE, variableName); + } +} diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java b/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java index 10b5aff985..deeb7f9ce7 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java @@ -19,6 +19,7 @@ package org.apache.tajo.exception; import com.google.common.collect.Maps; +import org.apache.log4j.spi.ErrorCode; import org.apache.tajo.error.Errors.ResultCode; import org.apache.tajo.exception.ErrorMessages; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; @@ -54,27 +55,34 @@ public static void throwIfError(ReturnState state) throws SQLException { } } - public static SQLException toSQLException(ReturnState state) throws SQLException { - - if (SQLSTATES.containsKey(state.getReturnCode())) { + private static SQLException toSQLException(ResultCode code, String message) throws SQLException { + if (SQLSTATES.containsKey(code)) { return new SQLException( - state.getMessage(), - SQLSTATES.get(state.getReturnCode()), - state.getReturnCode().getNumber() + message, + SQLSTATES.get(code), + code.getNumber() ); } else { // If there is no SQLState corresponding to error code, // It will make SQLState '42000' (Syntax Error Or Access Rule Violation). return new SQLException( - state.getMessage(), + message, "42000", ResultCode.SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION_VALUE ); } } + public static SQLException toSQLException(TajoException e) throws SQLException { + return toSQLException(e.getErrorCode(), e.getMessage()); + } + + public static SQLException toSQLException(ReturnState state) throws SQLException { + return toSQLException(state.getReturnCode(), state.getMessage()); + } + public static SQLException makeSQLException(ResultCode code, String ...args) { if (SQLSTATES.containsKey(code)) { return new SQLException( diff --git a/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java b/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java index b4a28dbf28..90c95a139f 100644 --- a/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java +++ b/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java @@ -28,6 +28,7 @@ import org.apache.tajo.client.TajoClientImpl; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.conf.TajoConf.ConfVars; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.service.ServiceTracker; import org.apache.tajo.service.ServiceTrackerFactory; import org.apache.tajo.util.FileUtil; @@ -91,7 +92,7 @@ protected void loadQueries(String dir) throws IOException { public abstract void loadQueries() throws IOException; - public abstract void loadTables() throws SQLException; + public abstract void loadTables() throws TajoException; public String [] getTableNames() { return schemas.keySet().toArray(new String[schemas.size()]); diff --git a/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java b/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java index 91a3b66bbe..9739767f7b 100644 --- a/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java +++ b/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java @@ -32,6 +32,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.StoreType; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.common.TajoDataTypes.Type; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.storage.StorageConstants; import java.io.File; @@ -192,7 +193,7 @@ public void loadQueries() throws IOException { loadQueries(BENCHMARK_DIR); } - public void loadTables() throws SQLException { + public void loadTables() throws TajoException { loadTable(LINEITEM); loadTable(CUSTOMER); loadTable(CUSTOMER_PARTS); @@ -206,7 +207,7 @@ public void loadTables() throws SQLException { } - public void loadTable(String tableName) throws SQLException { + public void loadTable(String tableName) throws TajoException { TableMeta meta = CatalogUtil.newTableMeta("TEXT"); meta.putOption(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER); diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java index d9712c9590..7e5d15f732 100644 --- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java +++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java @@ -29,6 +29,9 @@ import org.apache.tajo.SessionVars; import org.apache.tajo.algebra.JoinType; import org.apache.tajo.catalog.*; +import org.apache.tajo.catalog.exception.AmbiguousFunctionException; +import org.apache.tajo.catalog.exception.CatalogException; +import org.apache.tajo.catalog.exception.UndefinedFunctionException; import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.common.TajoDataTypes; @@ -37,10 +40,7 @@ import org.apache.tajo.engine.planner.global.rewriter.GlobalPlanRewriteEngine; import org.apache.tajo.engine.planner.global.rewriter.GlobalPlanRewriteRuleProvider; import org.apache.tajo.engine.query.QueryContext; -import org.apache.tajo.exception.InternalException; -import org.apache.tajo.exception.TajoException; -import org.apache.tajo.exception.TajoInternalError; -import org.apache.tajo.exception.UnimplementedException; +import org.apache.tajo.exception.*; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.PlanningException; import org.apache.tajo.plan.Target; @@ -346,31 +346,32 @@ private void buildJoinPlanWithUnionChannel(GlobalPlanContext context, JoinNode j } } - private AggregationFunctionCallEval createSumFunction(EvalNode[] args) throws InternalException { - FunctionDesc functionDesc = getCatalog().getFunction("sum", CatalogProtos.FunctionType.AGGREGATION, + private AggregationFunctionCallEval createSumFunction(EvalNode[] args) throws CatalogException { + FunctionDesc functionDesc = null; + functionDesc = getCatalog().getFunction("sum", CatalogProtos.FunctionType.AGGREGATION, args[0].getValueType()); return new AggregationFunctionCallEval(functionDesc, args); } - private AggregationFunctionCallEval createCountFunction(EvalNode [] args) throws InternalException { + private AggregationFunctionCallEval createCountFunction(EvalNode [] args) throws CatalogException { FunctionDesc functionDesc = getCatalog().getFunction("count", CatalogProtos.FunctionType.AGGREGATION, args[0].getValueType()); return new AggregationFunctionCallEval(functionDesc, args); } - private AggregationFunctionCallEval createCountRowFunction(EvalNode[] args) throws InternalException { + private AggregationFunctionCallEval createCountRowFunction(EvalNode[] args) throws CatalogException { FunctionDesc functionDesc = getCatalog().getFunction("count", CatalogProtos.FunctionType.AGGREGATION, new TajoDataTypes.DataType[]{}); return new AggregationFunctionCallEval(functionDesc, args); } - private AggregationFunctionCallEval createMaxFunction(EvalNode [] args) throws InternalException { + private AggregationFunctionCallEval createMaxFunction(EvalNode [] args) throws CatalogException { FunctionDesc functionDesc = getCatalog().getFunction("max", CatalogProtos.FunctionType.AGGREGATION, args[0].getValueType()); return new AggregationFunctionCallEval(functionDesc, args); } - private AggregationFunctionCallEval createMinFunction(EvalNode [] args) throws InternalException { + private AggregationFunctionCallEval createMinFunction(EvalNode [] args) throws CatalogException { FunctionDesc functionDesc = getCatalog().getFunction("min", CatalogProtos.FunctionType.AGGREGATION, args[0].getValueType()); return new AggregationFunctionCallEval(functionDesc, args); @@ -428,57 +429,53 @@ public RewrittenFunctions(int firstStageEvalNum) { */ private RewrittenFunctions rewriteAggFunctionsForDistinctAggregation(GlobalPlanContext context, AggregationFunctionCallEval function) - throws PlanningException { + throws TajoException { LogicalPlan plan = context.plan.getLogicalPlan(); RewrittenFunctions rewritten = null; - try { - if (function.getName().equalsIgnoreCase("count")) { - rewritten = new RewrittenFunctions(1); - - if (function.getArgs().length == 0) { - rewritten.firstStageEvals[0] = createCountRowFunction(function.getArgs()); - } else { - rewritten.firstStageEvals[0] = createCountFunction(function.getArgs()); - } - String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); - FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); - rewritten.firstStageTargets[0] = new Target(fieldEval); - rewritten.secondStageEvals = createSumFunction(new EvalNode[] {fieldEval}); - } else if (function.getName().equalsIgnoreCase("sum")) { - rewritten = new RewrittenFunctions(1); - - rewritten.firstStageEvals[0] = createSumFunction(function.getArgs()); - String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); - FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); - rewritten.firstStageTargets[0] = new Target(fieldEval); - rewritten.secondStageEvals = createSumFunction(new EvalNode[] {fieldEval}); - - } else if (function.getName().equals("max")) { - rewritten = new RewrittenFunctions(1); - - rewritten.firstStageEvals[0] = createMaxFunction(function.getArgs()); - String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); - FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); - rewritten.firstStageTargets[0] = new Target(fieldEval); - rewritten.secondStageEvals = createMaxFunction(new EvalNode[]{fieldEval}); - - } else if (function.getName().equals("min")) { - - rewritten = new RewrittenFunctions(1); - - rewritten.firstStageEvals[0] = createMinFunction(function.getArgs()); - String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); - FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); - rewritten.firstStageTargets[0] = new Target(fieldEval); - rewritten.secondStageEvals = createMinFunction(new EvalNode[]{fieldEval}); + if (function.getName().equalsIgnoreCase("count")) { + rewritten = new RewrittenFunctions(1); + if (function.getArgs().length == 0) { + rewritten.firstStageEvals[0] = createCountRowFunction(function.getArgs()); } else { - throw new PlanningException("Cannot support a mix of other functions"); + rewritten.firstStageEvals[0] = createCountFunction(function.getArgs()); } - } catch (InternalException e) { - LOG.error(e, e); + String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); + FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); + rewritten.firstStageTargets[0] = new Target(fieldEval); + rewritten.secondStageEvals = createSumFunction(new EvalNode[]{fieldEval}); + } else if (function.getName().equalsIgnoreCase("sum")) { + rewritten = new RewrittenFunctions(1); + + rewritten.firstStageEvals[0] = createSumFunction(function.getArgs()); + String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); + FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); + rewritten.firstStageTargets[0] = new Target(fieldEval); + rewritten.secondStageEvals = createSumFunction(new EvalNode[]{fieldEval}); + + } else if (function.getName().equals("max")) { + rewritten = new RewrittenFunctions(1); + + rewritten.firstStageEvals[0] = createMaxFunction(function.getArgs()); + String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); + FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); + rewritten.firstStageTargets[0] = new Target(fieldEval); + rewritten.secondStageEvals = createMaxFunction(new EvalNode[]{fieldEval}); + + } else if (function.getName().equals("min")) { + + rewritten = new RewrittenFunctions(1); + + rewritten.firstStageEvals[0] = createMinFunction(function.getArgs()); + String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]); + FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType()); + rewritten.firstStageTargets[0] = new Target(fieldEval); + rewritten.secondStageEvals = createMinFunction(new EvalNode[]{fieldEval}); + + } else { + throw new UnsupportedException("Cannot support a mix of other functions"); } return rewritten; @@ -523,7 +520,7 @@ private RewrittenFunctions rewriteAggFunctionsForDistinctAggregation(GlobalPlanC */ private ExecutionBlock buildGroupByIncludingDistinctFunctionsMultiStage(GlobalPlanContext context, ExecutionBlock latestExecBlock, - GroupbyNode groupbyNode) throws PlanningException { + GroupbyNode groupbyNode) throws TajoException { Column [] originalGroupingColumns = groupbyNode.getGroupingColumns(); LinkedHashSet firstStageGroupingColumns = diff --git a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java index 0a4ac2c46f..ee4f432115 100644 --- a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java +++ b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java @@ -38,6 +38,7 @@ import org.apache.tajo.catalog.CatalogService; import org.apache.tajo.catalog.FunctionDesc; import org.apache.tajo.catalog.LocalCatalogWrapper; +import org.apache.tajo.catalog.exception.DuplicateDatabaseException; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.conf.TajoConf.ConfVars; import org.apache.tajo.engine.function.FunctionLoader; @@ -369,7 +370,7 @@ private void writeSystemConf() throws IOException { } } - private void checkBaseTBSpaceAndDatabase() throws IOException { + private void checkBaseTBSpaceAndDatabase() throws IOException, DuplicateDatabaseException { if (!catalog.existTablespace(DEFAULT_TABLESPACE_NAME)) { catalog.createTablespace(DEFAULT_TABLESPACE_NAME, context.getConf().getVar(ConfVars.WAREHOUSE_DIR)); } else { diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java index f6bb4f7c28..281ca2472c 100644 --- a/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java +++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java @@ -36,6 +36,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.PartitionKeyProto; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.engine.query.QueryContext; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.master.TajoMaster; import org.apache.tajo.plan.LogicalPlan; @@ -67,7 +68,9 @@ public DDLExecutor(TajoMaster.MasterContext context) { this.catalog = context.getCatalog(); } - public boolean execute(QueryContext queryContext, LogicalPlan plan) throws IOException { + public boolean execute(QueryContext queryContext, LogicalPlan plan) + throws IOException, TajoException { + LogicalNode root = ((LogicalRootNode) plan.getRootBlock().getRoot()).getChild(); switch (root.getType()) { @@ -142,7 +145,7 @@ public static void alterTablespace(final TajoMaster.MasterContext context, final //-------------------------------------------------------------------------- public boolean createDatabase(@Nullable QueryContext queryContext, String databaseName, @Nullable String tablespace, - boolean ifNotExists) throws IOException { + boolean ifNotExists) throws IOException, DuplicateDatabaseException { String tablespaceName; if (tablespace == null) { @@ -172,7 +175,9 @@ public boolean createDatabase(@Nullable QueryContext queryContext, String databa return true; } - public boolean dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) { + public boolean dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) + throws UndefinedDatabaseException { + boolean exists = catalog.existDatabase(databaseName); if(!exists) { if (ifExists) { // DROP DATABASE IF EXISTS @@ -197,7 +202,7 @@ public boolean dropDatabase(QueryContext queryContext, String databaseName, bool // Table Section //-------------------------------------------------------------------------- private TableDesc createTable(QueryContext queryContext, CreateTableNode createTable, boolean ifNotExists) - throws IOException { + throws IOException, DuplicateTableException { TableMeta meta; if (createTable.hasOptions()) { @@ -231,7 +236,7 @@ public TableDesc createTable(QueryContext queryContext, @Nullable URI uri, boolean isExternal, @Nullable PartitionMethodDesc partitionDesc, - boolean ifNotExists) throws IOException { + boolean ifNotExists) throws IOException, DuplicateTableException { String databaseName; String simpleTableName; @@ -300,7 +305,8 @@ public TableDesc createTable(QueryContext queryContext, * @param tableName to be dropped * @param purge Remove all data if purge is true. */ - public boolean dropTable(QueryContext queryContext, String tableName, boolean ifExists, boolean purge) { + public boolean dropTable(QueryContext queryContext, String tableName, boolean ifExists, boolean purge) + throws UndefinedTableException { String databaseName; String simpleTableName; @@ -343,7 +349,8 @@ public boolean dropTable(QueryContext queryContext, String tableName, boolean if * Truncate table a given table */ public void truncateTable(final QueryContext queryContext, final TruncateTableNode truncateTableNode) - throws IOException { + throws IOException, UndefinedTableException { + List tableNames = truncateTableNode.getTableNames(); final CatalogService catalog = context.getCatalog(); @@ -401,7 +408,10 @@ public void truncateTable(final QueryContext queryContext, final TruncateTableNo * @throws IOException */ public void alterTable(TajoMaster.MasterContext context, final QueryContext queryContext, - final AlterTableNode alterTable) throws IOException { + final AlterTableNode alterTable) + throws IOException, UndefinedTableException, DuplicateTableException, DuplicateColumnException, + DuplicatePartitionException, UndefinedPartitionException { + final CatalogService catalog = context.getCatalog(); final String tableName = alterTable.getTableName(); diff --git a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java index 24534b0cff..630b1e99c4 100644 --- a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java +++ b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java @@ -360,7 +360,7 @@ public void run() { if (queryId != null) { try { tajoClient.closeQuery(queryId); - } catch (SQLException e) { + } catch (Throwable e) { LOG.warn(e); } } diff --git a/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java b/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java index eae9e8c10d..f084138305 100644 --- a/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java +++ b/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java @@ -19,7 +19,6 @@ package org.apache.tajo; import com.google.common.base.Preconditions; -import com.google.protobuf.ServiceException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -31,12 +30,12 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; import org.apache.tajo.catalog.TableMeta; -import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.catalog.statistics.TableStats; import org.apache.tajo.client.TajoClient; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.engine.planner.global.MasterPlan; import org.apache.tajo.engine.query.QueryContext; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.session.Session; import org.apache.tajo.util.CommonTestingUtil; import org.apache.tajo.util.FileUtil; @@ -47,7 +46,6 @@ import java.io.IOException; import java.net.URL; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.UUID; public class LocalTajoTestingUtility { @@ -140,7 +138,7 @@ public TajoTestingCluster getTestingCluster() { return util; } - public ResultSet execute(String query) throws IOException, SQLException { + public ResultSet execute(String query) throws TajoException { return client.executeQueryAndGetResult(query); } diff --git a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java index 3fcb15ef64..a71a1484c9 100644 --- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java +++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java @@ -29,6 +29,8 @@ import org.apache.tajo.catalog.CatalogService; import org.apache.tajo.catalog.CatalogUtil; import org.apache.tajo.catalog.TableDesc; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.cli.tsql.ParsedResult; import org.apache.tajo.cli.tsql.SimpleParser; import org.apache.tajo.client.TajoClient; @@ -199,7 +201,7 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws SQLException { + public static void tearDownClass() throws Exception { for (String tableName : createdTableGlobalSet) { client.updateQuery("DROP TABLE IF EXISTS " + CatalogUtil.denormalizeIdentifier(tableName)); } @@ -704,17 +706,17 @@ public void assertTableNotExists(String tableName) throws SQLException { assertTrue(!client.existTable(tableName)); } - public void assertColumnExists(String tableName,String columnName) throws ServiceException, SQLException { + public void assertColumnExists(String tableName,String columnName) throws UndefinedTableException { TableDesc tableDesc = getTableDesc(tableName); assertTrue(tableDesc.getSchema().containsByName(columnName)); } - private TableDesc getTableDesc(String tableName) throws ServiceException, SQLException { + private TableDesc getTableDesc(String tableName) throws UndefinedTableException { return client.getTableDesc(tableName); } public void assertTablePropertyEquals(String tableName, String key, String expectedValue) - throws ServiceException, SQLException { + throws UndefinedTableException { TableDesc tableDesc = getTableDesc(tableName); assertEquals(expectedValue, tableDesc.getMeta().getOption(key)); diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java index d647db4ec3..701e880c14 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java @@ -85,7 +85,7 @@ private static Path writeTmpTable(String tableName) throws IOException { } @Test - public final void testCreateAndDropDatabases() throws SQLException { + public final void testCreateAndDropDatabases() throws TajoException { int currentNum = client.getAllDatabaseNames().size(); String prefix = CatalogUtil.normalizeIdentifier("testCreateDatabase_"); @@ -116,7 +116,7 @@ public final void testCreateAndDropDatabases() throws SQLException { } @Test - public final void testCurrentDatabase() throws IOException, SQLException, InterruptedException { + public final void testCurrentDatabase() throws IOException, TajoException, InterruptedException { int currentNum = client.getAllDatabaseNames().size(); assertEquals(TajoConstants.DEFAULT_DATABASE_NAME, client.getCurrentDatabase()); @@ -133,7 +133,7 @@ public final void testCurrentDatabase() throws IOException, SQLException, Interr } @Test - public final void testSelectDatabaseToInvalidOne() throws IOException, SQLException, InterruptedException { + public final void testSelectDatabaseToInvalidOne() throws IOException, TajoException, InterruptedException { int currentNum = client.getAllDatabaseNames().size(); assertFalse(client.existDatabase("invaliddatabase")); @@ -148,7 +148,7 @@ public final void testSelectDatabaseToInvalidOne() throws IOException, SQLExcept } @Test - public final void testDropCurrentDatabase() throws IOException, SQLException, InterruptedException { + public final void testDropCurrentDatabase() throws IOException, TajoException, InterruptedException { int currentNum = client.getAllDatabaseNames().size(); String databaseName = CatalogUtil.normalizeIdentifier("testdropcurrentdatabase"); assertTrue(client.createDatabase(databaseName)); @@ -168,7 +168,7 @@ public final void testDropCurrentDatabase() throws IOException, SQLException, In } @Test - public final void testSessionVariables() throws IOException, SQLException, InterruptedException { + public final void testSessionVariables() throws IOException, TajoException, InterruptedException { String prefixName = "key_"; String prefixValue = "val_"; @@ -214,7 +214,7 @@ public final void testSessionVariables() throws IOException, SQLException, Inter } @Test - public final void testKillQuery() throws IOException, SQLException, InterruptedException { + public final void testKillQuery() throws IOException, TajoException, InterruptedException { ClientProtos.SubmitQueryResponse res = client.executeQuery("select sleep(1) from lineitem"); Thread.sleep(1000); QueryId queryId = new QueryId(res.getQueryId()); @@ -223,7 +223,7 @@ public final void testKillQuery() throws IOException, SQLException, InterruptedE } @Test - public final void testUpdateQuery() throws IOException, SQLException { + public final void testUpdateQuery() throws IOException, TajoException { final String tableName = CatalogUtil.normalizeIdentifier("testUpdateQuery"); Path tablePath = writeTmpTable(tableName); @@ -238,7 +238,7 @@ public final void testUpdateQuery() throws IOException, SQLException { } @Test - public final void testCreateAndDropExternalTable() throws IOException, SQLException { + public final void testCreateAndDropExternalTable() throws IOException, TajoException { final String tableName = "testCreateAndDropExternalTable"; Path tablePath = writeTmpTable(tableName); LOG.error("Full path:" + tablePath.toUri().getRawPath()); @@ -256,7 +256,7 @@ public final void testCreateAndDropExternalTable() throws IOException, SQLExcept } @Test - public final void testCreateAndPurgeExternalTable() throws IOException, SQLException { + public final void testCreateAndPurgeExternalTable() throws IOException, TajoException { final String tableName = "testCreateAndPurgeExternalTable"; Path tablePath = writeTmpTable(tableName); LOG.error("Full path:" + tablePath.toUri().getRawPath()); @@ -274,7 +274,7 @@ public final void testCreateAndPurgeExternalTable() throws IOException, SQLExcep } @Test - public final void testCreateAndDropExternalTableByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropExternalTableByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndDropExternalTableByExecuteQuery"); @@ -294,7 +294,7 @@ public final void testCreateAndDropExternalTableByExecuteQuery() throws IOExcept } @Test - public final void testCreateAndPurgeExternalTableByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndPurgeExternalTableByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndPurgeExternalTableByExecuteQuery"); @@ -314,7 +314,7 @@ public final void testCreateAndPurgeExternalTableByExecuteQuery() throws IOExcep } @Test - public final void testCreateAndDropTableByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropTableByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndDropTableByExecuteQuery"); @@ -335,7 +335,7 @@ public final void testCreateAndDropTableByExecuteQuery() throws IOException, SQL } @Test - public final void testCreateAndPurgeTableByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndPurgeTableByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndPurgeTableByExecuteQuery"); @@ -356,7 +356,7 @@ public final void testCreateAndPurgeTableByExecuteQuery() throws IOException, SQ } @Test - public final void testDDLByExecuteQuery() throws IOException, SQLException { + public final void testDDLByExecuteQuery() throws IOException, TajoException { final String tableName = CatalogUtil.normalizeIdentifier("testDDLByExecuteQuery"); Path tablePath = writeTmpTable(tableName); @@ -369,7 +369,7 @@ public final void testDDLByExecuteQuery() throws IOException, SQLException { } @Test - public final void testGetTableList() throws IOException, SQLException { + public final void testGetTableList() throws IOException, TajoException { String tableName1 = "GetTableList1".toLowerCase(); String tableName2 = "GetTableList2".toLowerCase(); @@ -389,7 +389,7 @@ public final void testGetTableList() throws IOException, SQLException { Log LOG = LogFactory.getLog(TestTajoClient.class); @Test - public final void testGetTableDesc() throws IOException, SQLException { + public final void testGetTableDesc() throws IOException, TajoException { final String tableName1 = CatalogUtil.normalizeIdentifier("table3"); Path tablePath = writeTmpTable(tableName1); LOG.error("Full path:" + tablePath.toUri().getRawPath()); @@ -409,7 +409,7 @@ public final void testGetTableDesc() throws IOException, SQLException { } //@Test - public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = "testCreateAndDropTablePartitionedHash1ByExecuteQuery"; @@ -432,7 +432,7 @@ public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() throws } //@Test - public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = "testCreateAndPurgeTablePartitionedHash1ByExecuteQuery"; @@ -455,7 +455,7 @@ public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() throws } //@Test - public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = "testCreateAndDropTablePartitionedHash2ByExecuteQuery"; @@ -478,7 +478,7 @@ public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() throws } //@Test - public final void testCreateAndDropTablePartitionedListByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropTablePartitionedListByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = "testCreateAndDropTablePartitionedListByExecuteQuery"; @@ -502,7 +502,7 @@ public final void testCreateAndDropTablePartitionedListByExecuteQuery() throws I } //@Test - public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = "testCreateAndDropTablePartitionedRangeByExecuteQuery"; @@ -527,7 +527,7 @@ public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() throws } @Test - public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOException, SQLException { + public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = "testFailCreateTablePartitionedOtherExceptColumn"; @@ -571,7 +571,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc } @Test - public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() throws IOException, SQLException { + public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() throws IOException, TajoException { TajoConf conf = cluster.getConfiguration(); final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndDropTablePartitionedColumnByExecuteQuery"); @@ -593,7 +593,7 @@ public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() throws } @Test - public final void testGetFunctions() throws IOException, SQLException { + public final void testGetFunctions() throws IOException, TajoException { Collection catalogFunctions = cluster.getMaster().getCatalog().getFunctions(); String functionName = "sum"; int numFunctions = 0; @@ -614,7 +614,7 @@ public final void testGetFunctions() throws IOException, SQLException { } @Test - public final void testGetFinishedQueryList() throws IOException, SQLException { + public final void testGetFinishedQueryList() throws SQLException, TajoException { final String tableName = CatalogUtil.normalizeIdentifier("testGetFinishedQueryList"); String sql = "create table " + tableName + " (deptname text, score int4)"; diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java index d43f61c4f6..6d49369f11 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java @@ -21,7 +21,9 @@ import net.jcip.annotations.NotThreadSafe; import org.apache.tajo.TajoTestingCluster; import org.apache.tajo.TpchTestBase; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.error.Errors; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -49,17 +51,17 @@ public static void tearDown() throws Exception { } @Test - public final void testCreateDatabase() throws SQLException { + public final void testCreateDatabase() throws TajoException { assertFalse(client.createDatabase("default")); // duplicate database } @Test - public final void testDropDatabase() throws SQLException { + public final void testDropDatabase() throws TajoException { assertFalse(client.dropDatabase("unknown-database")); // unknown database } @Test - public final void testDropTable() throws SQLException { + public final void testDropTable() throws UndefinedTableException { assertFalse(client.dropTable("unknown-table")); // unknown table } diff --git a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java index 0e1b98d87e..bc4565a63d 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java @@ -19,7 +19,9 @@ package org.apache.tajo.client.v2; import org.apache.tajo.QueryTestCaseBase; +import org.apache.tajo.catalog.exception.DuplicateDatabaseException; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.exception.TajoException; import org.apache.tajo.service.ServiceTracker; import org.apache.tajo.service.ServiceTrackerFactory; @@ -118,6 +120,18 @@ public void testExecuteQueryType3() throws TajoException, IOException, SQLExcept if (res != null) { res.close(); } + + clientv2.executeUpdate("drop database IF EXISTS client_v2_types3"); } } + + @Test(expected = DuplicateDatabaseException.class) + public void testErrorOnExecuteUpdate() throws TajoException, IOException, SQLException { + clientv2.executeUpdate("create database default"); + } + + @Test(expected = UndefinedTableException.class) + public void testErrorOnExecuteQuery() throws TajoException, IOException, SQLException { + clientv2.executeQuery("select * from unknown_table"); + } } diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java b/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java index d86081af8a..da59e8a56b 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java @@ -23,10 +23,9 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - public class TestEvalCodeGenerator extends ExprTestBase { private static Schema schema; static { @@ -44,7 +43,7 @@ public class TestEvalCodeGenerator extends ExprTestBase { } @Test - public void testArithmetic() throws IOException { + public void testArithmetic() throws TajoException { testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select 1+1;", new String [] {"2"}); testEval(schema, "table1", "0,1,2,3,4.5,5.5", "select col1 + col2 from table1;", new String [] {"3"}); testEval(schema, "table1", "0,1,2,3,4.5,5.5", "select col1 + col3 from table1;", new String [] {"4"}); @@ -53,7 +52,7 @@ public void testArithmetic() throws IOException { } @Test - public void testGetField() throws IOException { + public void testGetField() throws TajoException { testEval(schema, "table1", "0,1,2,3,4.5,5.5,F6", "select col1 from table1;", new String [] {"1"}); testEval(schema, "table1", "0,1,2,3,4.5,5.5,F6", "select col2 from table1;", new String [] {"2"}); testEval(schema, "table1", "0,1,2,3,4.5,5.5,F6", "select col3 from table1;", new String [] {"3"}); @@ -64,7 +63,7 @@ public void testGetField() throws IOException { } @Test - public void testNullHandling() throws IOException { + public void testNullHandling() throws TajoException { schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -104,7 +103,7 @@ public void testNullHandling() throws IOException { } @Test - public void testComparison() throws IOException { + public void testComparison() throws TajoException { Schema inetSchema = new Schema(); inetSchema.addColumn("addr1", TajoDataTypes.Type.INET4); inetSchema.addColumn("addr2", TajoDataTypes.Type.INET4); @@ -160,7 +159,7 @@ public void testComparison() throws IOException { } @Test - public void testBetweenAsymmetric() throws IOException { + public void testBetweenAsymmetric() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TajoDataTypes.Type.INT4); schema.addColumn("col2", TajoDataTypes.Type.INT4); @@ -194,7 +193,7 @@ public void testBetweenAsymmetric() throws IOException { } @Test - public void testBetweenSymmetric() throws IOException { + public void testBetweenSymmetric() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TajoDataTypes.Type.INT4); schema.addColumn("col2", TajoDataTypes.Type.INT4); @@ -229,7 +228,7 @@ public void testBetweenSymmetric() throws IOException { } @Test - public void testUnary() throws IOException { + public void testUnary() throws TajoException { schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -266,7 +265,7 @@ public void testUnary() throws IOException { } @Test - public void testAndOr() throws IOException { + public void testAndOr() throws TajoException { testSimpleEval("select true or (false or false) or false;", new String[] {"t"}); testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select true and true;", new String [] {"t"}); @@ -289,7 +288,7 @@ public void testAndOr() throws IOException { } @Test - public void testFunction() throws IOException { + public void testFunction() throws TajoException { testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select upper('abc');", new String [] {"ABC"}); testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select upper('bbc');", new String [] {"BBC"}); testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select upper('chs');", new String [] {"CHS"}); @@ -298,7 +297,7 @@ public void testFunction() throws IOException { } @Test - public void testStringConcat() throws IOException { + public void testStringConcat() throws TajoException { testSimpleEval("select length('123456') as col1 ", new String[]{"6"}); testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select 'abc' || 'bbc'", new String [] {"abcbbc"}); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java index 762971174b..b18bd691ac 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java @@ -35,6 +35,7 @@ import org.apache.tajo.engine.function.FunctionLoader; import org.apache.tajo.engine.json.CoreGsonHelper; import org.apache.tajo.engine.parser.SQLAnalyzer; +import org.apache.tajo.engine.query.QueryContext; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.function.FunctionSignature; @@ -44,8 +45,6 @@ import org.apache.tajo.plan.expr.EvalNode; import org.apache.tajo.plan.serder.EvalNodeDeserializer; import org.apache.tajo.plan.serder.EvalNodeSerializer; -import org.apache.tajo.engine.query.QueryContext; -import org.apache.tajo.catalog.SchemaUtil; import org.apache.tajo.plan.serder.PlanProto; import org.apache.tajo.plan.verifier.LogicalPlanVerifier; import org.apache.tajo.plan.verifier.PreLogicalPlanVerifier; @@ -68,9 +67,7 @@ import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME; import static org.apache.tajo.TajoConstants.DEFAULT_TABLESPACE_NAME; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public class ExprTestBase { private static TajoTestingCluster util; @@ -180,46 +177,46 @@ private static Target[] getRawTargets(QueryContext context, String query, boolea return targets; } - public void testSimpleEval(String query, String [] expected) throws IOException { + public void testSimpleEval(String query, String [] expected) throws TajoException { testEval(null, null, null, query, expected); } - public void testSimpleEval(OverridableConf context, String query, String [] expected) throws IOException { + public void testSimpleEval(OverridableConf context, String query, String [] expected) throws TajoException { testEval(context, null, null, null, query, expected); } public void testSimpleEval(String query, String [] expected, boolean successOrFail) - throws IOException { + throws TajoException, IOException { testEval(null, null, null, null, query, expected, ',', successOrFail); } public void testSimpleEval(OverridableConf context, String query, String [] expected, boolean successOrFail) - throws IOException { + throws TajoException, IOException { testEval(context, null, null, null, query, expected, ',', successOrFail); } public void testEval(Schema schema, String tableName, String csvTuple, String query, String [] expected) - throws IOException { + throws TajoException { testEval(null, schema, tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null, csvTuple, query, expected, ',', true); } public void testEval(OverridableConf context, Schema schema, String tableName, String csvTuple, String query, String [] expected) - throws IOException { + throws TajoException { testEval(context, schema, tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null, csvTuple, query, expected, ',', true); } public void testEval(Schema schema, String tableName, String csvTuple, String query, - String [] expected, char delimiter, boolean condition) throws IOException { + String [] expected, char delimiter, boolean condition) throws TajoException { testEval(null, schema, tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null, csvTuple, query, expected, delimiter, condition); } public void testEval(OverridableConf context, Schema schema, String tableName, String csvTuple, String query, - String [] expected, char delimiter, boolean condition) throws IOException { + String [] expected, char delimiter, boolean condition) throws TajoException { QueryContext queryContext; if (context == null) { queryContext = LocalTajoTestingUtility.createDummyContext(conf); @@ -266,8 +263,12 @@ public void testEval(OverridableConf context, Schema schema, String tableName, S vtuple.put(i, lazyTuple.get(i)); } } - cat.createTable(new TableDesc(qualifiedTableName, inputSchema,"TEXT", - new KeyValueSet(), CommonTestingUtil.getTestDir().toUri())); + try { + cat.createTable(new TableDesc(qualifiedTableName, inputSchema,"TEXT", + new KeyValueSet(), CommonTestingUtil.getTestDir().toUri())); + } catch (IOException e) { + throw new TajoInternalError(e); + } } Target [] targets; @@ -313,6 +314,8 @@ public void testEval(OverridableConf context, Schema schema, String tableName, S } assertEquals(query, expected[i], outTupleAsChars); } + } catch (IOException e) { + throw new TajoInternalError(e); } catch (InvalidStatementException e) { assertFalse(e.getMessage(), true); } catch (TajoException e) { diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java index cde370d349..9f9d294701 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java @@ -19,15 +19,14 @@ package org.apache.tajo.engine.eval; import org.apache.tajo.exception.InvalidOperationException; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - import static org.junit.Assert.fail; public class TestIntervalType extends ExprTestBase { @Test - public void testIntervalPostgresqlCase() throws IOException { + public void testIntervalPostgresqlCase() throws TajoException { // http://www.postgresql.org/docs/8.2/static/functions-datetime.html testSimpleEval("select date '2001-09-28' + 7", new String[]{"2001-10-05"}); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java index 94d5e712e8..6c42c3e839 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java @@ -21,6 +21,7 @@ import org.apache.tajo.catalog.CatalogUtil; import org.apache.tajo.catalog.Schema; import org.apache.tajo.common.TajoDataTypes; +import org.apache.tajo.exception.TajoException; import org.junit.Test; import java.io.IOException; @@ -36,7 +37,7 @@ public class TestPredicates extends ExprTestBase { ////////////////////////////////////////////////////////////////// @Test - public void testAnd() throws IOException { + public void testAnd() throws TajoException { testSimpleEval("select true;", new String[] {"t"}); testSimpleEval("select true and true;", new String[] {"t"}); @@ -46,7 +47,7 @@ public void testAnd() throws IOException { } @Test - public void testOr() throws IOException { + public void testOr() throws TajoException { testSimpleEval("select true or true;", new String[] {"t"}); testSimpleEval("select true or false;", new String[] {"t"}); testSimpleEval("select false or true;", new String[] {"t"}); @@ -54,7 +55,7 @@ public void testOr() throws IOException { } @Test - public void testLogicalOperatorPrecedence() throws IOException { + public void testLogicalOperatorPrecedence() throws TajoException { testSimpleEval("select true or (false or false) or false;", new String[] {"t"}); testSimpleEval("select false or (true or false) or false;", new String[] {"t"}); testSimpleEval("select false or (false or true) or false;", new String[] {"t"}); @@ -77,7 +78,7 @@ public void testLogicalOperatorPrecedence() throws IOException { } @Test - public void testNot() throws IOException { + public void testNot() throws TajoException { testSimpleEval("select true;", new String[] {"t"}); testSimpleEval("select not true;", new String[] {"f"}); @@ -99,7 +100,7 @@ public void testNot() throws IOException { } @Test - public void testParenthesizedValues() throws IOException { + public void testParenthesizedValues() throws TajoException { testSimpleEval("select ((true));", new String[] {"t"}); testSimpleEval("select ((((true))));", new String[] {"t"}); testSimpleEval("select not(not(not(false)));", new String[] {"t"}); @@ -110,7 +111,7 @@ public void testParenthesizedValues() throws IOException { ////////////////////////////////////////////////////////////////// @Test - public void testComparisonEqual() throws IOException { + public void testComparisonEqual() throws TajoException { Schema schema = new Schema(); @@ -142,7 +143,7 @@ public void testComparisonEqual() throws IOException { } @Test - public void testComparisonNotEqual() throws IOException { + public void testComparisonNotEqual() throws TajoException { Schema schema1 = new Schema(); schema1.addColumn("col1", INT4); schema1.addColumn("col2", INT4); @@ -159,7 +160,7 @@ public void testComparisonNotEqual() throws IOException { } @Test - public void testComparisonLessThan() throws IOException { + public void testComparisonLessThan() throws TajoException { Schema schema1 = new Schema(); schema1.addColumn("col1", INT4); schema1.addColumn("col2", INT4); @@ -176,7 +177,7 @@ public void testComparisonLessThan() throws IOException { } @Test - public void testComparisonLessThanEqual() throws IOException { + public void testComparisonLessThanEqual() throws TajoException { Schema schema1 = new Schema(); schema1.addColumn("col1", INT4); schema1.addColumn("col2", INT4); @@ -193,7 +194,7 @@ public void testComparisonLessThanEqual() throws IOException { } @Test - public void testComparisonGreaterThan() throws IOException { + public void testComparisonGreaterThan() throws TajoException { Schema schema1 = new Schema(); schema1.addColumn("col1", INT4); schema1.addColumn("col2", INT4); @@ -210,7 +211,7 @@ public void testComparisonGreaterThan() throws IOException { } @Test - public void testComparisonGreaterThanEqual() throws IOException { + public void testComparisonGreaterThanEqual() throws TajoException { Schema schema1 = new Schema(); schema1.addColumn("col1", INT4); schema1.addColumn("col2", INT4); @@ -231,7 +232,7 @@ public void testComparisonGreaterThanEqual() throws IOException { ////////////////////////////////////////////////////////////////// @Test - public void testBetween() throws IOException { + public void testBetween() throws TajoException { Schema schema2 = new Schema(); schema2.addColumn("col1", TEXT); schema2.addColumn("col2", TEXT); @@ -255,7 +256,7 @@ public void testBetween() throws IOException { } @Test - public void testBetween2() throws IOException { // for TAJO-249 + public void testBetween2() throws TajoException { // for TAJO-249 Schema schema3 = new Schema(); schema3.addColumn("date_a", INT4); schema3.addColumn("date_b", INT4); @@ -294,7 +295,7 @@ public void testBetween2() throws IOException { // for TAJO-249 ////////////////////////////////////////////////////////////////// @Test - public void testInPredicateWithConstant() throws IOException { + public void testInPredicateWithConstant() throws TajoException { Schema schema2 = new Schema(); schema2.addColumn("col1", TEXT); schema2.addColumn("col2", TEXT); @@ -319,7 +320,7 @@ public void testInPredicateWithConstant() throws IOException { } @Test - public void testInPredicateWithSimpleExprs() throws IOException { + public void testInPredicateWithSimpleExprs() throws TajoException { Schema schema2 = new Schema(); schema2.addColumn("col1", TEXT); schema2.addColumn("col2", INT4); @@ -343,7 +344,7 @@ public void testInPredicateWithSimpleExprs() throws IOException { ////////////////////////////////////////////////////////////////// @Test - public void testIsNullPredicate() throws IOException { + public void testIsNullPredicate() throws TajoException { Schema schema1 = new Schema(); schema1.addColumn("col1", INT4); schema1.addColumn("col2", INT4); @@ -354,7 +355,7 @@ public void testIsNullPredicate() throws IOException { } @Test - public void testIsNullPredicateWithFunction() throws IOException { + public void testIsNullPredicateWithFunction() throws TajoException { Schema schema2 = new Schema(); schema2.addColumn("col1", TEXT); schema2.addColumn("col2", TEXT); @@ -370,7 +371,7 @@ public void testIsNullPredicateWithFunction() throws IOException { ////////////////////////////////////////////////////////////////// @Test - public void testBooleanTest() throws IOException { + public void testBooleanTest() throws TajoException { testSimpleEval("select 1 < 3 is true", new String [] {"t"}); testSimpleEval("select 1 < 3 is not true", new String [] {"f"}); testSimpleEval("select 1 < 3 is false", new String [] {"f"}); @@ -393,7 +394,7 @@ public void testBooleanTest() throws IOException { } @Test - public void testBooleanTestOnTable() throws IOException { + public void testBooleanTestOnTable() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", BOOLEAN); schema.addColumn("col2", BOOLEAN); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java index fc74339356..1b599a6f4f 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java @@ -18,14 +18,13 @@ package org.apache.tajo.engine.eval; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - public class TestSQLDateTimeTypes extends ExprTestBase { @Test - public void testTimestamp() throws IOException { + public void testTimestamp() throws TajoException { testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37';", new String[]{"1970-01-17 10:09:37"}); testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.5';", new String[]{"1970-01-17 10:09:37.5"}); testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.01';", new String[]{"1970-01-17 10:09:37.01"}); @@ -33,18 +32,18 @@ public void testTimestamp() throws IOException { } @Test - public void testToTimestamp() throws IOException { + public void testToTimestamp() throws TajoException { testSimpleEval("select to_char(TIMESTAMP '1970-01-17 10:09:37', 'YYYY-MM-DD HH24:MI:SS');", new String[]{"1970-01-17 10:09:37"}); } @Test - public void testTimeLiteral() throws IOException { + public void testTimeLiteral() throws TajoException { testSimpleEval("select TIME '10:09:37';", new String[]{"10:09:37"}); } @Test - public void testDateLiteral() throws IOException { + public void testDateLiteral() throws TajoException { testSimpleEval("select DATE '1970-01-17';", new String[]{"1970-01-17"}); } diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java index 8d81ae8c16..4dcb7e127f 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java @@ -26,6 +26,7 @@ import org.apache.tajo.datum.DatumFactory; import org.apache.tajo.datum.TimestampDatum; import org.apache.tajo.engine.query.QueryContext; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.util.datetime.DateTimeUtil; import org.junit.Test; @@ -38,7 +39,7 @@ public class TestSQLExpression extends ExprTestBase { @Test - public void testQuotedIdentifiers() throws IOException { + public void testQuotedIdentifiers() throws Throwable { Schema schema = new Schema(); schema.addColumn("컬럼1", TEXT); schema.addColumn("컬럼2", TEXT); @@ -50,7 +51,7 @@ public void testQuotedIdentifiers() throws IOException { } @Test - public void testNoSuchFunction() throws IOException { + public void testNoSuchFunction() { try { testSimpleEval("select test123('abc') col1 ", new String[]{"abc"}); fail("This test should throw UndefinedFunctionException"); @@ -62,7 +63,7 @@ public void testNoSuchFunction() throws IOException { } @Test - public void testSQLStandardCast() throws IOException { + public void testSQLStandardCast() throws TajoException { testSimpleEval("select cast (1 as char)", new String[] {"1"}); testSimpleEval("select cast (119 as char)", new String[] {"1"}); @@ -92,7 +93,7 @@ public void testSQLStandardCast() throws IOException { } @Test - public void testExplicitCast() throws IOException { + public void testExplicitCast() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", INT1); schema.addColumn("col1", INT2); @@ -172,7 +173,7 @@ public void testExplicitCast() throws IOException { } @Test - public void testImplicitCastForInt1() throws IOException { + public void testImplicitCastForInt1() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -274,7 +275,7 @@ public void testImplicitCastForInt1() throws IOException { } @Test - public void testImplicitCastForInt2() throws IOException { + public void testImplicitCastForInt2() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -376,7 +377,7 @@ public void testImplicitCastForInt2() throws IOException { } @Test - public void testImplicitCastForInt4() throws IOException { + public void testImplicitCastForInt4() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -479,7 +480,7 @@ public void testImplicitCastForInt4() throws IOException { } @Test - public void testImplicitCastForInt8() throws IOException { + public void testImplicitCastForInt8() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -586,7 +587,7 @@ public void testImplicitCastForInt8() throws IOException { } @Test - public void testImplicitCastForFloat4() throws IOException { + public void testImplicitCastForFloat4() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -705,7 +706,7 @@ public void testImplicitCastForFloat4() throws IOException { } @Test - public void testImplicitCastForFloat8() throws IOException { + public void testImplicitCastForFloat8() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -825,7 +826,7 @@ public void testImplicitCastForFloat8() throws IOException { } @Test - public void testSigned() throws IOException { + public void testSigned() throws TajoException { Schema schema = new Schema(); schema.addColumn("col0", TajoDataTypes.Type.INT1); schema.addColumn("col1", TajoDataTypes.Type.INT2); @@ -853,7 +854,7 @@ public void testSigned() throws IOException { } @Test - public void testCastWithNestedFunction() throws IOException { + public void testCastWithNestedFunction() throws TajoException { QueryContext context = new QueryContext(getConf()); context.put(SessionVars.TIMEZONE, "GMT-6"); TimeZone tz = TimeZone.getTimeZone("GMT-6"); @@ -865,7 +866,7 @@ public void testCastWithNestedFunction() throws IOException { } @Test - public void testCastFromTable() throws IOException { + public void testCastFromTable() throws TajoException { QueryContext queryContext = new QueryContext(getConf()); queryContext.put(SessionVars.TIMEZONE, "GMT-6"); TimeZone tz = TimeZone.getTimeZone("GMT-6"); @@ -898,7 +899,7 @@ public void testCastFromTable() throws IOException { } @Test - public void testBooleanLiteral() throws IOException { + public void testBooleanLiteral() throws TajoException { testSimpleEval("select true", new String[] {"t"}); testSimpleEval("select false", new String[]{"f"}); @@ -909,7 +910,7 @@ public void testBooleanLiteral() throws IOException { } @Test - public void testNullComparisons() throws IOException { + public void testNullComparisons() throws TajoException { testSimpleEval("select (1 > null) is null", new String[] {"t"}); testSimpleEval("select null is null", new String[] {"t"}); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java index 1d35139488..7e63bc1b98 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java @@ -23,15 +23,14 @@ import org.apache.tajo.catalog.exception.UndefinedFunctionException; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - import static org.junit.Assert.fail; public class TestConditionalExpressions extends ExprTestBase { @Test - public void testCaseWhens1() throws IOException { + public void testCaseWhens1() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TajoDataTypes.Type.INT1); schema.addColumn("col2", TajoDataTypes.Type.INT2); @@ -58,7 +57,7 @@ public void testCaseWhens1() throws IOException { } @Test - public void testCaseWhensWithNullReturn() throws IOException { + public void testCaseWhensWithNullReturn() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TajoDataTypes.Type.TEXT); schema.addColumn("col2", TajoDataTypes.Type.TEXT); @@ -72,7 +71,7 @@ public void testCaseWhensWithNullReturn() throws IOException { } @Test - public void testCaseWhensWithCommonExpression() throws IOException { + public void testCaseWhensWithCommonExpression() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TajoDataTypes.Type.INT4); schema.addColumn("col2", TajoDataTypes.Type.INT4); @@ -110,7 +109,7 @@ public void testCaseWhensWithCommonExpression() throws IOException { } @Test - public void testCaseWhensWithCommonExpressionAndNull() throws IOException { + public void testCaseWhensWithCommonExpressionAndNull() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TajoDataTypes.Type.INT4); schema.addColumn("col2", TajoDataTypes.Type.INT4); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java index 25a10fd77c..9dd8653183 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java @@ -25,21 +25,20 @@ import org.apache.tajo.datum.TimestampDatum; import org.apache.tajo.engine.eval.ExprTestBase; import org.apache.tajo.engine.query.QueryContext; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.util.datetime.DateTimeUtil; import org.apache.tajo.util.datetime.TimeMeta; import org.junit.Test; -import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import static org.apache.tajo.common.TajoDataTypes.Type.*; -import static org.junit.Assert.assertEquals; public class TestDateTimeFunctions extends ExprTestBase { @Test - public void testToTimestamp() throws IOException { + public void testToTimestamp() throws TajoException { long expectedTimestamp = System.currentTimeMillis(); TimestampDatum expected = DatumFactory.createTimestmpDatumWithUnixTime((int)(expectedTimestamp/ 1000)); @@ -100,7 +99,7 @@ public void testToTimestamp() throws IOException { } @Test - public void testToChar() throws IOException { + public void testToChar() throws TajoException { long expectedTimestamp = System.currentTimeMillis(); TimeMeta tm = new TimeMeta(); DateTimeUtil.toJulianTimeMeta(DateTimeUtil.javaTimeToJulianTime(expectedTimestamp), tm); @@ -116,7 +115,7 @@ public void testToChar() throws IOException { } @Test - public void testExtract() throws IOException { + public void testExtract() throws TajoException { TimeZone GMT = TimeZone.getTimeZone("GMT"); TimeZone PST = TimeZone.getTimeZone("PST"); @@ -232,7 +231,7 @@ public void testExtract() throws IOException { } @Test - public void testDatePart() throws IOException { + public void testDatePart() throws TajoException { TimeZone GMT = TimeZone.getTimeZone("GMT"); TimeZone PST = TimeZone.getTimeZone("PST"); @@ -345,7 +344,7 @@ public void testDatePart() throws IOException { } @Test - public void testUtcUsecTo() throws IOException { + public void testUtcUsecTo() throws TajoException { testSimpleEval("select utc_usec_to('day' ,1274259481071200);", new String[]{1274227200000000L+""}); testSimpleEval("select utc_usec_to('hour' ,1274259481071200);", new String[]{1274256000000000L+""}); testSimpleEval("select utc_usec_to('month' ,1274259481071200);", new String[]{1272672000000000L+""}); @@ -354,7 +353,7 @@ public void testUtcUsecTo() throws IOException { } @Test - public void testToDate() throws IOException { + public void testToDate() throws TajoException { testSimpleEval("select to_date('2014-01-04', 'YYYY-MM-DD')", new String[]{"2014-01-04"}); testSimpleEval("select to_date('2014-01-04', 'YYYY-MM-DD') + interval '1 day'", new String[]{"2014-01-05 00:00:00"}); @@ -394,7 +393,7 @@ public void testAddMonths() throws Exception { } @Test - public void testAddDays() throws IOException { + public void testAddDays() throws TajoException { testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT2);", new String[]{"2014-01-04 00:00:00"}); testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT4);", @@ -425,7 +424,7 @@ public void testAddDays() throws IOException { } @Test - public void testDateTimeNow() throws IOException { + public void testDateTimeNow() throws TajoException { TimeZone originalTimezone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT-6")); @@ -454,7 +453,7 @@ public void testDateTimeNow() throws IOException { } @Test - public void testTimeValueKeyword() throws IOException { + public void testTimeValueKeyword() throws TajoException { TimeZone originTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT-6")); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java index 89f0439df9..57248a8d45 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java @@ -20,15 +20,14 @@ import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - public class TestJsonFunctions extends ExprTestBase { static final String JSON_DOCUMENT = "{\"map\" : {\"name\" : \"tajo\"}, \"array\" : [1,2,3]}"; @Test - public void testJsonExtractPathText() throws IOException { + public void testJsonExtractPathText() throws TajoException { testSimpleEval("select json_extract_path_text('" + JSON_DOCUMENT + "', '$.map.name') ", new String[]{"tajo"}); testSimpleEval("select json_extract_path_text('" + JSON_DOCUMENT + "', '$.array[1]') ", new String[]{"2"}); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java index 78509f77e1..4b0303f244 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java @@ -20,15 +20,14 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - import static org.apache.tajo.common.TajoDataTypes.Type.*; public class TestMathFunctions extends ExprTestBase { @Test - public void testRound() throws IOException { + public void testRound() throws TajoException { testSimpleEval("select round(5.1) as col1 ", new String[]{"5"}); testSimpleEval("select round(5.5) as col1 ", new String[]{"6"}); testSimpleEval("select round(5.6) as col1 ", new String[]{"6"}); @@ -57,7 +56,7 @@ public void testRound() throws IOException { } @Test - public void testFloor() throws IOException { + public void testFloor() throws TajoException { testSimpleEval("select floor(5.1) as col1 ", new String[]{"5"}); testSimpleEval("select floor(5.5) as col1 ", new String[]{"5"}); testSimpleEval("select floor(5.6) as col1 ", new String[]{"5"}); @@ -75,7 +74,7 @@ public void testFloor() throws IOException { } @Test - public void testCeil() throws IOException { + public void testCeil() throws TajoException { testSimpleEval("select ceil(5.0) as col1 ", new String[]{"5"}); testSimpleEval("select ceil(5.1) as col1 ", new String[]{"6"}); testSimpleEval("select ceil(5.5) as col1 ", new String[]{"6"}); @@ -94,7 +93,7 @@ public void testCeil() throws IOException { } @Test - public void testCeiling() throws IOException { + public void testCeiling() throws TajoException { testSimpleEval("select ceiling(5.0) as col1 ", new String[]{"5"}); testSimpleEval("select ceiling(5.1) as col1 ", new String[]{"6"}); testSimpleEval("select ceiling(5.5) as col1 ", new String[]{"6"}); @@ -113,7 +112,7 @@ public void testCeiling() throws IOException { } @Test - public void testSin() throws IOException { + public void testSin() throws TajoException { testSimpleEval("select sin(0.0) as col1 ", new String[]{"0.0"}); testSimpleEval("select sin(0.7) as col1 ", new String[]{"0.644217687237691"}); testSimpleEval("select sin(1.2) as col1 ", new String[]{"0.9320390859672263"}); @@ -130,7 +129,7 @@ public void testSin() throws IOException { @Test - public void testCos() throws IOException { + public void testCos() throws TajoException { testSimpleEval("select cos(0.0) as col1 ", new String[]{"1.0"}); testSimpleEval("select cos(0.7) as col1 ", new String[]{"0.7648421872844885"}); testSimpleEval("select cos(1.2) as col1 ", new String[]{"0.3623577544766736"}); @@ -146,7 +145,7 @@ public void testCos() throws IOException { } @Test - public void testTan() throws IOException { + public void testTan() throws TajoException { testSimpleEval("select tan(0.0) as col1 ", new String[]{"0.0"}); testSimpleEval("select tan(0.3) as col1 ", new String[]{"0.30933624960962325"}); testSimpleEval("select tan(0.8) as col1 ", new String[]{"1.0296385570503641"}); @@ -162,7 +161,7 @@ public void testTan() throws IOException { } @Test - public void testAsin() throws IOException { + public void testAsin() throws TajoException { testSimpleEval("select asin(0.0) as col1 ", new String[]{"0.0"}); testSimpleEval("select asin(0.3) as col1 ", new String[]{"0.3046926540153975"}); testSimpleEval("select asin(0.8) as col1 ", new String[]{"0.9272952180016123"}); @@ -178,7 +177,7 @@ public void testAsin() throws IOException { } @Test - public void testAcos() throws IOException { + public void testAcos() throws TajoException { testSimpleEval("select acos(0.0) as col1 ", new String[]{"1.5707963267948966"}); testSimpleEval("select acos(0.3) as col1 ", new String[]{"1.2661036727794992"}); testSimpleEval("select acos(0.8) as col1 ", new String[]{"0.6435011087932843"}); @@ -194,7 +193,7 @@ public void testAcos() throws IOException { } @Test - public void testAtan() throws IOException { + public void testAtan() throws TajoException { testSimpleEval("select atan(0.0) as col1 ", new String[]{"0.0"}); testSimpleEval("select atan(0.8) as col1 ", new String[]{"0.6747409422235527"}); testSimpleEval("select atan(1.2) as col1 ", new String[]{"0.8760580505981934"}); @@ -210,7 +209,7 @@ public void testAtan() throws IOException { } @Test - public void testAtan2() throws IOException { + public void testAtan2() throws TajoException { testSimpleEval("select atan2(0.8, 0.0) as col1 ", new String[]{"1.5707963267948966"}); testSimpleEval("select atan2(0.8, 1.1) as col1 ", new String[]{"0.628796286415433"}); testSimpleEval("select atan2(2.7, 0.3) as col1 ", new String[]{"1.460139105621001"}); @@ -227,7 +226,7 @@ public void testAtan2() throws IOException { } @Test - public void testMod() throws IOException { + public void testMod() throws TajoException { testSimpleEval("select mod(9,4) as col1 ", new String[]{"1"}); testSimpleEval("select mod(200000000001,200000000000) as col1 ", new String[]{"1"}); testSimpleEval("select mod(200000000000,2) as col1 ", new String[]{"0"}); @@ -243,7 +242,7 @@ public void testMod() throws IOException { } @Test - public void testDiv() throws IOException { + public void testDiv() throws TajoException { testSimpleEval("select div(9,4) as col1 ", new String[]{"2"}); testSimpleEval("select div(200000000001,200000000000) as col1 ", new String[]{"1"}); testSimpleEval("select div(200000000000,2) as col1 ", new String[]{"100000000000"}); @@ -259,7 +258,7 @@ public void testDiv() throws IOException { } @Test - public void testSign() throws IOException { + public void testSign() throws TajoException { testSimpleEval("select sign(2) as col1 ", new String[]{"1.0"}); testSimpleEval("select sign(2.345) as col1 ", new String[]{"1.0"}); testSimpleEval("select sign(0.3) as col1 ", new String[]{"1.0"}); @@ -284,7 +283,7 @@ public void testSign() throws IOException { } @Test - public void testSqrt() throws IOException { + public void testSqrt() throws TajoException { testSimpleEval("select sqrt(27.0) as col1 ", new String[]{"5.196152422706632"}); testSimpleEval("select sqrt(64.0) as col1 ", new String[]{"8.0"}); testSimpleEval("select sqrt(8.0) as col1 ", new String[]{"2.8284271247461903"}); @@ -309,7 +308,7 @@ public void testSqrt() throws IOException { } @Test - public void testExp() throws IOException { + public void testExp() throws TajoException { testSimpleEval("select exp(1.0) as col1 ", new String[]{String.valueOf(Math.exp(1.0d))}); testSimpleEval("select exp(1.1) as col1 ", new String[]{String.valueOf(Math.exp(1.1d))}); testSimpleEval("select exp(1.2) as col1 ", new String[]{String.valueOf(Math.exp(1.2d))}); @@ -330,7 +329,7 @@ public void testExp() throws IOException { @Test - public void testAbs() throws IOException { + public void testAbs() throws TajoException { testSimpleEval("select abs(9) as col1 ", new String[]{"9"}); testSimpleEval("select abs(-9) as col1 ", new String[]{"9"}); testSimpleEval("select abs(200000000000) as col1 ", new String[]{"200000000000"}); @@ -351,7 +350,7 @@ public void testAbs() throws IOException { } @Test - public void testCbrt() throws IOException { + public void testCbrt() throws TajoException { testSimpleEval("select cbrt(27.0) as col1 ", new String[]{"3.0"}); testSimpleEval("select cbrt(64.0) as col1 ", new String[]{"4.0"}); testSimpleEval("select cbrt(8.0) as col1 ", new String[]{"2.0"}); @@ -373,7 +372,7 @@ public void testCbrt() throws IOException { } @Test - public void testDegrees() throws IOException { + public void testDegrees() throws TajoException { testSimpleEval("select degrees(0.0) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.0))}); testSimpleEval("select degrees(0.8) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.8))}); testSimpleEval("select degrees(2.7) as col1 ", new String[]{String.valueOf(Math.toDegrees(2.7))}); @@ -393,7 +392,7 @@ public void testDegrees() throws IOException { } @Test - public void testPow() throws IOException { + public void testPow() throws TajoException { testSimpleEval("select pow(9,3) as col1 ", new String[]{String.valueOf(Math.pow(9, 3))}); testSimpleEval("select pow(1.0,3) as col1 ", new String[]{String.valueOf(Math.pow(1.0, 3))}); testSimpleEval("select pow(20.1,3.1) as col1 ", new String[]{String.valueOf(Math.pow(20.1, 3.1))}); @@ -414,7 +413,7 @@ public void testPow() throws IOException { } @Test - public void testRadians() throws IOException { + public void testRadians() throws TajoException { testSimpleEval("select radians(0.0) as col1 ", new String[]{String.valueOf(Math.toRadians(0.0))}); testSimpleEval("select radians(0.8) as col1 ", new String[]{String.valueOf(Math.toRadians(0.8))}); testSimpleEval("select radians(2.7) as col1 ", new String[]{String.valueOf(Math.toRadians(2.7))}); @@ -434,12 +433,12 @@ public void testRadians() throws IOException { } @Test - public void testPi() throws IOException { + public void testPi() throws TajoException { testSimpleEval("select pi() as col1 ", new String[]{String.valueOf(Math.PI)}); } @Test - public void testRoundWithSpecifiedPrecision() throws IOException { + public void testRoundWithSpecifiedPrecision() throws TajoException { // TODO - in order to make this test possible, testSimpleEval should take session variables. Now, we disable it. // divide zero // try { diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java index 8aae26d9c6..50a8f35905 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java @@ -20,16 +20,15 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - import static org.apache.tajo.common.TajoDataTypes.Type.TEXT; public class TestPatternMatchingPredicates extends ExprTestBase { @Test - public void testLike() throws IOException { + public void testLike() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TEXT); @@ -58,7 +57,7 @@ public void testLike() throws IOException { } @Test - public void testILike() throws IOException { + public void testILike() throws TajoException { testSimpleEval("select 'abc' ilike '%c'", new String[]{"t"}); testSimpleEval("select 'abc' ilike 'a%'", new String[]{"t"}); testSimpleEval("select 'abc' ilike '_bc'", new String[]{"t"}); @@ -80,7 +79,7 @@ public void testILike() throws IOException { } @Test - public void testSimilarToLike() throws IOException { + public void testSimilarToLike() throws TajoException { testSimpleEval("select 'abc' similar to '%c'", new String[]{"t"}); testSimpleEval("select 'abc' similar to 'a%'", new String[]{"t"}); testSimpleEval("select 'abc' similar to '_bc'", new String[]{"t"}); @@ -104,7 +103,7 @@ public void testSimilarToLike() throws IOException { } @Test - public void testRegexWithSimilarOperator() throws IOException { + public void testRegexWithSimilarOperator() throws TajoException { testSimpleEval("select 'abc' ~ '.*c'", new String[]{"t"}); testSimpleEval("select 'abc' ~ '.*c$'", new String[]{"t"}); testSimpleEval("select 'aaabc' ~ '([a-z]){3}bc'", new String[]{"t"}); @@ -121,7 +120,7 @@ public void testRegexWithSimilarOperator() throws IOException { } @Test - public void testRegexp() throws IOException { + public void testRegexp() throws TajoException { testSimpleEval("select 'abc' regexp '.*c'", new String[]{"t"}); testSimpleEval("select 'abc' regexp '.*c$'", new String[]{"t"}); @@ -130,7 +129,7 @@ public void testRegexp() throws IOException { } @Test - public void testRLike() throws IOException { + public void testRLike() throws TajoException { testSimpleEval("select 'abc' rlike '.*c'", new String[]{"t"}); testSimpleEval("select 'abc' rlike '.*c$'", new String[]{"t"}); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java index 6f73d01ec4..e94f8690b3 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java @@ -19,6 +19,7 @@ package org.apache.tajo.engine.function; import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; import java.io.IOException; @@ -26,7 +27,7 @@ public class TestPythonFunctions extends ExprTestBase { @Test - public void testFunctions() throws IOException { + public void testFunctions() throws TajoException { testSimpleEval("select return_one()", new String[]{"1"}); testSimpleEval("select helloworld()", new String[]{"Hello, World"}); testSimpleEval("select concat_py('1')", new String[]{"11"}); @@ -37,7 +38,7 @@ public void testFunctions() throws IOException { } @Test - public void testNestedFunctions() throws IOException { + public void testNestedFunctions() throws TajoException { testSimpleEval("select add_py(3, return_one())", new String[]{"4"}); testSimpleEval("select concat_py(helloworld())", new String[]{"Hello, WorldHello, World"}); } diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java index 7f402a13bc..366d8ed236 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java @@ -22,16 +22,15 @@ import org.apache.commons.lang.StringEscapeUtils; import org.apache.tajo.catalog.Schema; import org.apache.tajo.engine.eval.ExprTestBase; +import org.apache.tajo.exception.TajoException; import org.junit.Test; -import java.io.IOException; - import static org.apache.tajo.common.TajoDataTypes.Type.*; public class TestStringOperatorsAndFunctions extends ExprTestBase { @Test - public void testConcatenateOnLiteral() throws IOException { + public void testConcatenateOnLiteral() throws TajoException { testSimpleEval("select ('abc' || 'def') col1 ", new String[]{"abcdef"}); testSimpleEval("select 'abc' || 'def' as col1 ", new String[]{"abcdef"}); testSimpleEval("select 1 || 'def' as col1 ", new String[]{"1def"}); @@ -39,7 +38,7 @@ public void testConcatenateOnLiteral() throws IOException { } @Test - public void testConcatenateOnExpressions() throws IOException { + public void testConcatenateOnExpressions() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TEXT); schema.addColumn("col2", INT4); @@ -52,7 +51,7 @@ public void testConcatenateOnExpressions() throws IOException { } @Test - public void testFunctionCallIngoreCases() throws IOException { + public void testFunctionCallIngoreCases() throws TajoException { testSimpleEval("select ltrim(' trim') ", new String[]{"trim"}); testSimpleEval("select LTRIM(' trim') ", new String[]{"trim"}); testSimpleEval("select lTRim(' trim') ", new String[]{"trim"}); @@ -60,7 +59,7 @@ public void testFunctionCallIngoreCases() throws IOException { } @Test - public void testLTrim() throws IOException { + public void testLTrim() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TEXT); schema.addColumn("col2", TEXT); @@ -81,7 +80,7 @@ public void testLTrim() throws IOException { } @Test - public void testRTrim() throws IOException { + public void testRTrim() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TEXT); schema.addColumn("col2", TEXT); @@ -102,7 +101,7 @@ public void testRTrim() throws IOException { } @Test - public void testTrim() throws IOException { + public void testTrim() throws TajoException { Schema schema = new Schema(); schema.addColumn("col1", TEXT); schema.addColumn("col2", TEXT); @@ -123,7 +122,7 @@ public void testTrim() throws IOException { } @Test - public void testRegexReplace() throws IOException { + public void testRegexReplace() throws TajoException { testSimpleEval("select regexp_replace('abcdef','bc','--') as col1 ", new String[]{"a--def"}); // null test @@ -148,7 +147,7 @@ public void testRegexReplace() throws IOException { } @Test - public void testLeft() throws IOException { + public void testLeft() throws TajoException { testSimpleEval("select left('abcdef',1) as col1 ", new String[]{"a"}); testSimpleEval("select left('abcdef',2) as col1 ", new String[]{"ab"}); testSimpleEval("select left('abcdef',3) as col1 ", new String[]{"abc"}); @@ -177,7 +176,7 @@ public void testLeft() throws IOException { } @Test - public void testRight() throws IOException { + public void testRight() throws TajoException { testSimpleEval("select right('abcdef',1) as col1 ", new String[]{"f"}); testSimpleEval("select right('abcdef',2) as col1 ", new String[]{"ef"}); testSimpleEval("select right('abcdef',3) as col1 ", new String[]{"def"}); @@ -206,7 +205,7 @@ public void testRight() throws IOException { } @Test - public void testReverse() throws IOException { + public void testReverse() throws TajoException { testSimpleEval("select reverse('abcdef') as col1 ", new String[]{"fedcba"}); testSimpleEval("select reverse('가') as col1 ", new String[]{"가"}); @@ -219,7 +218,7 @@ public void testReverse() throws IOException { } @Test - public void testRepeat() throws IOException { + public void testRepeat() throws TajoException { testSimpleEval("select repeat('ab',4) as col1 ", new String[]{"abababab"}); testSimpleEval("select repeat('가',3) as col1 ", new String[]{"가가가"}); testSimpleEval("select repeat('a',2) as col1 ", new String[]{"aa"}); @@ -233,7 +232,7 @@ public void testRepeat() throws IOException { @Test - public void testUpper() throws IOException { + public void testUpper() throws TajoException { testSimpleEval("select upper('abcdef') as col1 ", new String[]{"ABCDEF"}); Schema schema = new Schema(); @@ -246,7 +245,7 @@ public void testUpper() throws IOException { } @Test - public void testLower() throws IOException { + public void testLower() throws TajoException { testSimpleEval("select lower('ABCdEF') as col1 ", new String[]{"abcdef"}); Schema schema = new Schema(); @@ -259,7 +258,7 @@ public void testLower() throws IOException { } @Test - public void testCharLength() throws IOException { + public void testCharLength() throws TajoException { testSimpleEval("select char_length('123456') as col1 ", new String[]{"6"}); Schema schema = new Schema(); @@ -271,7 +270,7 @@ public void testCharLength() throws IOException { } @Test - public void testLength() throws IOException { + public void testLength() throws TajoException { testSimpleEval("select length('123456') as col1 ", new String[]{"6"}); Schema schema = new Schema(); @@ -283,7 +282,7 @@ public void testLength() throws IOException { } @Test - public void testMd5() throws IOException { + public void testMd5() throws TajoException { testSimpleEval("select md5('1') as col1 ", new String[]{"c4ca4238a0b923820dcc509a6f75849b"}); testSimpleEval("select md5('tajo') as col1 ", new String[]{"742721b3a79f71a9491681b8e8a7ce85"}); @@ -296,7 +295,7 @@ public void testMd5() throws IOException { } @Test - public void testDigest() throws IOException { + public void testDigest() throws TajoException { testSimpleEval("select digest('tajo', 'md2') as col1 ", new String[]{"bf523bce8241982f6bea9af0f7fd37ff"}); testSimpleEval("select digest('tajo', 'md5') as col1 ", new String[]{"742721b3a79f71a9491681b8e8a7ce85"}); testSimpleEval("select digest('tajo', 'sha1') as col1 ", new String[]{"02b0e20540b89f0b735092bbac8093eb2e3804cf"}); @@ -310,7 +309,7 @@ public void testDigest() throws IOException { } @Test - public void testHex() throws IOException { + public void testHex() throws TajoException { testSimpleEval("select to_hex(1) as col1 ", new String[]{"1"}); testSimpleEval("select to_hex(10) as col1 ", new String[]{"a"}); testSimpleEval("select to_hex(1234) as col1 ", new String[]{"4d2"}); @@ -325,7 +324,7 @@ public void testHex() throws IOException { } @Test - public void testBin() throws IOException { + public void testBin() throws TajoException { testSimpleEval("select to_bin(1) as col1 ", new String[]{"1"}); testSimpleEval("select to_bin(10) as col1 ", new String[]{"1010"}); testSimpleEval("select to_bin(1234) as col1 ", new String[]{"10011010010"}); @@ -339,7 +338,7 @@ public void testBin() throws IOException { } @Test - public void testOctetLength() throws IOException { + public void testOctetLength() throws TajoException { testSimpleEval("select octet_length('123456') as col1 ", new String[]{"6"}); testSimpleEval("select octet_length('1') as col1 ", new String[]{"1"}); testSimpleEval("select octet_length('가') as col1 ", new String[]{"3"}); @@ -353,7 +352,7 @@ public void testOctetLength() throws IOException { } @Test - public void testSplitPart() throws IOException { + public void testSplitPart() throws TajoException { testSimpleEval("select split_part('1386577650.123', '.', 1) as col1 ", new String[]{"1386577650"}); testSimpleEval("select split_part('1386577650.123', '.', 2) as col1 ", new String[]{"123"}); // If part is larger than the number of string portions, it will returns NULL. @@ -372,7 +371,7 @@ public void testSplitPart() throws IOException { } @Test - public void testSubstr() throws IOException { + public void testSubstr() throws TajoException { testSimpleEval("select substr('abcdef', 3, 2) as col1 ", new String[]{"cd"}); testSimpleEval("select substr('abcdef', 3) as col1 ", new String[]{"cdef"}); testSimpleEval("select substr('abcdef', 1, 1) as col1 ", new String[]{"a"}); @@ -398,7 +397,7 @@ public void testSubstr() throws IOException { } @Test - public void testLocate() throws IOException { + public void testLocate() throws TajoException { // normal case testSimpleEval("select locate('abcdef', 'a') as col1 ", new String[]{"1"}); testSimpleEval("select locate('abcdef', 'a', 0) as col1 ", new String[]{"1"}); @@ -447,7 +446,7 @@ public void testLocate() throws IOException { } @Test - public void testBitLength() throws IOException { + public void testBitLength() throws TajoException { testSimpleEval("select bit_length('123456') as col1 ", new String[]{"48"}); Schema schema = new Schema(); @@ -459,7 +458,7 @@ public void testBitLength() throws IOException { } @Test - public void testStrpos() throws IOException { + public void testStrpos() throws TajoException { testSimpleEval("select strpos('tajo','jo') as col1 ", new String[]{"3"}); testSimpleEval("select strpos('tajo','') as col1 ", new String[]{"1"}); testSimpleEval("select strpos('tajo','abcdef') as col1 ", new String[]{"0"}); @@ -475,7 +474,7 @@ public void testStrpos() throws IOException { } @Test - public void testStrposb() throws IOException { + public void testStrposb() throws TajoException { testSimpleEval("select strposb('tajo','jo') as col1 ", new String[]{"3"}); testSimpleEval("select strposb('tajo','') as col1 ", new String[]{"1"}); testSimpleEval("select strposb('tajo','abcdef') as col1 ", new String[]{"0"}); @@ -491,13 +490,13 @@ public void testStrposb() throws IOException { } @Test - public void testInitcap() throws IOException { + public void testInitcap() throws TajoException { testSimpleEval("select initcap('hi bro') ", new String[]{"Hi Bro"}); testSimpleEval("select initcap('HI BRO') ", new String[]{"Hi Bro"}); } @Test - public void testAscii() throws IOException { + public void testAscii() throws TajoException { testSimpleEval("select ascii('abc') as col1 ", new String[]{"97"}); Schema schema = new Schema(); @@ -510,7 +509,7 @@ public void testAscii() throws IOException { } @Test - public void testChr() throws IOException { + public void testChr() throws TajoException { testSimpleEval("select chr(48) as col1 ", new String[]{"0"}); testSimpleEval("select chr(49) as col1 ", new String[]{"1"}); testSimpleEval("select chr(50) as col1 ", new String[]{"2"}); @@ -524,7 +523,7 @@ public void testChr() throws IOException { } @Test - public void testLpad() throws IOException { + public void testLpad() throws TajoException { testSimpleEval("select lpad('hi', 5, 'xy') ", new String[]{"xyxhi"}); testSimpleEval("select LPAD('hello', 7, 'xy') ", new String[]{"xyhello"}); testSimpleEval("select LPAD('hello', 3, 'xy') ", new String[]{"hel"}); @@ -534,7 +533,7 @@ public void testLpad() throws IOException { } @Test - public void testRpad() throws IOException { + public void testRpad() throws TajoException { testSimpleEval("select rpad('hi', 5, 'xy') ", new String[]{"hixyx"}); testSimpleEval("select RPAD('hello', 7, 'xy') ", new String[]{"helloxy"}); testSimpleEval("select RPAD('hello', 3, 'xy') ", new String[]{"hel"}); @@ -544,13 +543,13 @@ public void testRpad() throws IOException { } @Test - public void testQuote_ident() throws IOException { + public void testQuote_ident() throws TajoException { testSimpleEval("select quote_ident('Foo bar') ", new String[]{"\"Foo bar\""}); testSimpleEval("select QUOTE_IDENT('Tajo Function') ", new String[]{"\"Tajo Function\""}); } @Test - public void testEncode() throws IOException { + public void testEncode() throws TajoException { testSimpleEval("select encode('Hello\nworld', 'base64') ", new String[]{"SGVsbG8Kd29ybGQ="}); testSimpleEval("select encode('Hello\nworld', 'hex') ", new String[]{"0x480x650x6c0x6c0x6f0x0a0x770x6f0x720x6c0x64"}); @@ -562,7 +561,7 @@ public void testEncode() throws IOException { @Test - public void testDecode() throws IOException { + public void testDecode() throws TajoException { testSimpleEval("select decode('SGVsbG8Kd29ybGQ=', 'base64') ", new String[]{StringEscapeUtils.escapeJava("Hello\nworld")}); testSimpleEval("select decode('0x480x650x6c0x6c0x6f0x0a0x770x6f0x720x6c0x64', 'hex') ", @@ -574,7 +573,7 @@ public void testDecode() throws IOException { } @Test - public void testFindInSet() throws IOException { + public void testFindInSet() throws TajoException { // abnormal cases testSimpleEval("select find_in_set('cr','crt') as col1 ", new String[]{"0"}); // there is no matched string testSimpleEval("select find_in_set('c,r','crt,c,cr,c,def') as col1 ", new String[]{"0"}); // abnormal parameter @@ -597,7 +596,7 @@ public void testFindInSet() throws IOException { } @Test - public void testConcat() throws IOException { + public void testConcat() throws TajoException { testSimpleEval("select concat('333', '22') ", new String[]{"33322"}); testSimpleEval("select concat('한글', '22') ", new String[]{"한글22"}); testSimpleEval("select concat(null, '22') ", new String[]{"22"}); @@ -606,7 +605,7 @@ public void testConcat() throws IOException { } @Test - public void testConcat_ws() throws IOException { + public void testConcat_ws() throws TajoException { testSimpleEval("select concat_ws(',', '333', '22') ", new String[]{"333,22"}); testSimpleEval("select concat_ws(',', '한글', '22') ", new String[]{"한글,22"}); testSimpleEval("select concat_ws(',', '22', null) ", new String[]{"22"}); diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java index 4ef5e9b7ea..4fb2d31d5a 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java @@ -31,11 +31,13 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; import org.apache.tajo.catalog.TableMeta; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.conf.TajoConf.ConfVars; import org.apache.tajo.datum.Datum; import org.apache.tajo.datum.Int4Datum; import org.apache.tajo.datum.TextDatum; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.storage.*; import org.apache.tajo.util.FileUtil; import org.apache.tajo.util.KeyValueSet; @@ -211,7 +213,7 @@ interface TupleCreator { Tuple createTuple(String[] columnDatas); } - private static String buildSchemaString(String tableName) throws ServiceException, SQLException { + private static String buildSchemaString(String tableName) throws TajoException { TableDesc desc = client.getTableDesc(tableName); StringBuffer sb = new StringBuffer(); for (Column column : desc.getSchema().getRootColumns()) { @@ -226,7 +228,7 @@ private static String buildSchemaString(String tableName) throws ServiceExceptio return sb.toString(); } - private static String buildMultifileDDlString(String tableName) throws ServiceException, SQLException { + private static String buildMultifileDDlString(String tableName) throws TajoException { String multiTableName = tableName + "_multifile"; StringBuilder sb = new StringBuilder("create table ").append(multiTableName).append(" ("); sb.append(buildSchemaString(tableName)).append(" )"); diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java index 1adad41007..be86a18ee9 100644 --- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java +++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java @@ -400,52 +400,6 @@ public void testMultipleConnectionsSequentialClose() throws Exception { } } - @Test - public void testSetStatement() throws Exception { - assertTrue(TajoStatement.isSetVariableQuery("Set JOIN_TASK_INPUT_SIZE 123")); - assertTrue(TajoStatement.isSetVariableQuery("SET JOIN_TASK_INPUT_SIZE 123")); - assertFalse(TajoStatement.isSetVariableQuery("--SET JOIN_TASK_INPUT_SIZE 123")); - - String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); - - Connection conn = DriverManager.getConnection(connUri); - - Statement stmt = null; - ResultSet res = null; - try { - stmt = conn.createStatement(); - res = stmt.executeQuery("Set JOIN_TASK_INPUT_SIZE 123"); - assertFalse(res.next()); - ResultSetMetaData rsmd = res.getMetaData(); - assertNotNull(rsmd); - assertEquals(0, rsmd.getColumnCount()); - - QueryClient connTajoClient = ((JdbcConnection) stmt.getConnection()).getQueryClient(); - Map variables = connTajoClient.getAllSessionVariables(); - String value = variables.get("JOIN_TASK_INPUT_SIZE"); - assertNotNull(value); - assertEquals("123", value); - - res.close(); - - res = stmt.executeQuery("unset JOIN_TASK_INPUT_SIZE"); - variables = connTajoClient.getAllSessionVariables(); - value = variables.get("JOIN_TASK_INPUT_SIZE"); - assertNull(value); - } finally { - if (res != null) { - res.close(); - } - if (stmt != null) { - stmt.close(); - } - if (conn != null) { - conn.close(); - } - } - } - @Test public void testSetPreparedStatement() throws Exception { String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java index 6db14474b1..b098b1670c 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java @@ -28,6 +28,8 @@ import org.apache.tajo.client.TajoClient; import org.apache.tajo.client.TajoClientImpl; import org.apache.tajo.conf.TajoConf; +import org.apache.tajo.exception.SQLExceptionUtil; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.jdbc.util.QueryStringDecoder; import org.apache.tajo.rpc.RpcUtils; import org.apache.tajo.util.KeyValueSet; @@ -267,14 +269,18 @@ public boolean isReadOnly() throws SQLException { @Override public boolean isValid(int timeout) throws SQLException { - if (tajoClient.isConnected()) { - ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;"); - boolean next = resultSet.next(); - boolean valid = next && resultSet.getLong(1) == 1; - resultSet.close(); - return valid; - } else { - return false; + try { + if (tajoClient.isConnected()) { + ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;"); + boolean next = resultSet.next(); + boolean valid = next && resultSet.getLong(1) == 1; + resultSet.close(); + return valid; + } else { + return false; + } + } catch (TajoException e) { + throw SQLExceptionUtil.toSQLException(e); } } @@ -357,7 +363,11 @@ public void setAutoCommit(boolean autoCommit) throws SQLException { @Override public void setCatalog(String catalog) throws SQLException { - tajoClient.selectDatabase(catalog); + try { + tajoClient.selectDatabase(catalog); + } catch (TajoException e) { + throw SQLExceptionUtil.toSQLException(e); + } } @Override diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java index 73035c7b90..eeb6bbfb46 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java @@ -152,13 +152,6 @@ public ResultSet executeQuery(String sql) throws SQLException { } protected ResultSet executeSQL(String sql) throws SQLException { - if (isSetVariableQuery(sql)) { - return setSessionVariable(tajoClient, sql); - } - if (isUnSetVariableQuery(sql)) { - return unSetSessionVariable(tajoClient, sql); - } - ClientProtos.SubmitQueryResponse response = tajoClient.executeQuery(sql); SQLExceptionUtil.throwIfError(response.getState()); @@ -187,53 +180,6 @@ protected void checkConnection(String errorMsg) throws SQLException { } } - public static boolean isSetVariableQuery(String sql) { - if (sql == null || sql.trim().isEmpty()) { - return false; - } - - return sql.trim().toLowerCase().startsWith("set"); - } - - public static boolean isUnSetVariableQuery(String sql) { - if (sql == null || sql.trim().isEmpty()) { - return false; - } - - return sql.trim().toLowerCase().startsWith("unset"); - } - - private ResultSet setSessionVariable(TajoClient client, String sql) throws SQLException { - int index = sql.toLowerCase().indexOf("set"); - if (index < 0) { - throw new SQLException("SET statement should be started 'SET' keyword: " + sql); - } - - String[] tokens = sql.substring(index + 3).trim().split(" "); - if (tokens.length != 2) { - throw new SQLException("SET statement should be : " + sql); - } - Map variable = new HashMap(); - variable.put(tokens[0].trim(), tokens[1].trim()); - client.updateSessionVariables(variable); - return NULL_RESULT_SET; - } - - private ResultSet unSetSessionVariable(TajoClient client, String sql) throws SQLException { - int index = sql.toLowerCase().indexOf("unset"); - if (index < 0) { - throw new SQLException("UNSET statement should be started 'UNSET' keyword: " + sql); - } - - String key = sql.substring(index + 5).trim(); - if (key.isEmpty()) { - throw new SQLException("UNSET statement should be : " + sql); - } - client.unsetSessionVariables(Lists.newArrayList(key)); - - return NULL_RESULT_SET; - } - @Override public int executeUpdate(String sql) throws SQLException { checkConnection("Can't execute update"); diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java index 392d308c07..a6f3d35cf8 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java @@ -149,7 +149,9 @@ public static Collection lookupTableByColumns(LogicalPlan.QueryBlo * @throws PlanningException */ static Column resolveFromRelsWithinBlock(LogicalPlan plan, LogicalPlan.QueryBlock block, - ColumnReferenceExpr columnRef) throws AmbiguousColumnException { + ColumnReferenceExpr columnRef) + throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { + String qualifier; String canonicalName; @@ -306,7 +308,7 @@ static Column resolveAliasedName(LogicalPlan.QueryBlock block, ColumnReferenceEx */ static Pair lookupQualifierAndCanonicalName(LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) - throws AmbiguousColumnException { + throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException { Preconditions.checkArgument(columnRef.hasQualifier(), "ColumnReferenceExpr must be qualified."); diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java index aa0d7f50ef..3bbb2be02c 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java @@ -99,7 +99,8 @@ private static Column resolveColumnWithQualifier(LogicalPlan plan, LogicalPlan.Q } static Column resolveColumnWithoutQualifier(LogicalPlan plan, LogicalPlan.QueryBlock block, - ColumnReferenceExpr columnRef) throws AmbiguousColumnException { + ColumnReferenceExpr columnRef) + throws AmbiguousColumnException, UndefinedColumnException { Column found = lookupColumnFromAllRelsInBlock(block, columnRef.getName()); if (found != null) { diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java index fa9fe84ac6..aee131b9cc 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java @@ -20,7 +20,9 @@ import org.apache.tajo.algebra.ColumnReferenceExpr; import org.apache.tajo.catalog.Column; +import org.apache.tajo.catalog.exception.AmbiguousTableException; import org.apache.tajo.catalog.exception.UndefinedColumnException; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.exception.AmbiguousColumnException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.PlanningException; @@ -28,7 +30,7 @@ public class ResolverByRels extends NameResolver { @Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) - throws AmbiguousColumnException { + throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromRelsWithinBlock(plan, block, columnRef); if (column == null) { diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java index cafba7d6f1..560ae50ae0 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java @@ -20,7 +20,9 @@ import org.apache.tajo.algebra.ColumnReferenceExpr; import org.apache.tajo.catalog.Column; +import org.apache.tajo.catalog.exception.AmbiguousTableException; import org.apache.tajo.catalog.exception.UndefinedColumnException; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.exception.AmbiguousColumnException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.PlanningException; @@ -28,7 +30,7 @@ public class ResolverByRelsAndSubExprs extends NameResolver { @Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) - throws AmbiguousColumnException { + throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromRelsWithinBlock(plan, block, columnRef); if (column == null) { diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java index c16bbe2ada..39458ec39d 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java @@ -20,7 +20,9 @@ import org.apache.tajo.algebra.ColumnReferenceExpr; import org.apache.tajo.catalog.Column; +import org.apache.tajo.catalog.exception.AmbiguousTableException; import org.apache.tajo.catalog.exception.UndefinedColumnException; +import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.exception.AmbiguousColumnException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.PlanningException; @@ -28,7 +30,7 @@ public class ResolverBySubExprsAndRels extends NameResolver { @Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) - throws AmbiguousColumnException{ + throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromCurrentAndChildNode(block, columnRef); if (column == null) { diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java index 650a48472f..5ad537ff8f 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java @@ -30,6 +30,7 @@ import org.apache.tajo.catalog.exception.DuplicateColumnException; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.LogicalPlan.QueryBlock; import org.apache.tajo.plan.LogicalPlanner; @@ -195,7 +196,7 @@ public String getRealReferenceName(String name) { * Add an expression with a specified name, which is usually an alias. * Later, you can refer this expression by the specified name. */ - private String add(String specifiedName, EvalNode evalNode) { + private String add(String specifiedName, EvalNode evalNode) throws DuplicateColumnException { // if a name already exists, it only just keeps an actual // expression instead of a column reference. @@ -253,7 +254,7 @@ private String add(String specifiedName, EvalNode evalNode) { * Adds an expression without any name. It returns an automatically * generated name. It can be also used for referring this expression. */ - public String add(EvalNode evalNode) { + public String add(EvalNode evalNode) throws DuplicateColumnException { String name; if (evalNode.getType() == EvalType.FIELD) { @@ -283,7 +284,7 @@ public Collection getNames() { return nameToIdBiMap.keySet(); } - public String add(Target target) { + public String add(Target target) throws DuplicateColumnException { return add(target.getCanonicalName(), target.getEvalTree()); } @@ -419,13 +420,13 @@ public Context(Context upperContext) { targetListMgr = upperContext.targetListMgr; } - public String addExpr(Target target) { + public String addExpr(Target target) throws DuplicateColumnException { String reference = targetListMgr.add(target); addNecessaryReferences(target.getEvalTree()); return reference; } - public String addExpr(EvalNode evalNode) { + public String addExpr(EvalNode evalNode) throws DuplicateColumnException { String reference = targetListMgr.add(evalNode); addNecessaryReferences(evalNode); return reference; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java index 05f95df8b8..73a07d5583 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java @@ -33,6 +33,7 @@ import org.apache.tajo.common.TajoDataTypes.DataType; import org.apache.tajo.datum.*; import org.apache.tajo.exception.InternalException; +import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.plan.expr.*; import org.apache.tajo.plan.function.python.PythonScriptEngine; import org.apache.tajo.plan.logical.WindowSpec; @@ -237,10 +238,10 @@ public int compare(PlanProto.EvalNode o1, PlanProto.EvalNode o2) { parameterTypes = funcSignatureProto.getParameterTypesList().toArray( new DataType[funcSignatureProto.getParameterTypesCount()]); } - throw new UndefinedFunctionException(functionName, parameterTypes); + throw new TajoInternalError(new UndefinedFunctionException(functionName, parameterTypes)); } } else { - throw new RuntimeException("Unknown EvalType: " + type.name()); + throw new TajoInternalError("Unknown EvalType: " + type.name()); } evalNodeMap.put(protoNode.getId(), current); From 1c07bf984ad2c6b359b83dea3b5201f8b8a6418b Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Wed, 29 Jul 2015 14:54:58 +0900 Subject: [PATCH 6/8] Add listener and refactored exceptions's constructor to take ReturnState. --- .../exception/AmbiguousTableException.java | 9 +- .../exception/DuplicateColumnException.java | 5 + .../exception/DuplicateDatabaseException.java | 3 +- .../exception/DuplicateIndexException.java | 5 + .../DuplicatePartitionException.java | 5 + .../exception/DuplicateTableException.java | 4 +- .../exception/UndefinedColumnException.java | 5 + .../exception/UndefinedDatabaseException.java | 4 +- .../exception/UndefinedFunctionException.java | 7 +- .../UndefinedPartitionException.java | 5 + .../exception/UndefinedTableException.java | 4 +- .../UndefinedTablespaceException.java | 5 + .../tajo/client/ClientExceptionUtil.java | 74 ++++++++++--- .../apache/tajo/client/v2/FutureListener.java | 25 +++++ .../tajo/client/v2/LegacyClientDelegate.java | 33 +++++- .../apache/tajo/client/v2/QueryFuture.java | 14 ++- .../org/apache/tajo/jdbc/FetchResultSet.java | 2 +- .../exception/AmbiguousColumnException.java | 9 +- .../apache/tajo/exception/ErrorMessages.java | 3 +- .../org/apache/tajo/exception/TajoError.java | 7 ++ .../tajo/exception/TajoInternalError.java | 6 + .../exception/UndefinedOperatorException.java | 5 + .../tajo/client/v2/TestTajoClientV2.java | 103 +++++++++++++++++- .../testExecuteQueryAsync.result | 7 ++ .../testExecuteQueryAsyncWithListener.result | 2 + 25 files changed, 311 insertions(+), 40 deletions(-) create mode 100644 tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java create mode 100644 tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result create mode 100644 tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java index 65ff746612..27f5534a9c 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java @@ -18,12 +18,15 @@ 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; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class AmbiguousTableException extends CatalogException { + + public AmbiguousTableException(ReturnState state) { + super(state); + } + public AmbiguousTableException(String tableName) { super(Errors.ResultCode.AMBIGUOUS_TABLE, tableName); } 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 index 121a289228..88b067ae7f 100644 --- 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 @@ -19,10 +19,15 @@ package org.apache.tajo.catalog.exception; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class DuplicateColumnException extends CatalogException { private static final long serialVersionUID = 6766228091940775275L; + public DuplicateColumnException(ReturnState state) { + super(state); + } + public DuplicateColumnException(String columnName) { super(Errors.ResultCode.DUPLICATE_COLUMN, columnName); } 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 index 5903051afa..8725d49a60 100644 --- 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 @@ -21,10 +21,11 @@ import org.apache.tajo.error.Errors; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class DuplicateDatabaseException extends CatalogException { - public DuplicateDatabaseException(PrimitiveProtos.ReturnState state) { + public DuplicateDatabaseException(ReturnState state) { super(state); } public DuplicateDatabaseException(String dbName) { 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 index c510b162a0..b9e71c2c4f 100644 --- 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 @@ -19,10 +19,15 @@ package org.apache.tajo.catalog.exception; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class DuplicateIndexException extends CatalogException { private static final long serialVersionUID = 3705839985189534673L; + public DuplicateIndexException(ReturnState state) { + super(state); + } + public DuplicateIndexException(String indexName) { super(Errors.ResultCode.DUPLICATE_INDEX, indexName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java index bdec4fc148..bbb50b9178 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java @@ -19,10 +19,15 @@ package org.apache.tajo.catalog.exception; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class DuplicatePartitionException extends CatalogException { private static final long serialVersionUID = 277182608283894930L; + public DuplicatePartitionException(ReturnState state) { + super(state); + } + public DuplicatePartitionException(String partitionName) { super(Errors.ResultCode.DUPLICATE_PARTITION, partitionName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java index 6833d39ceb..2111186f5b 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java @@ -20,12 +20,12 @@ import org.apache.tajo.error.Errors; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class DuplicateTableException extends CatalogException { private static final long serialVersionUID = -641623770742392865L; - public DuplicateTableException(PrimitiveProtos.ReturnState state) { + public DuplicateTableException(ReturnState state) { super(state); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java index 43b74104d7..39d61309cc 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java @@ -20,10 +20,15 @@ import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UndefinedColumnException extends CatalogException { private static final long serialVersionUID = 277182608283894937L; + public UndefinedColumnException(ReturnState state) { + super(state); + } + public UndefinedColumnException(String columnName) { super(ResultCode.UNDEFINED_COLUMN, columnName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java index 76f8b43fc2..75dcd496c1 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java @@ -20,12 +20,12 @@ import org.apache.tajo.error.Errors; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UndefinedDatabaseException extends CatalogException { private static final long serialVersionUID = 277182608283894937L; - public UndefinedDatabaseException(PrimitiveProtos.ReturnState state) { + public UndefinedDatabaseException(ReturnState state) { super(state); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java index 94ce23642e..0ac2a93482 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java @@ -19,19 +19,16 @@ 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.exception.TajoException; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.function.FunctionUtil; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; import java.util.Collection; public class UndefinedFunctionException extends CatalogException { private static final long serialVersionUID = 5062193018697228028L; - public UndefinedFunctionException(PrimitiveProtos.ReturnState state) { + public UndefinedFunctionException(ReturnState state) { super(state); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java index 282f0a22cc..1033c44e9b 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java @@ -19,11 +19,16 @@ package org.apache.tajo.catalog.exception; import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UndefinedPartitionException extends CatalogException { private static final long serialVersionUID = 277182608283894938L; + public UndefinedPartitionException(ReturnState state) { + super(state); + } + public UndefinedPartitionException(String partitionName) { super(ResultCode.UNDEFINED_PARTITION, partitionName); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java index 35ccb70770..bbdb69d31d 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java @@ -21,12 +21,12 @@ import org.apache.tajo.catalog.CatalogUtil; import org.apache.tajo.error.Errors.ResultCode; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UndefinedTableException extends CatalogException { private static final long serialVersionUID = 277182608283894937L; - public UndefinedTableException(PrimitiveProtos.ReturnState state) { + public UndefinedTableException(ReturnState state) { super(state); } diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java index ffe57897fd..f3faf6e77d 100644 --- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java +++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java @@ -19,10 +19,15 @@ package org.apache.tajo.catalog.exception; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UndefinedTablespaceException extends CatalogException { private static final long serialVersionUID = 277182608283894937L; + public UndefinedTablespaceException(ReturnState state) { + super(state); + } + public UndefinedTablespaceException(String spaceName) { super(Errors.ResultCode.UNDEFINED_TABLESPACE, spaceName); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java index 9c74b19abf..902ab90822 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java @@ -18,29 +18,77 @@ package org.apache.tajo.client; -import org.apache.tajo.catalog.exception.DuplicateDatabaseException; -import org.apache.tajo.catalog.exception.UndefinedTableException; -import org.apache.tajo.exception.TajoException; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import com.google.common.collect.Maps; +import org.apache.tajo.catalog.exception.*; +import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.exception.*; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; +import java.lang.reflect.Constructor; +import java.util.Map; + +import static org.apache.tajo.error.Errors.ResultCode.*; import static org.apache.tajo.exception.ReturnStateUtil.isError; +/** + * Exception related utilities. Especially, it provides a way to recover @{link ReturnState} into TajoException. + */ public class ClientExceptionUtil { - public static void throwIfError(PrimitiveProtos.ReturnState state) throws TajoException { + static Map> EXCEPTIONS = Maps.newHashMap(); + + static { + + // General Errors + ADD_EXCEPTION(INTERNAL_ERROR, TajoInternalError.class); + + ADD_EXCEPTION(UNDEFINED_TABLESPACE, UndefinedTablespaceException.class); + ADD_EXCEPTION(UNDEFINED_DATABASE, UndefinedDatabaseException.class); + // ADD_EXCEPTION(UNDEFINED_SCHEMA, ); + ADD_EXCEPTION(UNDEFINED_TABLE, UndefinedTableException.class); + ADD_EXCEPTION(UNDEFINED_COLUMN, UndefinedColumnException.class); + ADD_EXCEPTION(UNDEFINED_FUNCTION, UndefinedFunctionException.class); + ADD_EXCEPTION(UNDEFINED_PARTITION, UndefinedPartitionException.class); + ADD_EXCEPTION(UNDEFINED_OPERATOR, UndefinedOperatorException.class); + + ADD_EXCEPTION(DUPLICATE_TABLESPACE, DuplicateTableException.class); + ADD_EXCEPTION(DUPLICATE_DATABASE, DuplicateDatabaseException.class); + // ADD_EXCEPTION(DUPLICATE_SCHEMA, ); + ADD_EXCEPTION(DUPLICATE_TABLE, DuplicateTableException.class); + ADD_EXCEPTION(DUPLICATE_COLUMN, DuplicateColumnException.class); + // ADD_EXCEPTION(DUPLICATE_ALIAS, ); + ADD_EXCEPTION(DUPLICATE_INDEX, DuplicateIndexException.class); + ADD_EXCEPTION(DUPLICATE_PARTITION, DuplicatePartitionException.class); + + ADD_EXCEPTION(AMBIGUOUS_TABLE, AmbiguousTableException.class); + ADD_EXCEPTION(AMBIGUOUS_COLUMN, AmbiguousColumnException.class); + } + + private static void ADD_EXCEPTION(ResultCode code, Class cls) { + EXCEPTIONS.put(code, cls); + } + + public static void throwIfError(ReturnState state) throws TajoException { if (isError(state)) { throw toTajoException(state); } } - public static TajoException toTajoException(PrimitiveProtos.ReturnState state) { - switch (state.getReturnCode()) { - case DUPLICATE_DATABASE: - return new DuplicateDatabaseException(state); - case UNDEFINED_TABLE: - return new UndefinedTableException(state); - default: - return new TajoException(state); + public static TajoException toTajoException(ReturnState state) { + + if (state.getReturnCode() == ResultCode.INTERNAL_ERROR) { + throw new TajoInternalError(state); + + } else if (EXCEPTIONS.containsKey(state.getReturnCode())) { + try { + Constructor c = EXCEPTIONS.get(state.getReturnCode()).getConstructor(ReturnState.class); + return (TajoException) c.newInstance(new Object[] {state}); + } catch (Throwable t) { + throw new TajoInternalError(t); + } + } else { + throw new TajoInternalError("Unregistred Exception (" + state.getReturnCode().name() +"): " + + state.getMessage()); } } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java new file mode 100644 index 0000000000..ac6283ece0 --- /dev/null +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java @@ -0,0 +1,25 @@ +/** + * 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.client.v2; + +import java.util.EventListener; + +public interface FutureListener extends EventListener { + void processingCompleted(V future); +} diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java index 0cdb68bb6e..b574debe00 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java @@ -53,7 +53,7 @@ public class LegacyClientDelegate extends SessionConnection implements ClientDelegate { private QueryClientImpl queryClient; - private ExecutorService executor = Executors.newFixedThreadPool(8); + private final ExecutorService executor = Executors.newFixedThreadPool(8); public LegacyClientDelegate(String host, int port, Map props) { super(new DummyServiceTracker(NetUtils.createSocketAddr(host, port)), null, new KeyValueSet(props)); @@ -110,7 +110,7 @@ public void selectDB(String db) throws UndefinedDatabaseException { } private class QueryFutureForNoFetch implements QueryFuture { - private final QueryId id; + protected final QueryId id; private final long now = System.currentTimeMillis(); QueryFutureForNoFetch(QueryId id) { @@ -181,6 +181,16 @@ public long finishTime() { return now; } + @Override + public void release() { + queryClient.closeQuery(id); + } + + @Override + public void addListener(FutureListener future) { + future.processingCompleted(this); + } + @Override public boolean cancel(boolean mayInterruptIfRunning) { return false; @@ -235,6 +245,7 @@ private class AsyncQueryFuture extends AbstractFuture implements Quer public AsyncQueryFuture(QueryId queryId) { this.queryId = queryId; + this.lastState = QueryState.SCHEDULED; } @Override @@ -302,6 +313,22 @@ public long finishTime() { return finishTime; } + @Override + public void release() { + queryClient.closeQuery(queryId); + } + + @Override + public void addListener(final FutureListener listener) { + final QueryFuture f = this; + addListener(new Runnable() { + @Override + public void run() { + listener.processingCompleted(f); + }}, + executor); + } + private void updateState(GetQueryStatusResponse lastState) { this.startTime = lastState.getSubmitTime(); this.finishTime = lastState.getFinishTime(); @@ -317,12 +344,12 @@ GetQueryStatusResponse waitCompletion() { while(!TajoClientUtil.isQueryComplete(response.getQueryState())) { try { Thread.sleep(500); - updateState(response); } catch (InterruptedException e) { e.printStackTrace(); } response = queryClient.getRawQueryStatus(queryId); + updateState(response); ensureOk(response.getState()); } return response; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java index 016d8a7c0d..a607342890 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java @@ -18,9 +18,7 @@ package org.apache.tajo.client.v2; -import com.google.common.base.Optional; import org.apache.tajo.auth.UserRoleInfo; -import org.apache.tajo.exception.TajoException; import java.sql.ResultSet; import java.util.concurrent.Future; @@ -112,4 +110,16 @@ public interface QueryFuture extends Future { * @return Millisecond since epoch */ long finishTime(); + + /** + * Release a query future. It will be automatically released after the session invalidation. + */ + void release(); + + /** + * Add a listener which will be executed after this query is completed, error, failed or killed. + * + * @param future + */ + void addListener(FutureListener future); } diff --git a/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java b/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java index 869d7c4716..8f15710cb8 100644 --- a/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java +++ b/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java @@ -87,6 +87,6 @@ public void close() throws SQLException { currentResultSet.close(); currentResultSet = null; } - tajoClient.closeNonForwardQuery(queryId); + tajoClient.closeQuery(queryId); } } diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java b/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java index 7cf6e1efe8..574dc3bec1 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java @@ -18,14 +18,17 @@ package org.apache.tajo.exception; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; + import static org.apache.tajo.error.Errors.ResultCode.AMBIGUOUS_COLUMN; public class AmbiguousColumnException extends TajoException { private static final long serialVersionUID = 3102675985226352347L; - /** - * @param fieldName - */ + public AmbiguousColumnException(ReturnState state) { + super(state); + } + public AmbiguousColumnException(String fieldName) { super(AMBIGUOUS_COLUMN, fieldName); } diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java index d84f53db2e..281331fe5c 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java @@ -21,6 +21,7 @@ import com.google.common.collect.Maps; import org.apache.tajo.error.Errors.ResultCode; import org.apache.tajo.util.Pair; +import org.apache.tajo.util.StringUtils; import java.util.Map; @@ -133,7 +134,7 @@ public static String getMessage(ResultCode code, String...args) { } } else { - throw new TajoRuntimeException(code, args); + throw new TajoInternalError("Argument mismatch: code=" + code.name() + ", args=" + StringUtils.join(args)); } } } diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java index dbb2748965..765ead394e 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java @@ -19,6 +19,8 @@ package org.apache.tajo.exception; import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; /** * Unrecoverable errors @@ -26,6 +28,11 @@ public class TajoError extends Error implements TajoExceptionInterface { private ResultCode code; + public TajoError(ReturnState state) { + super(state.getMessage()); + code = state.getReturnCode(); + } + public TajoError(ResultCode code) { super(ErrorMessages.getMessage(code)); this.code = code; diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java index 767c13ca5b..072636b5d8 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java @@ -19,12 +19,18 @@ package org.apache.tajo.exception; import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; /** * Exception for Internal Bugs and Unexpected exception */ public class TajoInternalError extends TajoError { + public TajoInternalError(ReturnState state) { + super(state); + } + public TajoInternalError(String message) { super(ResultCode.INTERNAL_ERROR, message); } diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java index 9d91946785..70586c9c9e 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java @@ -19,9 +19,14 @@ package org.apache.tajo.exception; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UndefinedOperatorException extends TajoException { + public UndefinedOperatorException(ReturnState state) { + super(state); + } + public UndefinedOperatorException(String operation) { super(Errors.ResultCode.UNDEFINED_OPERATOR, operation); } diff --git a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java index bc4565a63d..f88c0bfb02 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java @@ -18,6 +18,7 @@ package org.apache.tajo.client.v2; +import com.facebook.presto.hive.shaded.com.google.common.collect.Lists; import org.apache.tajo.QueryTestCaseBase; import org.apache.tajo.catalog.exception.DuplicateDatabaseException; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; @@ -33,9 +34,11 @@ import java.net.InetSocketAddress; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public class TestTajoClientV2 extends QueryTestCaseBase { private static TajoClient clientv2; @@ -125,6 +128,97 @@ public void testExecuteQueryType3() throws TajoException, IOException, SQLExcept } } + @Test + public void testExecuteQueryAsync() throws TajoException, IOException, SQLException, ExecutionException, + InterruptedException { + QueryFuture future = clientv2.executeQueryAsync("select * from lineitem where l_orderkey > 0"); + + ResultSet result = future.get(); + assertResultSet(result); + + assertTrue(future.isDone()); + assertEquals(QueryState.COMPLETED, future.state()); + assertTrue(future.isCompleted()); + assertFalse(future.isFailed()); + assertFalse(future.isKilled()); + assertTrue(1.0f == future.progress()); + assertEquals("default", future.queue()); + + assertTrue(future.submitTime() > 0); + assertTrue(future.startTime() > 0); + assertTrue(future.finishTime() > 0); + + result.close(); + } + + @Test(timeout = 10 * 1000) + public void testExecuteQueryAsyncWithListener() throws TajoException, IOException, SQLException, ExecutionException, + InterruptedException { + QueryFuture future = clientv2.executeQueryAsync( + "select l_orderkey, sleep(1) from lineitem where l_orderkey > 3"); + + final AtomicBoolean success = new AtomicBoolean(false); + final List resultContainer = Lists.newArrayList(); + + future.addListener(new FutureListener() { + @Override + public void processingCompleted(QueryFuture future) { + try { + ResultSet result = future.get(); + resultContainer.add(result); // for better error handling, it should be verified outside this future. + + assertTrue(future.isDone()); + assertEquals(QueryState.COMPLETED, future.state()); + assertTrue(future.isCompleted()); + assertFalse(future.isFailed()); + assertFalse(future.isKilled()); + assertTrue(1.0f == future.progress()); + assertEquals("default", future.queue()); + + assertTrue(future.submitTime() > 0); + assertTrue(future.startTime() > 0); + assertTrue(future.finishTime() > 0); + + success.set(true); + + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + }); + + while(!future.isDone()) { + Thread.sleep(100); + } + + assertTrue(success.get()); + assertResultSet(resultContainer.get(0)); + resultContainer.get(0).close(); + } + + @Test(timeout = 10 * 1000) + public void testQueryFutureKill() throws TajoException, ExecutionException, InterruptedException, SQLException { + QueryFuture future = clientv2.executeQueryAsync("select sleep(1) from lineitem where l_orderkey > 4"); + + assertTrue(future.isOk()); + assertFalse(future.isDone()); + assertFalse(future.isCompleted()); + assertFalse(future.isFailed()); + assertFalse(future.isKilled()); + + future.kill(); + while(!future.isDone()) { + Thread.sleep(100); + } + + assertTrue(future.isOk()); + assertTrue(future.isDone()); + assertFalse(future.isCompleted()); + assertFalse(future.isFailed()); + assertTrue(future.isKilled()); + } + + @Test(expected = DuplicateDatabaseException.class) public void testErrorOnExecuteUpdate() throws TajoException, IOException, SQLException { clientv2.executeUpdate("create database default"); @@ -134,4 +228,9 @@ public void testErrorOnExecuteUpdate() throws TajoException, IOException, SQLExc public void testErrorOnExecuteQuery() throws TajoException, IOException, SQLException { clientv2.executeQuery("select * from unknown_table"); } + + @Test(expected = UndefinedTableException.class) + public void testErrorOnExecuteQueryAsync() throws TajoException { + clientv2.executeQueryAsync("select * from unknown_table"); + } } diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result new file mode 100644 index 0000000000..ec6b9110c3 --- /dev/null +++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result @@ -0,0 +1,7 @@ +l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment +------------------------------- +1,1,7706,1,17.0,21168.23,0.04,0.02,N,O,1996-03-13,1996-02-12,1996-03-22,DELIVER IN PERSON,TRUCK,egular courts above the +1,1,7311,2,36.0,45983.16,0.09,0.06,N,O,1996-04-12,1996-02-28,1996-04-20,TAKE BACK RETURN,MAIL,ly final dependencies: slyly bold +2,2,1191,1,38.0,44694.46,0.0,0.05,N,O,1997-01-28,1997-01-14,1997-02-02,TAKE BACK RETURN,RAIL,ven requests. deposits breach a +3,2,1798,1,45.0,54058.05,0.06,0.0,R,F,1994-02-02,1994-01-04,1994-02-23,NONE,AIR,ongside of the furiously brave acco +3,3,6540,2,49.0,46796.47,0.1,0.0,R,F,1993-11-09,1993-12-20,1993-11-24,TAKE BACK RETURN,RAIL, unusual accounts. eve \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result new file mode 100644 index 0000000000..7a51ca307c --- /dev/null +++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result @@ -0,0 +1,2 @@ +l_orderkey,?sleep +------------------------------- \ No newline at end of file From 631263e5b823bcee51c9758f4c572e632a578e01 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Wed, 29 Jul 2015 16:52:46 +0900 Subject: [PATCH 7/8] Fixed unit tests and fixed exception handling. --- .../org/apache/tajo/catalog/TestSchema.java | 3 +- .../tajo/client/ClientExceptionUtil.java | 16 ++++++- .../tajo/client/DummyServiceTracker.java | 1 + .../org/apache/tajo/client/ResultSetUtil.java | 2 + .../tajo/exception/UnsupportedException.java | 5 +++ .../apache/tajo/client/TestTajoClient.java | 10 ++--- .../tajo/client/TestTajoClientFailures.java | 8 ++-- .../apache/tajo/engine/eval/ExprTestBase.java | 2 +- .../org/apache/tajo/jdbc/TestTajoJdbc.java | 44 ------------------- .../org/apache/tajo/jdbc/MetaDataTuple.java | 17 +++---- .../tajo/plan/expr/BasicEvalNodeVisitor.java | 1 + .../tajo/plan/expr/SimpleEvalNodeVisitor.java | 3 +- .../tajo/plan/function/AggFunctionInvoke.java | 2 + .../tajo/plan/function/FunctionInvoke.java | 1 + .../function/stream/CSVLineSerializer.java | 2 +- .../TextFieldSerializerDeserializer.java | 1 + .../tajo/plan/logical/SetSessionNode.java | 1 + .../tajo/plan/verifier/VerificationState.java | 6 +++ .../org/apache/tajo/storage/FrameTuple.java | 1 + .../org/apache/tajo/storage/NullScanner.java | 1 + .../org/apache/tajo/storage/RowStoreUtil.java | 3 +- .../org/apache/tajo/storage/Tablespace.java | 4 +- .../apache/tajo/tuple/offheap/HeapTuple.java | 1 + .../tajo/tuple/offheap/UnSafeTuple.java | 2 + 24 files changed, 67 insertions(+), 70 deletions(-) diff --git a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java index cf1a24a19c..4c251af95e 100644 --- a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java +++ b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java @@ -22,6 +22,7 @@ import org.apache.tajo.catalog.json.CatalogGsonHelper; import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto; import org.apache.tajo.common.TajoDataTypes.Type; +import org.apache.tajo.exception.TajoRuntimeException; import org.junit.Before; import org.junit.Test; @@ -191,7 +192,7 @@ public final void testClone() throws CloneNotSupportedException { assertEquals(schema.size(), schema3.size()); } - @Test(expected = DuplicateColumnException.class) + @Test(expected = TajoRuntimeException.class) public final void testAddExistColumn() { Schema schema = new Schema(); schema.addColumn("abc", Type.FLOAT8); diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java index 902ab90822..2ecc0780bf 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java @@ -41,6 +41,7 @@ public class ClientExceptionUtil { // General Errors ADD_EXCEPTION(INTERNAL_ERROR, TajoInternalError.class); + ADD_EXCEPTION(FEATURE_NOT_SUPPORTED, UnsupportedException.class); ADD_EXCEPTION(UNDEFINED_TABLESPACE, UndefinedTablespaceException.class); ADD_EXCEPTION(UNDEFINED_DATABASE, UndefinedDatabaseException.class); @@ -80,12 +81,23 @@ public static TajoException toTajoException(ReturnState state) { throw new TajoInternalError(state); } else if (EXCEPTIONS.containsKey(state.getReturnCode())) { + Object exception = null; try { - Constructor c = EXCEPTIONS.get(state.getReturnCode()).getConstructor(ReturnState.class); - return (TajoException) c.newInstance(new Object[] {state}); + Class clazz = EXCEPTIONS.get(state.getReturnCode()); + Constructor c = clazz.getConstructor(ReturnState.class); + exception = c.newInstance(new Object[]{state}); } catch (Throwable t) { throw new TajoInternalError(t); } + + if (exception instanceof TajoException) { + return (TajoException) exception; + } else if (exception instanceof TajoRuntimeException) { + throw ((TajoRuntimeException) exception); + } else { + throw ((TajoError) exception); + } + } else { throw new TajoInternalError("Unregistred Exception (" + state.getReturnCode().name() +"): " + state.getMessage()); diff --git a/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java b/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java index cf826ea285..bb6ace82f1 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java @@ -19,6 +19,7 @@ package org.apache.tajo.client; import org.apache.tajo.conf.TajoConf; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.service.ServiceTracker; import org.apache.tajo.service.ServiceTrackerException; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java index 9211a1b851..4c807d4a56 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java @@ -19,6 +19,8 @@ package org.apache.tajo.client; import org.apache.tajo.common.TajoDataTypes; +import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import java.sql.ResultSet; diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java index 9ca55394b2..a7a3915de0 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java @@ -19,10 +19,15 @@ package org.apache.tajo.exception; import org.apache.tajo.error.Errors; +import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; public class UnsupportedException extends TajoRuntimeException { private static final long serialVersionUID = 6702291354858193578L; + public UnsupportedException(ReturnState state) { + super(state); + } + public UnsupportedException(String featureName) { super(Errors.ResultCode.FEATURE_NOT_SUPPORTED, featureName); } diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java index 701e880c14..0ba0d76a4e 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java @@ -37,6 +37,7 @@ import org.apache.tajo.error.Errors; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoRuntimeException; +import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto; import org.apache.tajo.ipc.ClientProtos.QueryInfoProto; @@ -542,8 +543,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc try { client.updateQuery(rangeSql); fail(); - } catch (TajoRuntimeException se) { - assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode()); + } catch (UnsupportedException se) { } String listSql = "create table " + tableName + " (deptname text, score int4)"; @@ -554,8 +554,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc try { assertFalse(client.updateQuery(listSql)); fail(); - } catch (TajoRuntimeException se) { - assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode()); + } catch (UnsupportedException se) { } String hashSql = "create table " + tableName + " (deptname text, score int4)"; @@ -565,8 +564,7 @@ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOExc try { assertFalse(client.updateQuery(hashSql)); fail(); - } catch (TajoRuntimeException se) { - assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode()); + } catch (UnsupportedException se) { } } diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java index 6d49369f11..b745caad4a 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java @@ -21,6 +21,8 @@ import net.jcip.annotations.NotThreadSafe; import org.apache.tajo.TajoTestingCluster; import org.apache.tajo.TpchTestBase; +import org.apache.tajo.catalog.exception.DuplicateDatabaseException; +import org.apache.tajo.catalog.exception.UndefinedDatabaseException; import org.apache.tajo.catalog.exception.UndefinedTableException; import org.apache.tajo.error.Errors; import org.apache.tajo.exception.TajoException; @@ -50,17 +52,17 @@ public static void tearDown() throws Exception { client.close(); } - @Test + @Test(expected = DuplicateDatabaseException.class) public final void testCreateDatabase() throws TajoException { assertFalse(client.createDatabase("default")); // duplicate database } - @Test + @Test(expected = UndefinedDatabaseException.class) public final void testDropDatabase() throws TajoException { assertFalse(client.dropDatabase("unknown-database")); // unknown database } - @Test + @Test(expected = UndefinedTableException.class) public final void testDropTable() throws UndefinedTableException { assertFalse(client.dropTable("unknown-table")); // unknown table } diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java index b18bd691ac..7586fd7533 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java @@ -324,7 +324,7 @@ public void testEval(OverridableConf context, Schema schema, String tableName, S if (!condition) { assertEquals(expected[0], e.getMessage()); } else { - assertFalse(e.getMessage(), true); + throw e; } } finally { if (schema != null) { diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java index be86a18ee9..acbc1a888e 100644 --- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java +++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java @@ -400,50 +400,6 @@ public void testMultipleConnectionsSequentialClose() throws Exception { } } - @Test - public void testSetPreparedStatement() throws Exception { - String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(), - DEFAULT_DATABASE_NAME); - - Connection conn = DriverManager.getConnection(connUri); - - PreparedStatement stmt = null; - ResultSet res = null; - try { - stmt = conn.prepareStatement("Set JOIN_TASK_INPUT_SIZE 123"); - res = stmt.executeQuery(); - assertFalse(res.next()); - ResultSetMetaData rsmd = res.getMetaData(); - assertNotNull(rsmd); - assertEquals(0, rsmd.getColumnCount()); - - QueryClient connTajoClient = ((JdbcConnection) stmt.getConnection()).getQueryClient(); - Map variables = connTajoClient.getAllSessionVariables(); - String value = variables.get("JOIN_TASK_INPUT_SIZE"); - assertNotNull(value); - assertEquals("123", value); - - res.close(); - stmt.close(); - - stmt = conn.prepareStatement("unset JOIN_TASK_INPUT_SIZE"); - res = stmt.executeQuery(); - variables = connTajoClient.getAllSessionVariables(); - value = variables.get("JOIN_TASK_INPUT_SIZE"); - assertNull(value); - } finally { - if (res != null) { - res.close(); - } - if (stmt != null) { - stmt.close(); - } - if (conn != null) { - conn.close(); - } - } - } - @Test public void testCreateTableWithDateAndTimestamp() throws Exception { String tableName = CatalogUtil.normalizeIdentifier("testCreateTableWithDateAndTimestamp"); diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java index fad285c67c..28b6b3c63c 100644 --- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java +++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java @@ -23,6 +23,7 @@ import org.apache.tajo.datum.IntervalDatum; import org.apache.tajo.datum.NullDatum; import org.apache.tajo.datum.ProtobufDatum; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; import org.apache.tajo.util.datetime.TimeMeta; @@ -94,7 +95,7 @@ public int size(int fieldId) { @Override public void clearOffset() { - throw new UnsupportedException("clearOffset"); + throw new UnsupportedException(); } @Override @@ -104,12 +105,12 @@ public Datum asDatum(int fieldId) { @Override public void setOffset(long offset) { - throw new UnsupportedException("setOffset"); + throw new UnsupportedException(); } @Override public long getOffset() { - throw new UnsupportedException("getOffset"); + throw new UnsupportedException(); } @Override @@ -129,7 +130,7 @@ public char getChar(int fieldId) { @Override public byte [] getBytes(int fieldId) { - throw new UnsupportedException("BlobDatum"); + throw new UnsupportedException(); } @Override @@ -174,12 +175,12 @@ public TimeMeta getTimeDate(int fieldId) { @Override public ProtobufDatum getProtobufDatum(int fieldId) { - throw new UnsupportedException("getProtobufDatum"); + throw new UnsupportedException(); } @Override public IntervalDatum getInterval(int fieldId) { - throw new UnsupportedException("getInterval"); + throw new UnsupportedException(); } @Override @@ -189,11 +190,11 @@ public char[] getUnicodeChars(int fieldId) { @Override public Tuple clone() throws CloneNotSupportedException { - throw new UnsupportedException("clone"); + throw new UnsupportedException(); } @Override public Datum[] getValues(){ - throw new UnsupportedException("getValues"); + throw new UnsupportedException(); } } diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java index 81b0f8e9dc..128cc7c4de 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java @@ -18,6 +18,7 @@ package org.apache.tajo.plan.expr; +import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.exception.UnsupportedException; import java.util.Stack; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java index e706391c38..61a25a9af3 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java @@ -19,6 +19,7 @@ package org.apache.tajo.plan.expr; import com.google.common.base.Preconditions; +import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.exception.UnsupportedException; import java.util.Stack; @@ -76,7 +77,7 @@ public EvalNode visit(CONTEXT context, EvalNode evalNode, Stack stack) break; default: - throw new UnsupportedException("Unknown EvalType: " + evalNode); + throw new TajoInternalError("Unknown EvalType: " + evalNode); } } diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java index 2c2afbe2b4..d1b1b3b1ee 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java @@ -23,6 +23,8 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.Datum; import org.apache.tajo.exception.InternalException; +import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java index b8b5cfe66e..3b7c0f56c3 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java @@ -22,6 +22,7 @@ import org.apache.tajo.catalog.FunctionDesc; import org.apache.tajo.datum.Datum; import org.apache.tajo.exception.InternalException; +import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java index 78404b0cff..64586bd603 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java @@ -23,6 +23,7 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.AnyDatum; import org.apache.tajo.datum.Datum; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.function.FunctionContext; import org.apache.tajo.plan.function.PythonAggFunctionInvoke.PythonAggFunctionContext; @@ -110,7 +111,6 @@ public int serializeContext(OutputStream out, FunctionContext context) throws IO @Override public void release() { - } public static String getTypeString(Datum val) { diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java index c22a0f2ac9..85814ef182 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java @@ -28,6 +28,7 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.*; import org.apache.tajo.datum.protobuf.ProtobufJsonFormat; +import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.exception.ValueTooLongForTypeCharactersException; import org.apache.tajo.storage.StorageConstants; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java index 117315f104..7288447dc1 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java @@ -19,6 +19,7 @@ package org.apache.tajo.plan.logical; import com.google.gson.annotations.Expose; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.PlanString; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java b/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java index d20f8f92d8..fd16d115f5 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.tajo.exception.TajoError; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoExceptionInterface; import org.apache.tajo.exception.TajoRuntimeException; @@ -32,6 +33,11 @@ public class VerificationState { private static final Log LOG = LogFactory.getLog(VerificationState.class); List errorMessages = Lists.newArrayList(); + public void addVerification(TajoError error) { + LOG.warn(TUtil.getCurrentCodePoint(1) + " causes: " + error.getMessage()); + errorMessages.add(error); + } + public void addVerification(TajoException error) { LOG.warn(TUtil.getCurrentCodePoint(1) + " causes: " + error.getMessage()); errorMessages.add(error); diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java index de39d0893a..ef07a5b809 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java @@ -26,6 +26,7 @@ import org.apache.tajo.datum.Datum; import org.apache.tajo.datum.IntervalDatum; import org.apache.tajo.datum.ProtobufDatum; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.util.datetime.TimeMeta; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java index 83d8e243f0..21c2b18ebd 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java @@ -21,6 +21,7 @@ import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableMeta; import org.apache.tajo.catalog.statistics.TableStats; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.expr.EvalNode; import org.apache.tajo.storage.fragment.Fragment; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java index 51cedb2149..a1c4e2bbf2 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java @@ -24,6 +24,7 @@ import org.apache.tajo.datum.DatumFactory; import org.apache.tajo.datum.IntervalDatum; import org.apache.tajo.datum.ProtobufDatum; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnknownDataTypeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.exception.ValueTooLongForTypeCharactersException; @@ -381,7 +382,7 @@ public static void convert(Tuple tuple, RowWriter writer) { writer.skipField(); break; default: - throw new UnsupportedException("Unknown data type: " + writer.dataTypes()[i]); + throw new UnsupportedException("data type " + writer.dataTypes()[i]); } } writer.endRow(); diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java index f8883b090a..5b8cc6b07b 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java @@ -29,6 +29,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.FragmentProto; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.exception.TajoException; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.logical.LogicalNode; @@ -107,8 +108,7 @@ public String toString() { * @return Root URI */ public URI getRootUri() { - throw new UnsupportedException( - String.format("Tablespace '%s' does not allow the use of artibrary paths", uri.toString())); + throw new UnsupportedException(String.format("artibrary path '%s'", uri.toString())); } /** diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java index 8f36b35726..d94dbc01f7 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java @@ -23,6 +23,7 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.*; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; import org.apache.tajo.storage.VTuple; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java index 4ccba7ba4d..9fffe0c1a1 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java @@ -24,6 +24,8 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.*; +import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; import org.apache.tajo.storage.VTuple; From d3631e72a4f5474012fb88d48c9d993603a77416 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Mon, 3 Aug 2015 14:18:52 +0900 Subject: [PATCH 8/8] Removed many unused imports and fixed some signatures. --- .../InfoSchemaMetadataDictionary.java | 6 +++++- .../tajo/catalog/store/AbstractDBStore.java | 6 +----- .../apache/tajo/client/CatalogAdminClient.java | 3 +-- .../tajo/client/CatalogAdminClientImpl.java | 9 +-------- .../tajo/client/DummyServiceTracker.java | 1 - .../org/apache/tajo/client/QueryClient.java | 4 ---- .../org/apache/tajo/client/ResultSetUtil.java | 2 -- .../org/apache/tajo/client/TajoClientImpl.java | 4 +--- ...Factory.java => ClientDelegateFactory.java} | 6 +++--- .../tajo/client/v2/LegacyClientDelegate.java | 4 ++-- .../org/apache/tajo/client/v2/QueryFuture.java | 10 +++++++++- .../tajo/client/v2/ServiceDiscovery.java | 3 +++ .../org/apache/tajo/client/v2/TajoClient.java | 18 ++++++------------ .../apache/tajo/exception/ExceptionUtil.java | 5 ----- .../tajo/client/v2/TestTajoClientV2.java | 8 ++++---- .../tajo/engine/eval/TestSQLExpression.java | 3 +-- .../tajo/plan/function/AggFunctionInvoke.java | 2 -- .../tajo/plan/function/FunctionInvoke.java | 1 - .../function/stream/CSVLineSerializer.java | 1 - .../TextFieldSerializerDeserializer.java | 1 - .../tajo/plan/logical/SetSessionNode.java | 1 - .../rewrite/rules/ProjectionPushDownRule.java | 2 -- .../org/apache/tajo/storage/FrameTuple.java | 1 - .../org/apache/tajo/storage/NullScanner.java | 5 +++-- .../org/apache/tajo/storage/RowStoreUtil.java | 1 - .../org/apache/tajo/storage/Tablespace.java | 1 - .../apache/tajo/tuple/offheap/HeapTuple.java | 3 --- .../apache/tajo/tuple/offheap/UnSafeTuple.java | 4 ---- 28 files changed, 40 insertions(+), 75 deletions(-) rename tajo-client/src/main/java/org/apache/tajo/client/v2/{ClientDeligateFactory.java => ClientDelegateFactory.java} (89%) diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java index 4f481820f9..b59d61caab 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java @@ -106,7 +106,11 @@ private TableDescriptor getTableDescriptor(String tableName) throws UndefinedTab break; } } - + + if (tableDescriptor == null) { + throw new UndefinedTableException(tableName); + } + return tableDescriptor; } 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 9f8192dca8..a3eb0c3a6b 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 @@ -170,11 +170,7 @@ public AbstractDBStore(Configuration conf) throws InternalException { createBaseTable(); LOG.info("The base tables of CatalogServer are created."); } catch (CatalogException ce) { - try { - dropBaseTable(); - } catch (Throwable t) { - LOG.error(t, t); - } + dropBaseTable(); throw ce; } } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java index 9d4382ff22..bc63f84241 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java @@ -137,8 +137,7 @@ TableDesc createExternalTable(final String tableName, final Schema schema, final */ TableDesc getTableDesc(final String tableName) throws UndefinedTableException; - List getFunctions(final String functionName) - throws AmbiguousFunctionException, UndefinedFunctionException; + List getFunctions(final String functionName); IndexDescProto getIndex(final String indexName) throws SQLException; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java index 560aa6025c..d4d8a8610a 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java @@ -240,8 +240,7 @@ public TableDesc getTableDesc(final String tableName) throws UndefinedTableExcep } @Override - public List getFunctions(final String functionName) - throws AmbiguousFunctionException, UndefinedFunctionException { + public List getFunctions(final String functionName) { final BlockingInterface stub = conn.getTMStub(); @@ -253,12 +252,6 @@ public List getFunctions(final String functionName) throw new RuntimeException(e); } - if (isThisError(res.getState(), Errors.ResultCode.AMBIGUOUS_FUNCTION)) { - throw new AmbiguousFunctionException(res.getState()); - } else if (isThisError(res.getState(), Errors.ResultCode.UNDEFINED_FUNCTION)) { - throw new UndefinedFunctionException(res.getState()); - } - ensureOk(res.getState()); return res.getFunctionList(); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java b/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java index bb6ace82f1..cf826ea285 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/DummyServiceTracker.java @@ -19,7 +19,6 @@ package org.apache.tajo.client; import org.apache.tajo.conf.TajoConf; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.service.ServiceTracker; import org.apache.tajo.service.ServiceTrackerException; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java index 0847f71f28..966bddf2a3 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java @@ -18,7 +18,6 @@ package org.apache.tajo.client; -import com.google.protobuf.ServiceException; import org.apache.tajo.QueryId; import org.apache.tajo.auth.UserRoleInfo; import org.apache.tajo.catalog.exception.UndefinedDatabaseException; @@ -31,14 +30,11 @@ import org.apache.tajo.jdbc.TajoMemoryResultSet; import java.io.Closeable; -import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; -import static org.apache.tajo.TajoIdProtos.SessionIdProto; - public interface QueryClient extends Closeable { boolean isConnected(); diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java index 4c807d4a56..9211a1b851 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/ResultSetUtil.java @@ -19,8 +19,6 @@ package org.apache.tajo.client; import org.apache.tajo.common.TajoDataTypes; -import org.apache.tajo.exception.TajoInternalError; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import java.sql.ResultSet; diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java index a98deec8ab..8c167a4d9e 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java @@ -227,9 +227,7 @@ public TableDesc getTableDesc(final String tableName) throws UndefinedTableExcep return catalogClient.getTableDesc(tableName); } - public List getFunctions(final String functionName) - throws AmbiguousFunctionException, UndefinedFunctionException { - + public List getFunctions(final String functionName) { return catalogClient.getFunctions(functionName); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java similarity index 89% rename from tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java rename to tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java index 656c2e33ce..44721b3c3f 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDeligateFactory.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java @@ -23,9 +23,9 @@ import java.util.Map; -public class ClientDeligateFactory { +public class ClientDelegateFactory { - public static ClientDelegate newDefaultDeligate(String host, + public static ClientDelegate newDefaultDelegate(String host, int port, @Nullable Map props) throws ClientUnableToConnectException { @@ -33,7 +33,7 @@ public static ClientDelegate newDefaultDeligate(String host, return new LegacyClientDelegate(host, port, props); } - public static ClientDelegate newDefaultDeligate(ServiceDiscovery discovery, + public static ClientDelegate newDefaultDelegate(ServiceDiscovery discovery, @Nullable Map props) throws ClientUnableToConnectException { diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java index b574debe00..a17311b0a3 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java @@ -143,7 +143,7 @@ public boolean isOk() { } @Override - public boolean isCompleted() { + public boolean isSuccessful() { return true; } @@ -259,7 +259,7 @@ public boolean isOk() { } @Override - public boolean isCompleted() { + public boolean isSuccessful() { return lastState == QueryState.COMPLETED; } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java index a607342890..f1604cd53f 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java @@ -23,6 +23,9 @@ import java.sql.ResultSet; import java.util.concurrent.Future; +/** + * + */ public interface QueryFuture extends Future { /** * Get a query id @@ -31,6 +34,11 @@ public interface QueryFuture extends Future { */ String id(); + /** + * Get the queue name that the query is running + * + * @return queue name + */ String queue(); /** @@ -59,7 +67,7 @@ public interface QueryFuture extends Future { * * @return True if the query is successfully completed. */ - boolean isCompleted(); + boolean isSuccessful(); /** * Get whether the query is abort due to error. diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java index 1a87808135..e69ca8aa29 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java @@ -20,6 +20,9 @@ import java.net.InetSocketAddress; +/** + * Client service discovery interface + */ public interface ServiceDiscovery { InetSocketAddress clientAddress(); } diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java index 01a1c5c87b..08a921d994 100644 --- a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java +++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java @@ -21,17 +21,11 @@ import org.apache.tajo.catalog.exception.UndefinedDatabaseException; import org.apache.tajo.client.v2.exception.ClientUnableToConnectException; import org.apache.tajo.exception.TajoException; -import org.apache.tajo.exception.TajoRuntimeException; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState; import java.io.Closeable; import java.io.IOException; import java.sql.ResultSet; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; public class TajoClient implements Closeable { /** @@ -47,7 +41,7 @@ public class TajoClient implements Closeable { * @param host hostname to connect */ public TajoClient(String host) throws ClientUnableToConnectException { - delegate = ClientDeligateFactory.newDefaultDeligate(host, DEFAULT_PORT, null); + delegate = ClientDelegateFactory.newDefaultDelegate(host, DEFAULT_PORT, null); } /** @@ -57,7 +51,7 @@ public TajoClient(String host) throws ClientUnableToConnectException { * @param properties Connection properties */ public TajoClient(String host, Map properties) throws ClientUnableToConnectException { - delegate = ClientDeligateFactory.newDefaultDeligate(host, DEFAULT_PORT, properties); + delegate = ClientDelegateFactory.newDefaultDelegate(host, DEFAULT_PORT, properties); } /** @@ -67,7 +61,7 @@ public TajoClient(String host, Map properties) throws ClientUnab * @param port Port number to connect */ public TajoClient(String host, int port) throws ClientUnableToConnectException { - delegate = ClientDeligateFactory.newDefaultDeligate(host, port, null); + delegate = ClientDelegateFactory.newDefaultDelegate(host, port, null); } /** @@ -78,7 +72,7 @@ public TajoClient(String host, int port) throws ClientUnableToConnectException { * @param properties Connection properties */ public TajoClient(String host, int port, Map properties) throws ClientUnableToConnectException { - delegate = ClientDeligateFactory.newDefaultDeligate(host, port, properties); + delegate = ClientDelegateFactory.newDefaultDelegate(host, port, properties); } /** @@ -87,7 +81,7 @@ public TajoClient(String host, int port, Map properties) throws * @param discovery Service discovery */ public TajoClient(ServiceDiscovery discovery) throws ClientUnableToConnectException { - delegate = ClientDeligateFactory.newDefaultDeligate(discovery, null); + delegate = ClientDelegateFactory.newDefaultDelegate(discovery, null); } /** @@ -97,7 +91,7 @@ public TajoClient(ServiceDiscovery discovery) throws ClientUnableToConnectExcept * @param properties Connection properties */ public TajoClient(ServiceDiscovery discovery, Map properties) throws ClientUnableToConnectException { - delegate = ClientDeligateFactory.newDefaultDeligate(discovery, properties); + delegate = ClientDelegateFactory.newDefaultDelegate(discovery, properties); } /** diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java b/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java index d97c478f5b..bc01cb9f9d 100644 --- a/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java +++ b/tajo-common/src/main/java/org/apache/tajo/exception/ExceptionUtil.java @@ -21,11 +21,6 @@ import org.apache.commons.logging.Log; import org.apache.hadoop.util.StringUtils; import org.apache.tajo.common.TajoDataTypes.DataType; -import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos; - -import java.sql.SQLException; - -import static org.apache.tajo.exception.ReturnStateUtil.isError; public class ExceptionUtil { diff --git a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java index f88c0bfb02..99b7c15b64 100644 --- a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java +++ b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java @@ -138,7 +138,7 @@ public void testExecuteQueryAsync() throws TajoException, IOException, SQLExcept assertTrue(future.isDone()); assertEquals(QueryState.COMPLETED, future.state()); - assertTrue(future.isCompleted()); + assertTrue(future.isSuccessful()); assertFalse(future.isFailed()); assertFalse(future.isKilled()); assertTrue(1.0f == future.progress()); @@ -169,7 +169,7 @@ public void processingCompleted(QueryFuture future) { assertTrue(future.isDone()); assertEquals(QueryState.COMPLETED, future.state()); - assertTrue(future.isCompleted()); + assertTrue(future.isSuccessful()); assertFalse(future.isFailed()); assertFalse(future.isKilled()); assertTrue(1.0f == future.progress()); @@ -202,7 +202,7 @@ public void testQueryFutureKill() throws TajoException, ExecutionException, Inte assertTrue(future.isOk()); assertFalse(future.isDone()); - assertFalse(future.isCompleted()); + assertFalse(future.isSuccessful()); assertFalse(future.isFailed()); assertFalse(future.isKilled()); @@ -213,7 +213,7 @@ public void testQueryFutureKill() throws TajoException, ExecutionException, Inte assertTrue(future.isOk()); assertTrue(future.isDone()); - assertFalse(future.isCompleted()); + assertFalse(future.isSuccessful()); assertFalse(future.isFailed()); assertTrue(future.isKilled()); } diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java index 4dcb7e127f..684f0f2e43 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java @@ -30,7 +30,6 @@ import org.apache.tajo.util.datetime.DateTimeUtil; import org.junit.Test; -import java.io.IOException; import java.util.TimeZone; import static org.apache.tajo.common.TajoDataTypes.Type.*; @@ -39,7 +38,7 @@ public class TestSQLExpression extends ExprTestBase { @Test - public void testQuotedIdentifiers() throws Throwable { + public void testQuotedIdentifiers() throws TajoException { Schema schema = new Schema(); schema.addColumn("컬럼1", TEXT); schema.addColumn("컬럼2", TEXT); diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java index d1b1b3b1ee..2c2afbe2b4 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/AggFunctionInvoke.java @@ -23,8 +23,6 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.Datum; import org.apache.tajo.exception.InternalException; -import org.apache.tajo.exception.TajoInternalError; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java index 3b7c0f56c3..b8b5cfe66e 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/FunctionInvoke.java @@ -22,7 +22,6 @@ import org.apache.tajo.catalog.FunctionDesc; import org.apache.tajo.datum.Datum; import org.apache.tajo.exception.InternalException; -import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java index 64586bd603..77f0a03f20 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java @@ -23,7 +23,6 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.AnyDatum; import org.apache.tajo.datum.Datum; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.function.FunctionContext; import org.apache.tajo.plan.function.PythonAggFunctionInvoke.PythonAggFunctionContext; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java index 85814ef182..c22a0f2ac9 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/TextFieldSerializerDeserializer.java @@ -28,7 +28,6 @@ import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.*; import org.apache.tajo.datum.protobuf.ProtobufJsonFormat; -import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.exception.ValueTooLongForTypeCharactersException; import org.apache.tajo.storage.StorageConstants; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java index 7288447dc1..117315f104 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/SetSessionNode.java @@ -19,7 +19,6 @@ package org.apache.tajo.plan.logical; import com.google.gson.annotations.Expose; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.PlanString; diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java index cf8ea6db2b..18e001e45e 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java @@ -21,7 +21,6 @@ import com.google.common.collect.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.tajo.OverridableConf; import org.apache.tajo.annotation.Nullable; import org.apache.tajo.catalog.Column; import org.apache.tajo.catalog.Schema; @@ -30,7 +29,6 @@ import org.apache.tajo.catalog.exception.DuplicateColumnException; import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoInternalError; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.LogicalPlan.QueryBlock; import org.apache.tajo.plan.LogicalPlanner; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java index ef07a5b809..de39d0893a 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/FrameTuple.java @@ -26,7 +26,6 @@ import org.apache.tajo.datum.Datum; import org.apache.tajo.datum.IntervalDatum; import org.apache.tajo.datum.ProtobufDatum; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.util.datetime.TimeMeta; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java index 21c2b18ebd..46b17263ff 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java @@ -1,4 +1,4 @@ -package org.apache.tajo.storage; /** +/** * 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 @@ -16,12 +16,13 @@ * limitations under the License. */ +package org.apache.tajo.storage; + import org.apache.hadoop.conf.Configuration; import org.apache.tajo.catalog.Column; import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableMeta; import org.apache.tajo.catalog.statistics.TableStats; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.expr.EvalNode; import org.apache.tajo.storage.fragment.Fragment; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java index a1c4e2bbf2..bfe4e5566e 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java @@ -24,7 +24,6 @@ import org.apache.tajo.datum.DatumFactory; import org.apache.tajo.datum.IntervalDatum; import org.apache.tajo.datum.ProtobufDatum; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnknownDataTypeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.exception.ValueTooLongForTypeCharactersException; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java index 59d15d9d0b..968601c78e 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java @@ -29,7 +29,6 @@ import org.apache.tajo.catalog.proto.CatalogProtos.FragmentProto; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.exception.TajoException; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.plan.LogicalPlan; import org.apache.tajo.plan.logical.LogicalNode; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java index d94dbc01f7..97be316bdc 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java @@ -20,17 +20,14 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Message; - import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.*; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; import org.apache.tajo.storage.VTuple; import org.apache.tajo.util.SizeOf; import org.apache.tajo.util.StringUtils; import org.apache.tajo.util.UnsafeUtil; - import org.apache.tajo.util.datetime.TimeMeta; import sun.misc.Unsafe; diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java index 524456b9ba..167519b349 100644 --- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java +++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java @@ -21,18 +21,14 @@ import com.google.common.base.Preconditions; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Message; - import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.datum.*; -import org.apache.tajo.exception.TajoInternalError; -import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.exception.UnsupportedException; import org.apache.tajo.storage.Tuple; import org.apache.tajo.storage.VTuple; import org.apache.tajo.util.SizeOf; import org.apache.tajo.util.StringUtils; import org.apache.tajo.util.UnsafeUtil; - import org.apache.tajo.util.datetime.TimeMeta; import sun.misc.Unsafe; import sun.nio.ch.DirectBuffer;