tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [12/13] tajo git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/tajo into index_support
Date Sat, 11 Apr 2015 01:10:14 GMT
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/tajo into index_support

Conflicts:
	tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
	tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
	tajo-storage/tajo-storage-hdfs/src/main/java/org/apache/tajo/storage/FileAppender.java


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/edef01e2
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/edef01e2
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/edef01e2

Branch: refs/heads/index_support
Commit: edef01e294f31defcdb8a7397e6289f4233e3e18
Parents: 69cbe34 6136142
Author: Jihoon Son <jihoonson@apache.org>
Authored: Sat Apr 11 10:09:08 2015 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Sat Apr 11 10:09:08 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  39 ++
 .../org/apache/tajo/algebra/AlterTable.java     |  24 +-
 .../apache/tajo/algebra/AlterTableOpType.java   |   2 +-
 .../org/apache/tajo/catalog/AlterTableDesc.java |  30 ++
 .../org/apache/tajo/catalog/AlterTableType.java |   2 +-
 .../org/apache/tajo/catalog/CatalogUtil.java    |   8 +
 .../src/main/proto/CatalogProtos.proto          |   2 +
 .../tajo/catalog/store/HCatalogStore.java       |   3 +
 .../tajo/catalog/store/AbstractDBStore.java     |  72 +++
 .../org/apache/tajo/catalog/store/MemStore.java |  18 +-
 .../org/apache/tajo/catalog/TestCatalog.java    |  19 +
 .../org/apache/tajo/client/QueryClient.java     |   4 +
 .../org/apache/tajo/client/QueryClientImpl.java |  13 +
 .../org/apache/tajo/client/TajoClientImpl.java  |   8 +
 .../org/apache/tajo/jdbc/FetchResultSet.java    |   5 +-
 .../java/org/apache/tajo/conf/TajoConf.java     |  71 +++
 .../java/org/apache/tajo/datum/DateDatum.java   |  79 ++--
 .../java/org/apache/tajo/datum/Float4Datum.java |   4 +-
 .../java/org/apache/tajo/datum/Float8Datum.java |   4 +-
 .../java/org/apache/tajo/datum/Int2Datum.java   |   4 +-
 .../java/org/apache/tajo/datum/Int4Datum.java   |   4 +-
 .../java/org/apache/tajo/datum/Int8Datum.java   |   4 +-
 .../org/apache/tajo/datum/IntervalDatum.java    |  57 +--
 .../java/org/apache/tajo/datum/TimeDatum.java   |  26 +-
 .../org/apache/tajo/datum/TimestampDatum.java   |  36 +-
 .../java/org/apache/tajo/util/BasicFuture.java  | 104 +++++
 .../apache/tajo/util/datetime/DateTimeUtil.java |  14 +-
 .../org/apache/tajo/util/datetime/TimeMeta.java |   9 +
 tajo-core/pom.xml                               |  20 +-
 .../org/apache/tajo/engine/parser/SQLLexer.g4   |   1 +
 .../org/apache/tajo/engine/parser/SQLParser.g4  |   9 +
 .../tajo/engine/function/datetime/ToDate.java   |   2 +-
 .../function/json/JsonExtractPathText.java      |  89 ++++
 .../apache/tajo/engine/parser/SQLAnalyzer.java  |  23 +
 .../planner/physical/ComparableVector.java      |  35 +-
 .../org/apache/tajo/engine/utils/TupleUtil.java |  31 --
 .../java/org/apache/tajo/master/TajoMaster.java |  17 +
 .../apache/tajo/master/exec/DDLExecutor.java    |   3 +
 .../exec/NonForwardQueryResultFileScanner.java  |   5 +
 .../exec/NonForwardQueryResultScanner.java      |   2 +
 .../NonForwardQueryResultSystemScanner.java     |   5 +
 .../apache/tajo/master/exec/QueryExecutor.java  |   1 +
 .../tajo/master/rm/TajoResourceTracker.java     |  49 +-
 .../master/rm/TajoWorkerResourceManager.java    | 313 +++++++------
 .../java/org/apache/tajo/master/rm/Worker.java  |  26 +-
 .../tajo/master/rm/WorkerResourceManager.java   |   8 +-
 .../main/java/org/apache/tajo/worker/Task.java  |   3 +-
 .../apache/tajo/worker/TaskRunnerManager.java   |   2 +-
 .../apache/tajo/ws/rs/ClientApplication.java    | 179 ++++++++
 .../tajo/ws/rs/JerseyResourceDelegate.java      |  31 ++
 .../ws/rs/JerseyResourceDelegateContext.java    |  64 +++
 .../ws/rs/JerseyResourceDelegateContextKey.java |  87 ++++
 .../tajo/ws/rs/JerseyResourceDelegateUtil.java  |  61 +++
 .../org/apache/tajo/ws/rs/ResourcesUtil.java    |  47 ++
 .../org/apache/tajo/ws/rs/TajoRestService.java  | 136 ++++++
 .../tajo/ws/rs/requests/NewDatabaseRequest.java |  34 ++
 .../tajo/ws/rs/requests/NewSessionRequest.java  |  49 ++
 .../tajo/ws/rs/requests/SubmitQueryRequest.java |  34 ++
 .../tajo/ws/rs/resources/ClusterResource.java   | 117 +++++
 .../tajo/ws/rs/resources/DatabasesResource.java | 339 ++++++++++++++
 .../tajo/ws/rs/resources/FunctionsResource.java | 121 +++++
 .../tajo/ws/rs/resources/QueryResource.java     | 449 +++++++++++++++++++
 .../ws/rs/resources/QueryResultResource.java    | 415 +++++++++++++++++
 .../tajo/ws/rs/resources/SessionsResource.java  | 380 ++++++++++++++++
 .../tajo/ws/rs/resources/TablesResource.java    | 350 +++++++++++++++
 .../ws/rs/responses/DatabaseInfoResponse.java   |  48 ++
 .../tajo/ws/rs/responses/ExceptionResponse.java |  33 ++
 .../responses/GetQueryResultDataResponse.java   |  72 +++
 .../ws/rs/responses/NewSessionResponse.java     |  76 ++++
 .../ws/rs/responses/ResultSetInfoResponse.java  |  43 ++
 .../responses/WorkerConnectionInfoResponse.java |  67 +++
 .../tajo/ws/rs/responses/WorkerResponse.java    |  76 ++++
 .../java/org/apache/tajo/QueryTestCaseBase.java |   5 +
 .../org/apache/tajo/TajoTestingCluster.java     |   5 +
 .../apache/tajo/engine/eval/TestEvalTree.java   | 107 ++++-
 .../tajo/engine/eval/TestEvalTreeUtil.java      |  12 +-
 .../tajo/engine/function/TestJsonFunctions.java |  36 ++
 .../tajo/engine/parser/TestSQLAnalyzer.java     |  39 ++
 .../planner/physical/TestExternalSortExec.java  |   8 +-
 .../tajo/engine/query/TestAlterTable.java       |  16 +-
 .../apache/tajo/ha/TestHAServiceHDFSImpl.java   |   2 +
 .../java/org/apache/tajo/jdbc/TestTajoJdbc.java |  40 +-
 .../tajo/ws/rs/resources/RestTestUtils.java     |  64 +++
 .../ws/rs/resources/TestClusterResource.java    |  84 ++++
 .../ws/rs/resources/TestDatabasesResource.java  | 189 ++++++++
 .../ws/rs/resources/TestFunctionsResource.java  |  78 ++++
 .../tajo/ws/rs/resources/TestQueryResource.java | 170 +++++++
 .../rs/resources/TestQueryResultResource.java   | 287 ++++++++++++
 .../ws/rs/resources/TestSessionsResource.java   | 263 +++++++++++
 .../ws/rs/resources/TestTablesResource.java     | 195 ++++++++
 .../resources/dataset/TestAlterTable/table2.tbl |   1 +
 .../alter_table_set_property_delimiter.sql      |   1 +
 .../alter_table_set_property_timezone.sql       |   1 +
 .../queries/TestAlterTable/table2_ddl.sql       |   1 +
 .../testAlterTableSetProperty.sql               |   1 +
 .../testAlterTableSetProperty2.sql              |   1 +
 .../default/alter_table_set_property_1.sql      |   1 +
 .../default/alter_table_set_property_2.sql      |   1 +
 .../default/alter_table_set_property_3.sql      |   1 +
 .../after_set_property_delimiter.result         |   3 +
 .../before_set_property_delimiter.result        |   3 +
 .../main/sphinx/backup_and_restore/catalog.rst  |   2 +-
 tajo-docs/src/main/sphinx/functions.rst         |   3 +-
 .../src/main/sphinx/functions/json_func.rst     |  16 +
 tajo-docs/src/main/sphinx/getting_started.rst   |   2 +-
 tajo-docs/src/main/sphinx/sql_language/ddl.rst  |   2 +-
 .../src/main/sphinx/table_management/csv.rst    | 115 -----
 .../sphinx/table_management/file_formats.rst    |   2 +-
 .../sphinx/table_management/table_overview.rst  |   6 +-
 .../src/main/sphinx/table_management/text.rst   | 115 +++++
 .../org/apache/tajo/jdbc/TajoStatement.java     |   7 +-
 .../org/apache/tajo/plan/ExprAnnotator.java     |   2 +-
 .../org/apache/tajo/plan/LogicalPlanner.java    |   2 +
 .../plan/expr/AggregationFunctionCallEval.java  |   6 +
 .../apache/tajo/plan/expr/AlgebraicUtil.java    |   6 +-
 .../tajo/plan/expr/BetweenPredicateEval.java    |   5 +-
 .../org/apache/tajo/plan/expr/BinaryEval.java   |   1 +
 .../org/apache/tajo/plan/expr/CaseWhenEval.java |   2 +
 .../org/apache/tajo/plan/expr/CastEval.java     |   1 +
 .../org/apache/tajo/plan/expr/ConstEval.java    |   1 +
 .../org/apache/tajo/plan/expr/EvalNode.java     |  13 +-
 .../org/apache/tajo/plan/expr/FieldEval.java    |   5 +-
 .../org/apache/tajo/plan/expr/FunctionEval.java |   5 +-
 .../tajo/plan/expr/GeneralFunctionEval.java     |   1 +
 .../java/org/apache/tajo/plan/expr/InEval.java  |   3 +
 .../org/apache/tajo/plan/expr/IsNullEval.java   |   1 +
 .../java/org/apache/tajo/plan/expr/NotEval.java |   1 +
 .../plan/expr/PatternMatchPredicateEval.java    |   6 +-
 .../apache/tajo/plan/expr/RowConstantEval.java  |   1 +
 .../org/apache/tajo/plan/expr/SignedEval.java   |   1 +
 .../org/apache/tajo/plan/expr/UnaryEval.java    |   1 +
 .../tajo/plan/expr/WindowFunctionEval.java      |   3 +
 .../tajo/plan/logical/AlterTableNode.java       |  16 +
 .../plan/serder/LogicalNodeDeserializer.java    |   3 +
 .../tajo/plan/serder/LogicalNodeSerializer.java |   4 +
 tajo-plan/src/main/proto/Plan.proto             |   2 +
 tajo-project/pom.xml                            |  15 +
 .../tajo/pullserver/TajoPullServerService.java  |  10 +-
 .../main/java/org/apache/tajo/rpc/RpcUtils.java |   9 +-
 .../apache/tajo/rpc/CancelableRpcCallback.java  |  74 +++
 tajo-rpc/tajo-ws-rs/pom.xml                     |   4 +
 .../apache/tajo/ws/rs/ResourceConfigUtil.java   |  38 ++
 .../ws/rs/netty/NettyRestHandlerContainer.java  |  48 +-
 .../tajo/ws/rs/netty/gson/GsonFeature.java      |  25 +-
 .../tajo/ws/rs/netty/gson/GsonReader.java       |  23 +-
 .../apache/tajo/ws/rs/netty/gson/GsonUtil.java  |   2 +-
 .../tajo/ws/rs/netty/gson/GsonWriter.java       |  23 +-
 .../tajo/ws/rs/netty/testapp2/Directory.java    |   8 +-
 tajo-storage/tajo-storage-hdfs/pom.xml          |   1 -
 .../org/apache/tajo/storage/FileAppender.java   |   2 +-
 .../tajo/storage/json/JsonLineDeserializer.java |  26 +-
 .../tajo/storage/json/JsonLineSerializer.java   |   3 +-
 .../text/TextFieldSerializerDeserializer.java   |  12 +-
 .../tajo/storage/TestByteBufLineReader.java     | 160 +++++++
 154 files changed, 6457 insertions(+), 620 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
----------------------------------------------------------------------
diff --cc tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
index 454405d,b058504..82068a2
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
@@@ -26,19 -26,17 +26,18 @@@ import com.google.common.collect.Maps
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.fs.Path;
  import org.apache.tajo.TajoConstants;
 +import org.apache.tajo.catalog.CatalogConstants;
  import org.apache.tajo.catalog.CatalogUtil;
  import org.apache.tajo.catalog.FunctionDesc;
 +import org.apache.tajo.catalog.Schema;
+ import org.apache.tajo.catalog.TableMeta;
  import org.apache.tajo.catalog.exception.*;
--import org.apache.tajo.catalog.partition.PartitionDesc;
  import org.apache.tajo.catalog.proto.CatalogProtos;
  import org.apache.tajo.catalog.proto.CatalogProtos.ColumnProto;
  import org.apache.tajo.catalog.proto.CatalogProtos.DatabaseProto;
  import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
 -import org.apache.tajo.catalog.proto.CatalogProtos.IndexProto;
 +import org.apache.tajo.catalog.proto.CatalogProtos.SortSpecProto;
  import org.apache.tajo.catalog.proto.CatalogProtos.TableDescProto;
- import org.apache.tajo.catalog.proto.CatalogProtos.TableDescProto;
  import org.apache.tajo.catalog.proto.CatalogProtos.TableDescriptorProto;
  import org.apache.tajo.catalog.proto.CatalogProtos.TableOptionProto;
  import org.apache.tajo.catalog.proto.CatalogProtos.TablePartitionProto;

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/java/org/apache/tajo/worker/Task.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
----------------------------------------------------------------------
diff --cc tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
index 0000000,99609d7..92544d5
mode 000000,100644..100644
--- a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
@@@ -1,0 -1,448 +1,449 @@@
+ /**
+  * 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.ws.rs.resources;
+ 
+ import java.net.URI;
+ import java.util.ArrayList;
+ import java.util.HashMap;
+ import java.util.List;
+ import java.util.Map;
+ 
+ import javax.ws.rs.Consumes;
+ import javax.ws.rs.DELETE;
+ import javax.ws.rs.GET;
+ import javax.ws.rs.HeaderParam;
+ import javax.ws.rs.POST;
+ import javax.ws.rs.Path;
+ import javax.ws.rs.PathParam;
+ import javax.ws.rs.Produces;
+ import javax.ws.rs.QueryParam;
+ import javax.ws.rs.core.Application;
+ import javax.ws.rs.core.Context;
+ import javax.ws.rs.core.MediaType;
+ import javax.ws.rs.core.Response;
+ import javax.ws.rs.core.Response.Status;
+ import javax.ws.rs.core.UriInfo;
+ 
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+ import org.apache.tajo.QueryId;
+ import org.apache.tajo.TajoProtos;
+ import org.apache.tajo.ipc.ClientProtos;
+ import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse;
+ import org.apache.tajo.master.QueryInProgress;
+ import org.apache.tajo.master.QueryInfo;
+ import org.apache.tajo.master.QueryManager;
+ import org.apache.tajo.master.TajoMaster.MasterContext;
+ import org.apache.tajo.querymaster.QueryJobEvent;
+ import org.apache.tajo.session.InvalidSessionException;
+ import org.apache.tajo.session.Session;
+ import org.apache.tajo.util.TajoIdUtils;
+ import org.apache.tajo.ws.rs.JerseyResourceDelegate;
+ import org.apache.tajo.ws.rs.JerseyResourceDelegateContext;
+ import org.apache.tajo.ws.rs.JerseyResourceDelegateContextKey;
+ import org.apache.tajo.ws.rs.JerseyResourceDelegateUtil;
+ import org.apache.tajo.ws.rs.ResourcesUtil;
+ import org.apache.tajo.ws.rs.requests.SubmitQueryRequest;
+ 
+ @Path("/databases/{databaseName}/queries")
+ public class QueryResource {
+ 
+   private static final Log LOG = LogFactory.getLog(QueryResource.class);
+   
+   @Context
+   UriInfo uriInfo;
+   
+   @Context
+   Application application;
+   
+   @PathParam("databaseName")
+   String databaseName;
+   
+   JerseyResourceDelegateContext context;
+   
+   protected static final String tajoSessionIdHeaderName = "X-Tajo-Session";
+   
+   private static final String databaseNameKeyName = "databaseName";
+   private static final String stateKeyName = "state";
+   private static final String startTimeKeyName = "startTime";
+   private static final String endTimeKeyName = "endTime";
+   private static final String sessionIdKeyName = "sessionId";
+   private static final String submitQueryRequestKeyName = "submitQueryRequest";
+   private static final String printTypeKeyName = "printType";
+   private static final String queryIdKeyName = "queryId";
+   
+   private void initializeContext() {
+     context = new JerseyResourceDelegateContext();
+     JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+         JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey,
UriInfo.class);
+     context.put(uriInfoKey, uriInfo);
+     JerseyResourceDelegateContextKey<String> databaseNameKey =
+         JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+     context.put(databaseNameKey, databaseName);
+   }
+   
+   @GET
+   @Produces(MediaType.APPLICATION_JSON)
+   public Response getAllQueries(@QueryParam("state") String state,
+       @QueryParam("startTime") long startTime,
+       @QueryParam("endTime") long endTime) {
+     if (LOG.isDebugEnabled()) {
+       LOG.debug("Client sent a get all queries request.");
+     }
+     
+     Response response = null;
+     
+     try {
+       initializeContext();
+       JerseyResourceDelegateContextKey<String> stateKey =
+           JerseyResourceDelegateContextKey.valueOf(stateKeyName, String.class);
+       if (state != null && !state.isEmpty()) {
+         context.put(stateKey, state);
+       }
+       JerseyResourceDelegateContextKey<Long> startTimeKey =
+           JerseyResourceDelegateContextKey.valueOf(startTimeKeyName, Long.class);
+       if (startTime > 0) {
+         context.put(startTimeKey, startTime);
+       }
+       JerseyResourceDelegateContextKey<Long> endTimeKey =
+           JerseyResourceDelegateContextKey.valueOf(endTimeKeyName, Long.class);
+       if (endTime > 0) {
+         context.put(endTimeKey, endTime);
+       }
+       
+       response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+           new GetAllQueriesDelegate(),
+           application,
+           context,
+           LOG);
+     } catch (Throwable e) {
+       LOG.error(e.getMessage(), e);
+       
+       response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+     }
+     
+     return response;
+   }
+   
+   private static class GetAllQueriesDelegate implements JerseyResourceDelegate {
+ 
+     @Override
+     public Response run(JerseyResourceDelegateContext context) {
+       JerseyResourceDelegateContextKey<String> stateKey =
+           JerseyResourceDelegateContextKey.valueOf(stateKeyName, String.class);
+       String state = context.get(stateKey);
+       JerseyResourceDelegateContextKey<Long> startTimeKey =
+           JerseyResourceDelegateContextKey.valueOf(startTimeKeyName, Long.class);
+       long startTime = context.get(startTimeKey);
+       JerseyResourceDelegateContextKey<Long> endTimeKey =
+           JerseyResourceDelegateContextKey.valueOf(endTimeKeyName, Long.class);
+       long endTime = context.get(endTimeKey);
+       JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+           JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey,
MasterContext.class);
+       MasterContext masterContext = context.get(masterContextKey);
+       
+       TajoProtos.QueryState queryState = null;
+       try {
+         if (state != null && !state.isEmpty()) {
+           queryState = TajoProtos.QueryState.valueOf(state);
+         }
+       } catch (Exception e) {
+         return ResourcesUtil.createBadRequestResponse(LOG, state + " is not a valid query
state.");
+       }
+       
+       Map<String, List<QueryInfo>> queriesMap = new HashMap<String, List<QueryInfo>>();
+       List<QueryInfo> queriesInfo = new ArrayList<QueryInfo>();
+       
+       QueryManager queryManager = masterContext.getQueryJobManager();
+       for (QueryInProgress queryInProgress: queryManager.getSubmittedQueries()) {
+         queriesInfo.add(queryInProgress.getQueryInfo());
+       }
+       
+       for (QueryInProgress queryInProgress: queryManager.getRunningQueries()) {
+         queriesInfo.add(queryInProgress.getQueryInfo());
+       }
+       
+       try {
+         queriesInfo.addAll(masterContext.getHistoryReader().getQueries(null));
+       } catch (Exception e) {
+         LOG.error(e.getMessage(), e);
+         return ResourcesUtil.createExceptionResponse(LOG, e.getMessage());
+       }
+       
+       if (state != null) {
+         queriesInfo = selectQueriesInfoByState(queriesInfo, queryState);
+       }
+       
+       if (startTime > 0 || endTime > 0) {
+         queriesInfo = selectQueriesInfoByTime(queriesInfo, startTime, endTime);
+       }
+       queriesMap.put("queries", queriesInfo);
+       
+       return Response.ok(queriesMap).build();
+     }
+     
+     private List<QueryInfo> selectQueriesInfoByState(List<QueryInfo> queriesInfo,
TajoProtos.QueryState state) {
+       List<QueryInfo> resultQueriesInfo = new ArrayList<QueryInfo>(queriesInfo.size()/2);
+       
+       for (QueryInfo queryInfo: queriesInfo) {
+         if (state.equals(queryInfo.getQueryState())) {
+           resultQueriesInfo.add(queryInfo);
+         }
+       }
+       
+       return resultQueriesInfo;
+     }
+     
+     private List<QueryInfo> selectQueriesInfoByTime(List<QueryInfo> queriesInfo,
long startTime, long endTime) {
+       List<QueryInfo> resultQueriesInfo = new ArrayList<QueryInfo>(queriesInfo.size()/2);
+       
+       for (QueryInfo queryInfo: queriesInfo) {
+         if (queryInfo.getStartTime() > startTime) {
+           resultQueriesInfo.add(queryInfo);
+         }
+         if (queryInfo.getStartTime() < endTime) {
+           resultQueriesInfo.add(queryInfo);
+         }
+       }
+       
+       return resultQueriesInfo;
+     }
+   }
+   
+   @POST
+   @Consumes(MediaType.APPLICATION_JSON)
+   public Response submitQuery(@HeaderParam(tajoSessionIdHeaderName) String sessionId,
+       SubmitQueryRequest request) {
+     if (LOG.isDebugEnabled()) {
+       LOG.debug("Client sent a submit query request.");
+     }
+     
+     Response response = null;
+     
+     try {
+       initializeContext();
+       JerseyResourceDelegateContextKey<String> sessionIdKey =
+           JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+       context.put(sessionIdKey, sessionId);
+       JerseyResourceDelegateContextKey<SubmitQueryRequest> submitQueryRequestKey =
+           JerseyResourceDelegateContextKey.valueOf(submitQueryRequestKeyName, SubmitQueryRequest.class);
+       context.put(submitQueryRequestKey, request);
+       
+       response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+           new SubmitQueryDelegate(),
+           application,
+           context,
+           LOG);
+     } catch (Throwable e) {
+       LOG.error(e.getMessage(), e);
+       
+       response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+     }
+     
+     return response;
+   }
+   
+   private static class SubmitQueryDelegate implements JerseyResourceDelegate {
+ 
+     @Override
+     public Response run(JerseyResourceDelegateContext context) {
+       JerseyResourceDelegateContextKey<String> sessionIdKey =
+           JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+       String sessionId = context.get(sessionIdKey);
+       JerseyResourceDelegateContextKey<SubmitQueryRequest> submitQueryRequestKey =
+           JerseyResourceDelegateContextKey.valueOf(submitQueryRequestKeyName, SubmitQueryRequest.class);
+       SubmitQueryRequest request = context.get(submitQueryRequestKey);
+       JerseyResourceDelegateContextKey<String> databaseNameKey =
+           JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+       String databaseName = context.get(databaseNameKey);
+       JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+           JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey,
MasterContext.class);
+       MasterContext masterContext = context.get(masterContextKey);
+       
+       if (sessionId == null || sessionId.isEmpty()) {
+         return ResourcesUtil.createBadRequestResponse(LOG, "Session Id is null or empty
string.");
+       }
+       if (request == null || request.getQuery() == null || request.getQuery().isEmpty())
{
+         return ResourcesUtil.createBadRequestResponse(LOG, "query is null or emptry string.");
+       }
+       
+       Session session;
+       try {
+         session = masterContext.getSessionManager().getSession(sessionId);
+       } catch (InvalidSessionException e) {
+         return ResourcesUtil.createBadRequestResponse(LOG, "Provided session id (" + sessionId
+ ") is invalid.");
+       }
+       
+       SubmitQueryResponse response = 
+           masterContext.getGlobalEngine().executeQuery(session, request.getQuery(), false);
 -      if (response.hasResultCode() && ClientProtos.ResultCode.ERROR.equals(response.getResultCode()))
{
 -        return ResourcesUtil.createExceptionResponse(LOG, response.getErrorMessage());
++      if (response.getResult().hasResultCode() &&
++          ClientProtos.ResultCode.ERROR.equals(response.getResult().getResultCode())) {
++        return ResourcesUtil.createExceptionResponse(LOG, response.getResult().getErrorMessage());
+       } else {
+         JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+             JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey,
UriInfo.class);
+         UriInfo uriInfo = context.get(uriInfoKey);
+         
+         URI queryURI = uriInfo.getBaseUriBuilder()
+             .path(QueryResource.class)
+             .path(QueryResource.class, "getQuery")
+             .build(databaseName, new QueryId(response.getQueryId()).toString());
+         return Response.created(queryURI).build();
+       }
+     }
+   }
+   
+   @GET
+   @Path("{queryId}")
+   @Produces(MediaType.APPLICATION_JSON)
+   public Response getQuery(@PathParam("queryId") String queryId, @QueryParam("print") String
printType) {
+     if (LOG.isDebugEnabled()) {
+       LOG.debug("Client sent a get query request.");
+     }
+     
+     Response response = null;
+     
+     try {
+       initializeContext();
+       JerseyResourceDelegateContextKey<String> queryIdKey =
+           JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+       context.put(queryIdKey, queryId);
+       JerseyResourceDelegateContextKey<String> printTypeKey =
+           JerseyResourceDelegateContextKey.valueOf(printTypeKeyName, String.class);
+       context.put(printTypeKey, printType);
+       
+       response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+           new GetQueryDelegate(),
+           application,
+           context,
+           LOG);
+     } catch (Throwable e) {
+       LOG.error(e.getMessage(), e);
+       
+       response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+     }
+     
+     return response;
+   }
+   
+   private static class GetQueryDelegate implements JerseyResourceDelegate {
+     
+     private static final String briefPrint = "BRIEF";
+ 
+     @Override
+     public Response run(JerseyResourceDelegateContext context) {
+       JerseyResourceDelegateContextKey<String> queryIdKey =
+           JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+       String queryId = context.get(queryIdKey);
+       JerseyResourceDelegateContextKey<String> printTypeKey =
+           JerseyResourceDelegateContextKey.valueOf(printTypeKeyName, String.class);
+       String printType = context.get(printTypeKey);
+       JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+           JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey,
MasterContext.class);
+       MasterContext masterContext = context.get(masterContextKey);
+       
+       QueryId queryIdObj = TajoIdUtils.parseQueryId(queryId);
+       
+       QueryManager queryManager = masterContext.getQueryJobManager();
+       QueryInProgress queryInProgress = queryManager.getQueryInProgress(queryIdObj);
+       
+       QueryInfo queryInfo = null;
+       if (queryInProgress == null) {
+         queryInfo = queryManager.getFinishedQuery(queryIdObj);
+       } else {
+         queryInfo = queryInProgress.getQueryInfo();
+       }
+       
+       if (queryInfo != null) {
+         if (briefPrint.equalsIgnoreCase(printType)) {
+           queryInfo = getBriefQueryInfo(queryInfo);
+         }
+         return Response.ok(queryInfo).build();
+       } else {
+         return Response.status(Status.NOT_FOUND).build();
+       }
+     }
+     
+     private QueryInfo getBriefQueryInfo(QueryInfo queryInfo) {
+       QueryInfo newQueryInfo = new QueryInfo(queryInfo.getQueryId(), null, null, null);
+       newQueryInfo.setQueryState(queryInfo.getQueryState());
+       newQueryInfo.setStartTime(queryInfo.getStartTime());
+       return newQueryInfo;
+     }
+   }
+   
+   @DELETE
+   @Path("{queryId}")
+   public Response terminateQuery(@PathParam("queryId") String queryId) {
+     if (LOG.isDebugEnabled()) {
+       LOG.debug("Client sent a terminate query request.");
+     }
+     
+     Response response = null;
+     
+     try {
+       initializeContext();
+       JerseyResourceDelegateContextKey<String> queryIdKey =
+           JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+       context.put(queryIdKey, queryId);
+       
+       response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+           new TerminateQueryDelegate(),
+           application,
+           context,
+           LOG);
+     } catch (Throwable e) {
+       LOG.error(e.getMessage(), e);
+       
+       response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+     }
+     
+     return response;
+   }
+   
+   private static class TerminateQueryDelegate implements JerseyResourceDelegate {
+ 
+     @Override
+     public Response run(JerseyResourceDelegateContext context) {
+       JerseyResourceDelegateContextKey<String> queryIdKey =
+           JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+       String queryId = context.get(queryIdKey);
+       JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+           JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey,
MasterContext.class);
+       MasterContext masterContext = context.get(masterContextKey);
+       
+       QueryId queryIdObj = TajoIdUtils.parseQueryId(queryId);
+       
+       QueryManager queryManager = masterContext.getQueryJobManager();
+       queryManager.getEventHandler().handle(new QueryJobEvent(QueryJobEvent.Type.QUERY_JOB_KILL,
+           new QueryInfo(queryIdObj)));
+       return Response.ok().build();
+     }
+   }
+   
+   @Path("/{queryId}/result")
+   public QueryResultResource getQueryResult(@PathParam("queryId") String queryId) {
+     QueryResultResource queryResultResource = new QueryResultResource();
+     queryResultResource.setUriInfo(uriInfo);
+     queryResultResource.setApplication(application);
+     queryResultResource.setDatabaseName(databaseName);
+     queryResultResource.setQueryId(queryId);
+     return queryResultResource;
+   }
+ }

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/edef01e2/tajo-plan/src/main/proto/Plan.proto
----------------------------------------------------------------------
diff --cc tajo-plan/src/main/proto/Plan.proto
index f0eaf1a,c555a1a..75c9dc1
--- a/tajo-plan/src/main/proto/Plan.proto
+++ b/tajo-plan/src/main/proto/Plan.proto
@@@ -317,25 -301,9 +318,26 @@@ message AlterTableNode 
    optional RenameTable renameTable = 3;
    optional RenameColumn renameColumn = 4;
    optional AddColumn addColumn = 5;
+   optional KeyValueSetProto properties = 6;
  }
  
 +message CreateIndexNode {
 +  required int32 childSeq = 1;
 +  required string indexName = 2;
 +  required IndexMethod indexMethod = 3;
 +  required string indexPath = 4;
 +  repeated SortSpecProto keySortSpecs = 5;
 +  required SchemaProto targetRelationSchema = 6;
 +  optional bool isUnique = 7 [default = false];
 +  optional bool isClustered = 8 [default = false];
 +  optional KeyValueSetProto indexProperties = 9;
 +  optional bool isExternal = 10;
 +}
 +
 +message DropIndexNode {
 +  required string indexName = 1;
 +}
 +
  enum EvalType {
    NOT = 0;
    AND = 1;


Mime
View raw message