You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by ji...@apache.org on 2015/04/06 06:42:56 UTC
[01/10] tajo git commit: TAJO-1462: Replace CSV examples into TEXT
examples in docs.
Repository: tajo
Updated Branches:
refs/heads/index_support 79b3cb25b -> 62fd83bc9
TAJO-1462: Replace CSV examples into TEXT examples in docs.
Closes #475
Signed-off-by: Jihoon Son <ji...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/b0abff8e
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/b0abff8e
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/b0abff8e
Branch: refs/heads/index_support
Commit: b0abff8e896d7985eaf1aa48d9c2ab3a45618f01
Parents: 70d5fdf
Author: Dongjoon Hyun <do...@apache.org>
Authored: Sat Apr 4 18:58:38 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Sat Apr 4 18:58:38 2015 +0900
----------------------------------------------------------------------
CHANGES | 3 +
.../main/sphinx/backup_and_restore/catalog.rst | 2 +-
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 +++++++++++++++++++
8 files changed, 125 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 5ee7715..3def16c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -124,6 +124,9 @@ Release 0.11.0 - unreleased
TASKS
+ TAJO-1462: Replace CSV examples into TEXT examples in docs.
+ (Contributed by Dongjoon Hyun, Committed by jihoon)
+
TAJO-1424: Investigate the problem of too many "Try to connect" messeges
during Travic CI build. (Contributed by navis, Committed by jihoon)
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/backup_and_restore/catalog.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/backup_and_restore/catalog.rst b/tajo-docs/src/main/sphinx/backup_and_restore/catalog.rst
index 200aa85..1c2b709 100644
--- a/tajo-docs/src/main/sphinx/backup_and_restore/catalog.rst
+++ b/tajo-docs/src/main/sphinx/backup_and_restore/catalog.rst
@@ -28,7 +28,7 @@ For example, if you want to backup a table customer, you should type a command a
-- Name: customer; Type: TABLE; Storage: CSV
-- Path: file:/home/hyunsik/tpch/customer
--
- CREATE EXTERNAL TABLE customer (c_custkey INT8, c_name TEXT, c_address TEXT, c_nationkey INT8, c_phone TEXT, c_acctbal FLOAT8, c_mktsegment TEXT, c_comment TEXT) USING CSV LOCATION 'file:/home/hyunsik/tpch/customer';
+ CREATE EXTERNAL TABLE customer (c_custkey INT8, c_name TEXT, c_address TEXT, c_nationkey INT8, c_phone TEXT, c_acctbal FLOAT8, c_mktsegment TEXT, c_comment TEXT) USING TEXT LOCATION 'file:/home/hyunsik/tpch/customer';
If you want to restore the catalog from the SQL dump file, please type the below command: ::
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/getting_started.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/getting_started.rst b/tajo-docs/src/main/sphinx/getting_started.rst
index eaf6973..e30c3fe 100644
--- a/tajo-docs/src/main/sphinx/getting_started.rst
+++ b/tajo-docs/src/main/sphinx/getting_started.rst
@@ -135,7 +135,7 @@ Here, we assume the schema as (int, text, float, text). ::
name text,
score float,
type text)
- using csv with ('text.delimiter'='|') location 'file:/home/x/table1';
+ using text with ('text.delimiter'='|') location 'file:/home/x/table1';
To load an external table, you need to use ‘create external table’ statement.
In the location clause, you should use the absolute directory path with an appropriate scheme.
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/sql_language/ddl.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/sql_language/ddl.rst b/tajo-docs/src/main/sphinx/sql_language/ddl.rst
index 60b7190..662ccff 100644
--- a/tajo-docs/src/main/sphinx/sql_language/ddl.rst
+++ b/tajo-docs/src/main/sphinx/sql_language/ddl.rst
@@ -56,7 +56,7 @@ If you want to add an external table that contains compressed data, you should g
...
L_COMMENT text)
- USING csv WITH ('text.delimiter'='|','compression.codec'='org.apache.hadoop.io.compress.DeflateCodec')
+ USING TEXT WITH ('text.delimiter'='|','compression.codec'='org.apache.hadoop.io.compress.DeflateCodec')
LOCATION 'hdfs://localhost:9010/tajo/warehouse/lineitem_100_snappy';
`compression.codec` parameter can have one of the following compression codecs:
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/table_management/csv.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/table_management/csv.rst b/tajo-docs/src/main/sphinx/table_management/csv.rst
deleted file mode 100644
index 53c6e1d..0000000
--- a/tajo-docs/src/main/sphinx/table_management/csv.rst
+++ /dev/null
@@ -1,115 +0,0 @@
-*************************************
-CSV (TextFile)
-*************************************
-
-A character-separated values (CSV) file represents a tabular data set consisting of rows and columns.
-Each row is a plan-text line. A line is usually broken by a character line feed ``\n`` or carriage-return ``\r``.
-The line feed ``\n`` is the default delimiter in Tajo. Each record consists of multiple fields, separated by
-some other character or string, most commonly a literal vertical bar ``|``, comma ``,`` or tab ``\t``.
-The vertical bar is used as the default field delimiter in Tajo.
-
-=========================================
-How to Create a CSV Table ?
-=========================================
-
-If you are not familiar with the ``CREATE TABLE`` statement, please refer to the Data Definition Language :doc:`/sql_language/ddl`.
-
-In order to specify a certain file format for your table, you need to use the ``USING`` clause in your ``CREATE TABLE``
-statement. The below is an example statement for creating a table using CSV files.
-
-.. code-block:: sql
-
- CREATE TABLE
- table1 (
- id int,
- name text,
- score float,
- type text
- ) USING CSV;
-
-=========================================
-Physical Properties
-=========================================
-
-Some table storage formats provide parameters for enabling or disabling features and adjusting physical parameters.
-The ``WITH`` clause in the CREATE TABLE statement allows users to set those parameters.
-
-Now, the CSV storage format provides the following physical properties.
-
-* ``text.delimiter``: delimiter character. ``|`` or ``\u0001`` is usually used, and the default field delimiter is ``|``.
-* ``text.null``: NULL character. The default NULL character is an empty string ``''``. Hive's default NULL character is ``'\\N'``.
-* ``compression.codec``: Compression codec. You can enable compression feature and set specified compression algorithm. The compression algorithm used to compress files. The compression codec name should be the fully qualified class name inherited from `org.apache.hadoop.io.compress.CompressionCodec <https://hadoop.apache.org/docs/current/api/org/apache/hadoop/io/compress/CompressionCodec.html>`_. By default, compression is disabled.
-* ``csvfile.serde`` (deprecated): custom (De)serializer class. ``org.apache.tajo.storage.TextSerializerDeserializer`` is the default (De)serializer class.
-* ``timezone``: the time zone that the table uses for writting. When table rows are read or written, ```timestamp``` and ```time``` column values are adjusted by this timezone if it is set. Time zone can be an abbreviation form like 'PST' or 'DST'. Also, it accepts an offset-based form like 'UTC+9' or a location-based form like 'Asia/Seoul'.
-* ``text.error-tolerance.max-num``: the maximum number of permissible parsing errors. This value should be an integer value. By default, ``text.error-tolerance.max-num`` is ``0``. According to the value, parsing errors will be handled in different ways.
- * If ``text.error-tolerance.max-num < 0``, all parsing errors are ignored.
- * If ``text.error-tolerance.max-num == 0``, any parsing error is not allowed. If any error occurs, the query will be failed. (default)
- * If ``text.error-tolerance.max-num > 0``, the given number of parsing errors in each task will be pemissible.
-
-The following example is to set a custom field delimiter, NULL character, and compression codec:
-
-.. code-block:: sql
-
- CREATE TABLE table1 (
- id int,
- name text,
- score float,
- type text
- ) USING CSV WITH('text.delimiter'='\u0001',
- 'text.null'='\\N',
- 'compression.codec'='org.apache.hadoop.io.compress.SnappyCodec');
-
-.. warning::
-
- Be careful when using ``\n`` as the field delimiter because CSV uses ``\n`` as the line delimiter.
- At the moment, Tajo does not provide a way to specify the line delimiter.
-
-=========================================
-Custom (De)serializer
-=========================================
-
-The CSV storage format not only provides reading and writing interfaces for CSV data but also allows users to process custom
-plan-text file formats with user-defined (De)serializer classes.
-For example, with custom (de)serializers, Tajo can process JSON file formats or any specialized plan-text file formats.
-
-In order to specify a custom (De)serializer, set a physical property ``csvfile.serde``.
-The property value should be a fully qualified class name.
-
-For example:
-
-.. code-block:: sql
-
- CREATE TABLE table1 (
- id int,
- name text,
- score float,
- type text
- ) USING CSV WITH ('csvfile.serde'='org.my.storage.CustomSerializerDeserializer')
-
-
-=========================================
-Null Value Handling Issues
-=========================================
-In default, NULL character in CSV files is an empty string ``''``.
-In other words, an empty field is basically recognized as a NULL value in Tajo.
-If a field domain is ``TEXT``, an empty field is recognized as a string value ``''`` instead of NULL value.
-Besides, You can also use your own NULL character by specifying a physical property ``text.null``.
-
-=========================================
-Compatibility Issues with Apache Hive™
-=========================================
-
-CSV files generated in Tajo can be processed directly by Apache Hive™ without further processing.
-In this section, we explain some compatibility issue for users who use both Hive and Tajo.
-
-If you set a custom field delimiter, the CSV tables cannot be directly used in Hive.
-In order to specify the custom field delimiter in Hive, you need to use ``ROW FORMAT DELIMITED FIELDS TERMINATED BY``
-clause in a Hive's ``CREATE TABLE`` statement as follows:
-
-.. code-block:: sql
-
- CREATE TABLE table1 (id int, name string, score float, type string)
- ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'
- STORED AS TEXT
-
-To the best of our knowledge, there is not way to specify a custom NULL character in Hive.
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/table_management/file_formats.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/table_management/file_formats.rst b/tajo-docs/src/main/sphinx/table_management/file_formats.rst
index c15dd3f..0579497 100644
--- a/tajo-docs/src/main/sphinx/table_management/file_formats.rst
+++ b/tajo-docs/src/main/sphinx/table_management/file_formats.rst
@@ -7,7 +7,7 @@ Currently, Tajo provides four file formats as follows:
.. toctree::
:maxdepth: 1
- csv
+ text
rcfile
parquet
sequencefile
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/table_management/table_overview.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/table_management/table_overview.rst b/tajo-docs/src/main/sphinx/table_management/table_overview.rst
index 3d933c2..3985e19 100644
--- a/tajo-docs/src/main/sphinx/table_management/table_overview.rst
+++ b/tajo-docs/src/main/sphinx/table_management/table_overview.rst
@@ -29,9 +29,9 @@ The following example is to set a custom field delimiter, NULL character, and co
name text,
score float,
type text
- ) USING CSV WITH('text.delimiter'='\u0001',
- 'text.null'='\\N',
- 'compression.codec'='org.apache.hadoop.io.compress.SnappyCodec');
+ ) USING TEXT WITH('text.delimiter'='\u0001',
+ 'text.null'='\\N',
+ 'compression.codec'='org.apache.hadoop.io.compress.SnappyCodec');
Each physical table layout has its own specialized properties. They will be addressed in :doc:`/table_management/file_formats`.
http://git-wip-us.apache.org/repos/asf/tajo/blob/b0abff8e/tajo-docs/src/main/sphinx/table_management/text.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/table_management/text.rst b/tajo-docs/src/main/sphinx/table_management/text.rst
new file mode 100644
index 0000000..3727b03
--- /dev/null
+++ b/tajo-docs/src/main/sphinx/table_management/text.rst
@@ -0,0 +1,115 @@
+*************************************
+TEXT
+*************************************
+
+A character-separated values plain-text file represents a tabular data set consisting of rows and columns.
+Each row is a plan-text line. A line is usually broken by a character line feed ``\n`` or carriage-return ``\r``.
+The line feed ``\n`` is the default delimiter in Tajo. Each record consists of multiple fields, separated by
+some other character or string, most commonly a literal vertical bar ``|``, comma ``,`` or tab ``\t``.
+The vertical bar is used as the default field delimiter in Tajo.
+
+=========================================
+How to Create a TEXT Table ?
+=========================================
+
+If you are not familiar with the ``CREATE TABLE`` statement, please refer to the Data Definition Language :doc:`/sql_language/ddl`.
+
+In order to specify a certain file format for your table, you need to use the ``USING`` clause in your ``CREATE TABLE``
+statement. The below is an example statement for creating a table using *TEXT* format.
+
+.. code-block:: sql
+
+ CREATE TABLE
+ table1 (
+ id int,
+ name text,
+ score float,
+ type text
+ ) USING TEXT;
+
+=========================================
+Physical Properties
+=========================================
+
+Some table storage formats provide parameters for enabling or disabling features and adjusting physical parameters.
+The ``WITH`` clause in the CREATE TABLE statement allows users to set those parameters.
+
+*TEXT* format provides the following physical properties.
+
+* ``text.delimiter``: delimiter character. ``|`` or ``\u0001`` is usually used, and the default field delimiter is ``|``.
+* ``text.null``: ``NULL`` character. The default ``NULL`` character is an empty string ``''``. Hive's default ``NULL`` character is ``'\\N'``.
+* ``compression.codec``: Compression codec. You can enable compression feature and set specified compression algorithm. The compression algorithm used to compress files. The compression codec name should be the fully qualified class name inherited from `org.apache.hadoop.io.compress.CompressionCodec <https://hadoop.apache.org/docs/current/api/org/apache/hadoop/io/compress/CompressionCodec.html>`_. By default, compression is disabled.
+* ``text.serde``: custom (De)serializer class. ``org.apache.tajo.storage.text.CSVLineSerDe`` is the default (De)serializer class.
+* ``timezone``: the time zone that the table uses for writting. When table rows are read or written, ```timestamp``` and ```time``` column values are adjusted by this timezone if it is set. Time zone can be an abbreviation form like 'PST' or 'DST'. Also, it accepts an offset-based form like 'UTC+9' or a location-based form like 'Asia/Seoul'.
+* ``text.error-tolerance.max-num``: the maximum number of permissible parsing errors. This value should be an integer value. By default, ``text.error-tolerance.max-num`` is ``0``. According to the value, parsing errors will be handled in different ways.
+ * If ``text.error-tolerance.max-num < 0``, all parsing errors are ignored.
+ * If ``text.error-tolerance.max-num == 0``, any parsing error is not allowed. If any error occurs, the query will be failed. (default)
+ * If ``text.error-tolerance.max-num > 0``, the given number of parsing errors in each task will be pemissible.
+
+The following example is to set a custom field delimiter, ``NULL`` character, and compression codec:
+
+.. code-block:: sql
+
+ CREATE TABLE table1 (
+ id int,
+ name text,
+ score float,
+ type text
+ ) USING TEXT WITH('text.delimiter'='\u0001',
+ 'text.null'='\\N',
+ 'compression.codec'='org.apache.hadoop.io.compress.SnappyCodec');
+
+.. warning::
+
+ Be careful when using ``\n`` as the field delimiter because *TEXT* format tables use ``\n`` as the line delimiter.
+ At the moment, Tajo does not provide a way to specify the line delimiter.
+
+=========================================
+Custom (De)serializer
+=========================================
+
+The *TEXT* format not only provides reading and writing interfaces for text data but also allows users to process custom
+plan-text file formats with user-defined (De)serializer classes.
+For example, with custom (de)serializers, Tajo can process JSON file formats or any specialized plan-text file formats.
+
+In order to specify a custom (De)serializer, set a physical property ``text.serde``.
+The property value should be a fully qualified class name.
+
+For example:
+
+.. code-block:: sql
+
+ CREATE TABLE table1 (
+ id int,
+ name text,
+ score float,
+ type text
+ ) USING TEXT WITH ('text.serde'='org.my.storage.CustomSerializerDeserializer')
+
+
+=========================================
+Null Value Handling Issues
+=========================================
+In default, ``NULL`` character in *TEXT* format is an empty string ``''``.
+In other words, an empty field is basically recognized as a ``NULL`` value in Tajo.
+If a field domain is ``TEXT``, an empty field is recognized as a string value ``''`` instead of ``NULL`` value.
+Besides, You can also use your own ``NULL`` character by specifying a physical property ``text.null``.
+
+=========================================
+Compatibility Issues with Apache Hive™
+=========================================
+
+*TEXT* tables generated in Tajo can be processed directly by Apache Hive™ without further processing.
+In this section, we explain some compatibility issue for users who use both Hive and Tajo.
+
+If you set a custom field delimiter, the *TEXT* tables cannot be directly used in Hive.
+In order to specify the custom field delimiter in Hive, you need to use ``ROW FORMAT DELIMITED FIELDS TERMINATED BY``
+clause in a Hive's ``CREATE TABLE`` statement as follows:
+
+.. code-block:: sql
+
+ CREATE TABLE table1 (id int, name string, score float, type string)
+ ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'
+ STORED AS TEXT
+
+To the best of our knowledge, there is not way to specify a custom ``NULL`` character in Hive.
[04/10] tajo git commit: TAJO-1338: Defines RESTful API for Clients
Posted by ji...@apache.org.
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
new file mode 100644
index 0000000..47a7bcb
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResource.java
@@ -0,0 +1,170 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.master.QueryInfo;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.apache.tajo.ws.rs.requests.NewSessionRequest;
+import org.apache.tajo.ws.rs.requests.SubmitQueryRequest;
+import org.apache.tajo.ws.rs.responses.NewSessionResponse;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.gson.internal.StringMap;
+
+import static org.junit.Assert.*;
+
+public class TestQueryResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI sessionsURI;
+ private URI queriesURI;
+ private Client restClient;
+
+ private static final String tajoSessionIdHeaderName = "X-Tajo-Session";
+
+ public TestQueryResource() {
+ super(TajoConstants.DEFAULT_DATABASE_NAME);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ sessionsURI = new URI(restServiceURI + "/sessions");
+ queriesURI = new URI(restServiceURI + "/databases/" + TajoConstants.DEFAULT_DATABASE_NAME + "/queries");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ private SubmitQueryRequest createNewQueryRequest(String query) throws Exception {
+ SubmitQueryRequest request = new SubmitQueryRequest();
+ request.setQuery(query);
+ return request;
+ }
+
+ private String generateNewSessionAndGetId() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+ request.setDatabaseName(TajoConstants.DEFAULT_DATABASE_NAME);
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertTrue(ResultCode.OK.equals(response.getResultCode()));
+ assertTrue(response.getId() != null && !response.getId().isEmpty());
+
+ return response.getId();
+ }
+
+ @Test
+ public void testGetAllQueries() throws Exception {
+ String sessionId = generateNewSessionAndGetId();
+ SubmitQueryRequest queryRequest = createNewQueryRequest("select * from lineitem");
+
+ Response response = restClient.target(queriesURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .post(Entity.entity(queryRequest, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+ String locationHeader = response.getHeaderString("Location");
+ assertTrue(locationHeader != null && !locationHeader.isEmpty());
+
+ String queryId = locationHeader.lastIndexOf('/') >= 0?
+ locationHeader.substring(locationHeader.lastIndexOf('/')+1):null;
+
+ assertTrue(queryId != null && !queryId.isEmpty());
+
+ Map<String, List<StringMap>> queriesMap = restClient.target(queriesURI)
+ .request().get(new GenericType<Map<String, List<StringMap>>>(Map.class));
+
+ assertNotNull(queriesMap);
+
+ List<StringMap> queryInfoList = queriesMap.get("queries");
+ assertNotNull(queryInfoList);
+
+ boolean assertQueryIdFound = false;
+ for (StringMap queryInfo: queryInfoList) {
+ if (queryId.equals(queryInfo.get("queryIdStr"))) {
+ assertQueryIdFound = true;
+ }
+ }
+
+ assertTrue(assertQueryIdFound);
+ }
+
+ @Test
+ public void testSubmitQuery() throws Exception {
+ String sessionId = generateNewSessionAndGetId();
+ SubmitQueryRequest queryRequest = createNewQueryRequest("select * from lineitem");
+
+ Response response = restClient.target(queriesURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .post(Entity.entity(queryRequest, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+ String locationHeader = response.getHeaderString("Location");
+ assertTrue(locationHeader != null && !locationHeader.isEmpty());
+
+ String queryId = locationHeader.lastIndexOf('/') >= 0?
+ locationHeader.substring(locationHeader.lastIndexOf('/')+1):null;
+
+ assertTrue(queryId != null && !queryId.isEmpty());
+
+ QueryInfo queryInfo = restClient.target(queriesURI)
+ .path("/{queryId}")
+ .resolveTemplate("queryId", queryId)
+ .queryParam("print", "BRIEF")
+ .request().get(new GenericType<QueryInfo>(QueryInfo.class));
+
+ assertNotNull(queryInfo);
+ assertEquals(queryId, queryInfo.getQueryIdStr());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
new file mode 100644
index 0000000..6fc4ea1
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestQueryResultResource.java
@@ -0,0 +1,287 @@
+/**
+ * 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.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.InputStream;
+import java.net.URI;
+import java.security.MessageDigest;
+import java.util.List;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.storage.RowStoreUtil;
+import org.apache.tajo.storage.Tuple;
+import org.apache.tajo.util.TUtil;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.apache.tajo.ws.rs.requests.NewSessionRequest;
+import org.apache.tajo.ws.rs.requests.SubmitQueryRequest;
+import org.apache.tajo.ws.rs.responses.GetQueryResultDataResponse;
+import org.apache.tajo.ws.rs.responses.NewSessionResponse;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestQueryResultResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI sessionsURI;
+ private URI queriesURI;
+ private Client restClient;
+
+ private static final String tajoSessionIdHeaderName = "X-Tajo-Session";
+ private static final String tajoDigestHeaderName = "X-Tajo-Digest";
+
+ public TestQueryResultResource() {
+ super(TajoConstants.DEFAULT_DATABASE_NAME);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ sessionsURI = new URI(restServiceURI + "/sessions");
+ queriesURI = new URI(restServiceURI + "/databases/" + TajoConstants.DEFAULT_DATABASE_NAME + "/queries");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ private String generateNewSessionAndGetId() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+ request.setDatabaseName(TajoConstants.DEFAULT_DATABASE_NAME);
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertTrue(ResultCode.OK.equals(response.getResultCode()));
+ assertTrue(response.getId() != null && !response.getId().isEmpty());
+
+ return response.getId();
+ }
+
+ private URI sendNewQueryResquest(String sessionId, String query) throws Exception {
+
+ SubmitQueryRequest request = new SubmitQueryRequest();
+ request.setQuery(query);
+
+ Response response = restClient.target(queriesURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .post(Entity.entity(request, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+ String locationHeader = response.getHeaderString("Location");
+ assertTrue(locationHeader != null && !locationHeader.isEmpty());
+
+ URI queryIdURI = new URI(locationHeader);
+
+ assertNotNull(queryIdURI);
+
+ return queryIdURI;
+ }
+
+ @Test
+ public void testGetQueryResult() throws Exception {
+ String sessionId = generateNewSessionAndGetId();
+ URI queryIdURI = sendNewQueryResquest(sessionId, "select * from lineitem");
+ URI queryResultURI = new URI(queryIdURI + "/result");
+
+ GetQueryResultDataResponse response = restClient.target(queryResultURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .get(new GenericType<GetQueryResultDataResponse>(GetQueryResultDataResponse.class));
+
+ assertNotNull(response);
+ assertNotNull(response.getResultCode());
+ assertEquals(ResultCode.OK, response.getResultCode());
+ assertNotNull(response.getSchema());
+ assertEquals(16, response.getSchema().getColumns().size());
+ assertNotNull(response.getResultset());
+ assertTrue(response.getResultset().getId() != 0);
+ assertNotNull(response.getResultset().getLink());
+ }
+
+ @Test
+ public void testGetQueryResultNotFound() throws Exception {
+ String sessionId = generateNewSessionAndGetId();
+ URI queryIdURI = new URI(queriesURI + "/q_11111_0001");
+ URI queryResultURI = new URI(queryIdURI + "/result");
+
+ Response response = restClient.target(queryResultURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .get();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testGetQueryResultSet() throws Exception {
+ String sessionId = generateNewSessionAndGetId();
+ URI queryIdURI = sendNewQueryResquest(sessionId, "select * from lineitem");
+ URI queryResultURI = new URI(queryIdURI + "/result");
+
+ GetQueryResultDataResponse response = restClient.target(queryResultURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .get(new GenericType<GetQueryResultDataResponse>(GetQueryResultDataResponse.class));
+
+ assertNotNull(response);
+ assertNotNull(response.getResultCode());
+ assertEquals(ResultCode.OK, response.getResultCode());
+ assertNotNull(response.getSchema());
+ assertEquals(16, response.getSchema().getColumns().size());
+ assertNotNull(response.getResultset());
+ assertTrue(response.getResultset().getId() != 0);
+ assertNotNull(response.getResultset().getLink());
+
+ URI queryResultSetURI = response.getResultset().getLink();
+
+ Response queryResultSetResponse = restClient.target(queryResultSetURI)
+ .queryParam("count", 100)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .get();
+
+ assertNotNull(queryResultSetResponse);
+ String tajoDigest = queryResultSetResponse.getHeaderString(tajoDigestHeaderName);
+ assertTrue(tajoDigest != null && !tajoDigest.isEmpty());
+
+ DataInputStream queryResultSetInputStream =
+ new DataInputStream(new BufferedInputStream(queryResultSetResponse.readEntity(InputStream.class)));
+
+ assertNotNull(queryResultSetInputStream);
+
+ boolean isFinished = false;
+ List<Tuple> tupleList = TUtil.newList();
+ RowStoreUtil.RowStoreDecoder decoder = RowStoreUtil.createDecoder(response.getSchema());
+ MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
+ while (!isFinished) {
+ try {
+ int length = queryResultSetInputStream.readInt();
+ byte[] dataByteArray = new byte[length];
+ int readBytes = queryResultSetInputStream.read(dataByteArray);
+
+ assertEquals(length, readBytes);
+
+ tupleList.add(decoder.toTuple(dataByteArray));
+ messageDigest.update(dataByteArray);
+ } catch (EOFException eof) {
+ isFinished = true;
+ }
+ }
+
+ assertEquals(5, tupleList.size());
+ assertEquals(tajoDigest, Base64.encodeBase64String(messageDigest.digest()));
+
+ for (Tuple aTuple: tupleList) {
+ assertTrue(aTuple.getInt4(response.getSchema().getColumnId("l_orderkey")) > 0);
+ }
+ }
+
+ @Test
+ public void testGetQueryResultSetWithOffset() throws Exception {
+ String sessionId = generateNewSessionAndGetId();
+ URI queryIdURI = sendNewQueryResquest(sessionId, "select * from lineitem");
+ URI queryResultURI = new URI(queryIdURI + "/result");
+
+ GetQueryResultDataResponse response = restClient.target(queryResultURI)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .get(new GenericType<GetQueryResultDataResponse>(GetQueryResultDataResponse.class));
+
+ assertNotNull(response);
+ assertNotNull(response.getResultCode());
+ assertEquals(ResultCode.OK, response.getResultCode());
+ assertNotNull(response.getSchema());
+ assertEquals(16, response.getSchema().getColumns().size());
+ assertNotNull(response.getResultset());
+ assertTrue(response.getResultset().getId() != 0);
+ assertNotNull(response.getResultset().getLink());
+
+ URI queryResultSetURI = response.getResultset().getLink();
+
+ Response queryResultSetResponse = restClient.target(queryResultSetURI)
+ .queryParam("count", 100)
+ .queryParam("offset", 3)
+ .request().header(tajoSessionIdHeaderName, sessionId)
+ .get();
+
+ assertNotNull(queryResultSetResponse);
+ String tajoDigest = queryResultSetResponse.getHeaderString(tajoDigestHeaderName);
+ assertTrue(tajoDigest != null && !tajoDigest.isEmpty());
+
+ DataInputStream queryResultSetInputStream =
+ new DataInputStream(new BufferedInputStream(queryResultSetResponse.readEntity(InputStream.class)));
+
+ assertNotNull(queryResultSetInputStream);
+
+ boolean isFinished = false;
+ List<Tuple> tupleList = TUtil.newList();
+ RowStoreUtil.RowStoreDecoder decoder = RowStoreUtil.createDecoder(response.getSchema());
+ MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
+ while (!isFinished) {
+ try {
+ int length = queryResultSetInputStream.readInt();
+ byte[] dataByteArray = new byte[length];
+ int readBytes = queryResultSetInputStream.read(dataByteArray);
+
+ assertEquals(length, readBytes);
+
+ tupleList.add(decoder.toTuple(dataByteArray));
+ messageDigest.update(dataByteArray);
+ } catch (EOFException eof) {
+ isFinished = true;
+ }
+ }
+
+ assertEquals(3, tupleList.size());
+ assertEquals(tajoDigest, Base64.encodeBase64String(messageDigest.digest()));
+
+ for (Tuple aTuple: tupleList) {
+ assertTrue(aTuple.getInt4(response.getSchema().getColumnId("l_orderkey")) > 0);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestSessionsResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestSessionsResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestSessionsResource.java
new file mode 100644
index 0000000..7b293d8
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestSessionsResource.java
@@ -0,0 +1,263 @@
+/**
+ * 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.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.apache.tajo.ws.rs.requests.NewSessionRequest;
+import org.apache.tajo.ws.rs.responses.NewSessionResponse;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestSessionsResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI sessionsURI;
+ private Client restClient;
+
+ public TestSessionsResource() {
+ super(TajoConstants.DEFAULT_DATABASE_NAME);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ sessionsURI = new URI(restServiceURI + "/sessions");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ private NewSessionRequest createNewSessionRequest() {
+ NewSessionRequest request = new NewSessionRequest();
+
+ request.setUserName("tajo-user1");
+ request.setDatabaseName("default");
+
+ return request;
+ }
+
+ @Test
+ public void testNewSession() throws Exception {
+ NewSessionRequest request = createNewSessionRequest();
+
+ assertNotNull(request);
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertNotNull(response.getId());
+ assertTrue(response.getMessage() == null || response.getMessage().isEmpty());
+ assertFalse(response.getId().isEmpty());
+ }
+
+ @Test
+ public void testNewSessionWithoutDBName() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertNotNull(response.getId());
+ assertTrue(response.getMessage() == null || response.getMessage().isEmpty());
+ assertFalse(response.getId().isEmpty());
+ }
+
+ @Test
+ public void testNewSessionWithBadRequest() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setDatabaseName("default");
+
+ Response response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testRemoveSession() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertTrue(response.getId() != null && !response.getId().isEmpty());
+
+ Response restResponse = restClient.target(sessionsURI)
+ .path("/{session-id}").resolveTemplate("session-id", response.getId())
+ .request().delete();
+
+ assertNotNull(restResponse);
+ assertEquals(Status.OK.getStatusCode(), restResponse.getStatus());
+ }
+
+ @Test
+ public void testRemoveSessionNotFound() throws Exception {
+ String invalidSessionId = "invalid";
+
+ Response response = restClient.target(sessionsURI)
+ .path("/{session-id}").resolveTemplate("session-id", invalidSessionId)
+ .request().delete();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testGetAllSessionVariables() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertTrue(response.getId() != null && !response.getId().isEmpty());
+
+ Map<String, Map<String, String>> variablesMap = restClient.target(sessionsURI)
+ .path("/{session-id}/variables").resolveTemplate("session-id", response.getId())
+ .request().get(new GenericType<Map<String, Map<String, String>>>(Map.class));
+
+ assertNotNull(variablesMap);
+ assertTrue(variablesMap.containsKey("variables"));
+ }
+
+ @Test
+ public void testGetAllSessionVariablesNotFound() throws Exception {
+ String invalidSessionId = "invalid";
+
+ Response response = restClient.target(sessionsURI)
+ .path("/{session-id}/variables").resolveTemplate("session-id", invalidSessionId)
+ .request().get();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testUpdateSessionVariables() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertTrue(response.getId() != null && !response.getId().isEmpty());
+
+ Map<String, String> variablesMap = new HashMap<String, String>();
+ variablesMap.put("variableA", "valueA");
+ variablesMap.put("variableB", "valueB");
+ Map<String, Map<String, String>> variables = new HashMap<String, Map<String, String>>();
+ variables.put("variables", variablesMap);
+ Response restResponse = restClient.target(sessionsURI)
+ .path("/{session-id}/variables").resolveTemplate("session-id", response.getId())
+ .request().put(Entity.entity(variables, MediaType.APPLICATION_JSON));
+
+ assertNotNull(restResponse);
+ assertEquals(Status.OK.getStatusCode(), restResponse.getStatus());
+
+ Map<String, Map<String, String>> retrievedVariables = restClient.target(sessionsURI)
+ .path("/{session-id}/variables").resolveTemplate("session-id", response.getId())
+ .request().get(new GenericType<Map<String, Map<String, String>>>(Map.class));
+
+ assertNotNull(retrievedVariables);
+ assertFalse(retrievedVariables.isEmpty());
+
+ Map<String, String> retrievedVariablesMap = retrievedVariables.get("variables");
+
+ assertNotNull(retrievedVariablesMap);
+ assertFalse(retrievedVariablesMap.isEmpty());
+
+ assertTrue(retrievedVariablesMap.containsKey("variableA"));
+ assertTrue(retrievedVariablesMap.containsKey("variableB"));
+ assertTrue("valueA".equals(retrievedVariablesMap.get("variableA")));
+ assertTrue("valueB".equals(retrievedVariablesMap.get("variableB")));
+ }
+
+ @Test
+ public void testUpdateSessionVariable() throws Exception {
+ NewSessionRequest request = new NewSessionRequest();
+ request.setUserName("tajo-user");
+
+ NewSessionResponse response = restClient.target(sessionsURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON), NewSessionResponse.class);
+
+ assertNotNull(response);
+ assertTrue(response.getId() != null && !response.getId().isEmpty());
+
+ Map<String, String> variablesMap = new HashMap<String, String>();
+ variablesMap.put("variableA", "valueA");
+ Response restResponse = restClient.target(sessionsURI)
+ .path("/{session-id}/variables").resolveTemplate("session-id", response.getId())
+ .request().put(Entity.entity(variablesMap, MediaType.APPLICATION_JSON));
+
+ assertNotNull(restResponse);
+ assertEquals(Status.OK.getStatusCode(), restResponse.getStatus());
+
+ Map<String, Map<String, String>> retrievedVariables = restClient.target(sessionsURI)
+ .path("/{session-id}/variables").resolveTemplate("session-id", response.getId())
+ .request().get(new GenericType<Map<String, Map<String, String>>>(Map.class));
+
+ assertNotNull(retrievedVariables);
+ assertFalse(retrievedVariables.isEmpty());
+
+ Map<String, String> retrievedVariablesMap = retrievedVariables.get("variables");
+
+ assertNotNull(retrievedVariablesMap);
+ assertFalse(retrievedVariablesMap.isEmpty());
+
+ assertTrue(retrievedVariablesMap.containsKey("variableA"));
+ assertTrue("valueA".equals(retrievedVariablesMap.get("variableA")));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
new file mode 100644
index 0000000..6144534
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestTablesResource.java
@@ -0,0 +1,195 @@
+/**
+ * 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.List;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+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.StoreType;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.storage.StorageConstants;
+import org.apache.tajo.util.KeyValueSet;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.gson.internal.StringMap;
+
+import static org.junit.Assert.*;
+
+public class TestTablesResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI tablesURI;
+ private Client restClient;
+
+ private static final String defaultDatabaseName = "TestTablesDB";
+
+ public TestTablesResource() {
+ super(defaultDatabaseName);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ tablesURI = new URI(restServiceURI + "/databases/" + defaultDatabaseName + "/tables");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ private TableDesc createNewTableForTestCreateTable(String tableName) throws Exception {
+ Schema tableSchema = new Schema(new Column[] {new Column("column1", TajoDataTypes.Type.TEXT)});
+ KeyValueSet tableOptions = new KeyValueSet();
+ tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+ TableMeta tableMeta = new TableMeta(StoreType.CSV, tableOptions);
+ return new TableDesc(tableName, tableSchema, tableMeta, null);
+ }
+
+ @Test
+ public void testCreateTable() throws Exception {
+ String tableName = "TestCreateTable";
+ TableDesc tableDesc = createNewTableForTestCreateTable(tableName);
+
+ Response response = restClient.target(tablesURI)
+ .request().post(Entity.entity(tableDesc, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testGetAllTable() throws Exception {
+ String tableName = "TestGetAllTable";
+ TableDesc tableDesc = createNewTableForTestCreateTable(tableName);
+
+ Response response = restClient.target(tablesURI)
+ .request().post(Entity.entity(tableDesc, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+
+ List<StringMap<String>> tables = restClient.target(tablesURI)
+ .request().get(new GenericType<List<StringMap<String>>>(List.class));
+
+ assertNotNull(tables);
+ assertTrue(!tables.isEmpty());
+
+ boolean tableFound = false;
+ for (StringMap<String> table: tables) {
+ if (tableName.equals(CatalogUtil.extractSimpleName(table.get("tableName")))) {
+ tableFound = true;
+ break;
+ }
+ }
+
+ assertTrue(tableFound);
+ }
+
+ @Test
+ public void testGetTable() throws Exception {
+ String tableName = "TestGetTable";
+ TableDesc tableDesc = createNewTableForTestCreateTable(tableName);
+
+ Response response = restClient.target(tablesURI)
+ .request().post(Entity.entity(tableDesc, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+
+ TableDesc selectedTable = restClient.target(tablesURI)
+ .path("/{tableName}").resolveTemplate("tableName", tableName)
+ .request().get(new GenericType<TableDesc>(TableDesc.class));
+
+ assertNotNull(selectedTable);
+ assertEquals(tableName, CatalogUtil.extractSimpleName(selectedTable.getName()));
+ }
+
+ @Test
+ public void testGetTableNotFound() throws Exception {
+ Response response = restClient.target(tablesURI)
+ .path("/{tableName}").resolveTemplate("tableName", "TestGetTableNotFound")
+ .request().get();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testDropTable() throws Exception {
+ String tableName = "TestDropTable";
+ TableDesc tableDesc = createNewTableForTestCreateTable(tableName);
+
+ Response response = restClient.target(tablesURI)
+ .request().post(Entity.entity(tableDesc, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+
+ TableDesc selectedTable = restClient.target(tablesURI)
+ .path("/{tableName}").resolveTemplate("tableName", tableName)
+ .request().get(new GenericType<TableDesc>(TableDesc.class));
+
+ assertNotNull(selectedTable);
+ assertEquals(tableName, CatalogUtil.extractSimpleName(selectedTable.getName()));
+
+ response = restClient.target(tablesURI)
+ .path("/{tableName}").resolveTemplate("tableName", tableName)
+ .request().delete();
+
+ assertNotNull(response);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testDropTableNotFound() throws Exception {
+ Response response = restClient.target(tablesURI)
+ .path("/{tableName}").resolveTemplate("tableName", "TestDropTableNotFound")
+ .request().delete();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-project/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-project/pom.xml b/tajo-project/pom.xml
index 7ad4ae0..e2b0a0e 100644
--- a/tajo-project/pom.xml
+++ b/tajo-project/pom.xml
@@ -1012,6 +1012,11 @@
<version>2.6</version>
</dependency>
<dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.10</version>
+ </dependency>
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/pom.xml b/tajo-rpc/tajo-ws-rs/pom.xml
index a87a67a..271d29a 100644
--- a/tajo-rpc/tajo-ws-rs/pom.xml
+++ b/tajo-rpc/tajo-ws-rs/pom.xml
@@ -95,6 +95,10 @@
<artifactId>tajo-rpc-common</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.tajo</groupId>
+ <artifactId>tajo-common</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/ResourceConfigUtil.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/ResourceConfigUtil.java b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/ResourceConfigUtil.java
new file mode 100644
index 0000000..10c680c
--- /dev/null
+++ b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/ResourceConfigUtil.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.ws.rs;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+public class ResourceConfigUtil {
+
+ public static Application getJAXRSApplication(Application application) {
+ Application result = application;
+
+ if (application instanceof ResourceConfig) {
+ ResourceConfig resourceConfig = (ResourceConfig) application;
+ result = resourceConfig.getApplication();
+ }
+
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonFeature.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonFeature.java b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonFeature.java
index 26086d4..20d7181 100644
--- a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonFeature.java
+++ b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonFeature.java
@@ -18,17 +18,38 @@
package org.apache.tajo.ws.rs.netty.gson;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
+import org.apache.tajo.json.GsonSerDerAdapter;
+
public class GsonFeature implements Feature {
+
+ private Map<Type, GsonSerDerAdapter<?>> adapterMap;
+
+ public GsonFeature() {
+ }
+
+ public GsonFeature(Map<Type, GsonSerDerAdapter<?>> adapterMap) {
+ this.adapterMap = new HashMap<Type, GsonSerDerAdapter<?>>(adapterMap.size());
+ this.adapterMap.putAll(adapterMap);
+ }
@Override
public boolean configure(FeatureContext featureContext) {
- featureContext.register(GsonReader.class, MessageBodyReader.class);
- featureContext.register(GsonWriter.class, MessageBodyWriter.class);
+ if (adapterMap != null && !adapterMap.isEmpty()) {
+ featureContext.register(new GsonReader().setAdapterMap(adapterMap), MessageBodyReader.class);
+ featureContext.register(new GsonWriter().setAdapterMap(adapterMap), MessageBodyWriter.class);
+ } else {
+ featureContext.register(GsonReader.class, MessageBodyReader.class);
+ featureContext.register(GsonWriter.class, MessageBodyWriter.class);
+ }
return true;
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonReader.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonReader.java b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonReader.java
index 4d6e440..fdaf811 100644
--- a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonReader.java
+++ b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonReader.java
@@ -26,15 +26,27 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
+
+import org.apache.tajo.json.GsonSerDerAdapter;
+
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.Map.Entry;
/**
* Custom message body reader with Gson feature.
*/
@Consumes(MediaType.APPLICATION_JSON)
public class GsonReader<T> implements MessageBodyReader<T> {
+
+ private Map<Type, GsonSerDerAdapter<?>> adapterMap;
+
+ public GsonReader<T> setAdapterMap(Map<Type, GsonSerDerAdapter<?>> adapterMap) {
+ this.adapterMap = adapterMap;
+ return this;
+ }
@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
@@ -45,7 +57,16 @@ public class GsonReader<T> implements MessageBodyReader<T> {
public T readFrom(Class<T> aClass, Type type, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> multivaluedMap, InputStream inputStream)
throws IOException, WebApplicationException {
- Gson gson = new GsonBuilder().create();
+ Gson gson;
+ if (adapterMap != null && !adapterMap.isEmpty()) {
+ GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
+ for (Entry<Type, GsonSerDerAdapter<?>> adapter: adapterMap.entrySet()) {
+ gsonBuilder.registerTypeAdapter(adapter.getKey(), adapter.getValue());
+ }
+ gson = gsonBuilder.create();
+ } else {
+ gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+ }
Reader reader = new BufferedReader(new InputStreamReader(inputStream));
return gson.fromJson(reader, type);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonUtil.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonUtil.java b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonUtil.java
index f16cb96..9994bfa 100644
--- a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonUtil.java
+++ b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonUtil.java
@@ -21,7 +21,7 @@ package org.apache.tajo.ws.rs.netty.gson;
import javax.ws.rs.core.MediaType;
public class GsonUtil {
-
+
public static boolean isJsonType(MediaType mediaType) {
if (mediaType != null) {
String subType = mediaType.getSubtype();
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonWriter.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonWriter.java b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonWriter.java
index d215611..29a4bbf 100644
--- a/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonWriter.java
+++ b/tajo-rpc/tajo-ws-rs/src/main/java/org/apache/tajo/ws/rs/netty/gson/GsonWriter.java
@@ -26,15 +26,27 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.apache.tajo.json.GsonSerDerAdapter;
+
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.Map.Entry;
/**
* custom message body writer with Gson feature.
*/
@Produces(MediaType.APPLICATION_JSON)
public class GsonWriter<T> implements MessageBodyWriter<T> {
+
+ private Map<Type, GsonSerDerAdapter<?>> adapterMap;
+
+ public GsonWriter<T> setAdapterMap(Map<Type, GsonSerDerAdapter<?>> adapterMap) {
+ this.adapterMap = adapterMap;
+ return this;
+ }
@Override
public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
@@ -50,7 +62,16 @@ public class GsonWriter<T> implements MessageBodyWriter<T> {
public void writeTo(T t, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream)
throws IOException, WebApplicationException {
- Gson gson = new GsonBuilder().create();
+ Gson gson;
+ if (adapterMap != null && !adapterMap.isEmpty()) {
+ GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
+ for (Entry<Type, GsonSerDerAdapter<?>> adapter: adapterMap.entrySet()) {
+ gsonBuilder.registerTypeAdapter(adapter.getKey(), adapter.getValue());
+ }
+ gson = gsonBuilder.create();
+ } else {
+ gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+ }
Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));
gson.toJson(t, type, writer);
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-rpc/tajo-ws-rs/src/test/java/org/apache/tajo/ws/rs/netty/testapp2/Directory.java
----------------------------------------------------------------------
diff --git a/tajo-rpc/tajo-ws-rs/src/test/java/org/apache/tajo/ws/rs/netty/testapp2/Directory.java b/tajo-rpc/tajo-ws-rs/src/test/java/org/apache/tajo/ws/rs/netty/testapp2/Directory.java
index 3851020..4ddc2b2 100644
--- a/tajo-rpc/tajo-ws-rs/src/test/java/org/apache/tajo/ws/rs/netty/testapp2/Directory.java
+++ b/tajo-rpc/tajo-ws-rs/src/test/java/org/apache/tajo/ws/rs/netty/testapp2/Directory.java
@@ -20,11 +20,13 @@ package org.apache.tajo.ws.rs.netty.testapp2;
import java.io.Serializable;
+import com.google.gson.annotations.Expose;
+
public class Directory implements Serializable {
- private String name;
- private String owner;
- private String group;
+ @Expose private String name;
+ @Expose private String owner;
+ @Expose private String group;
public String getName() {
return name;
[03/10] tajo git commit: TAJO-1400: Add TajoStatement::setMaxRows
method support.
Posted by ji...@apache.org.
TAJO-1400: Add TajoStatement::setMaxRows method support.
Closes #421
Signed-off-by: Jihoon Son <ji...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/696d2aa7
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/696d2aa7
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/696d2aa7
Branch: refs/heads/index_support
Commit: 696d2aa7fe6a507209c5b4660d4c4efb934d49b6
Parents: dd43373
Author: Yeonsu Han <ha...@gmail.com>
Authored: Sun Apr 5 23:28:42 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Sun Apr 5 23:29:07 2015 +0900
----------------------------------------------------------------------
CHANGES | 3 ++
.../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/jdbc/TestTajoJdbc.java | 40 +++++++++++++++++++-
.../org/apache/tajo/jdbc/TajoStatement.java | 7 +++-
7 files changed, 76 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e8a2c1f..4ec678f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@ Release 0.11.0 - unreleased
IMPROVEMENT
+ TAJO-1400: Add TajoStatement::setMaxRows method support.
+ (Contributed by YeonSu Han, Committed by jihoon)
+
TAJO-1421: Add 'ALTER TABLE SET PROPERTY' statement.
(Contributed by Yongjin Choi. Committed by jaehwa)
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
----------------------------------------------------------------------
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 7c7db33..39b5fc3 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
@@ -45,6 +45,10 @@ public interface QueryClient extends Closeable {
public Map<String, String> getClientSideSessionVars();
public String getBaseDatabase();
+
+ public void setMaxRows(int maxRows);
+
+ public int getMaxRows();
@Override
public void close();
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------
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 fae613a..4444a31 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
@@ -51,11 +51,14 @@ public class QueryClientImpl implements QueryClient {
private static final Log LOG = LogFactory.getLog(QueryClientImpl.class);
private final SessionConnection connection;
private final int defaultFetchRows;
+//maxRows number is limit value of resultSet. The value must be >= 0, and 0 means there is not limit.
+ private int maxRows;
public QueryClientImpl(SessionConnection connection) {
this.connection = connection;
this.defaultFetchRows = this.connection.getProperties().getInt(SessionVars.FETCH_ROWNUM.getConfVars().keyname(),
SessionVars.FETCH_ROWNUM.getConfVars().defaultIntVal);
+ this.maxRows = 0;
}
@Override
@@ -577,6 +580,16 @@ public class QueryClientImpl implements QueryClient {
return status;
}
+ @Override
+ public void setMaxRows(int maxRows) {
+ this.maxRows = maxRows;
+ }
+
+ @Override
+ public int getMaxRows() {
+ return this.maxRows;
+ }
+
public QueryInfoProto getQueryInfo(final QueryId queryId) throws ServiceException {
return new ServerCallable<QueryInfoProto>(connection.connPool, connection.getTajoMasterAddr(),
TajoMasterClientProtocol.class, false, true) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
----------------------------------------------------------------------
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 e61bea0..612b56e 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
@@ -166,6 +166,14 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que
return queryClient.getQueryHistory(queryId);
}
+ public void setMaxRows(int maxRows) {
+ queryClient.setMaxRows(maxRows);
+ }
+
+ public int getMaxRows() {
+ return queryClient.getMaxRows();
+ }
+
/*------------------------------------------------------------------------*/
// CatalogClient wrappers
/*------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
----------------------------------------------------------------------
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 06773f4..efe070e 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
@@ -32,10 +32,13 @@ public class FetchResultSet extends TajoResultSetBase {
private int fetchRowNum;
private TajoMemoryResultSet currentResultSet;
private boolean finished = false;
+// maxRows number is limit value of resultSet. The value must be >= 0, and 0 means there is not limit.
+ private int maxRows;
public FetchResultSet(QueryClient tajoClient, Schema schema, QueryId queryId, int fetchRowNum) {
super(tajoClient.getClientSideSessionVars());
this.tajoClient = tajoClient;
+ this.maxRows = tajoClient.getMaxRows();
this.queryId = queryId;
this.fetchRowNum = fetchRowNum;
this.totalRow = Integer.MAX_VALUE;
@@ -48,7 +51,7 @@ public class FetchResultSet extends TajoResultSetBase {
@Override
protected Tuple nextTuple() throws IOException {
- if (finished) {
+ if (finished || (maxRows > 0 && curRow >= maxRows)) {
return null;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
----------------------------------------------------------------------
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 db6192c..36bbd94 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
@@ -635,4 +635,42 @@ public class TestTajoJdbc extends QueryTestCaseBase {
}
}
}
-}
\ No newline at end of file
+
+ @Test
+ public void testMaxRows() throws Exception {
+ String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(),
+ DEFAULT_DATABASE_NAME);
+ Connection conn = DriverManager.getConnection(connUri);
+ assertTrue(conn.isValid(100));
+ Statement stmt = null;
+ ResultSet res = null;
+ //Parameter value setting for test.
+ final int maxRowsNum = 3;
+ int resultRowsNum = 0, returnMaxRows = 0;
+ try {
+ stmt = conn.createStatement();
+ //set maxRows(3)
+ stmt.setMaxRows(maxRowsNum);
+ //get MaxRows
+ returnMaxRows = stmt.getMaxRows();
+ res = stmt.executeQuery("select * from lineitem");
+ assertNotNull(res);
+ while (res.next()) {
+ //Actuality result Rows.
+ resultRowsNum++;
+ }
+ //The test success, if maxRowsNum and resultRowsNum and returnMaxRows is same.
+ assertTrue(maxRowsNum == resultRowsNum && maxRowsNum == returnMaxRows);
+ } finally {
+ if (res != null) {
+ cleanupQuery(res);
+ }
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
----------------------------------------------------------------------
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 0a0a849..820e350 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
@@ -241,7 +241,7 @@ public class TajoStatement implements Statement {
@Override
public int getMaxRows() throws SQLException {
- throw new SQLFeatureNotSupportedException("getMaxRows not supported");
+ return tajoClient.getMaxRows() ;
}
@Override
@@ -340,7 +340,10 @@ public class TajoStatement implements Statement {
@Override
public void setMaxRows(int max) throws SQLException {
- throw new SQLFeatureNotSupportedException("setMaxRows not supported");
+ if (max < 0) {
+ throw new SQLException("max must be >= 0");
+ }
+ tajoClient.setMaxRows(max);
}
@Override
[07/10] tajo git commit: TAJO-1510: Change a function name from
getFileCunks to getFileChunks.
Posted by ji...@apache.org.
TAJO-1510: Change a function name from getFileCunks to getFileChunks.
Closes #499
Signed-off-by: JaeHwa Jung <bl...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/4eb87133
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/4eb87133
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/4eb87133
Branch: refs/heads/index_support
Commit: 4eb8713326d5f049df577e49c1a2e629b3ee8096
Parents: 32b524d
Author: swlsw <so...@gmail.com>
Authored: Mon Apr 6 12:11:31 2015 +0900
Committer: JaeHwa Jung <bl...@apache.org>
Committed: Mon Apr 6 12:11:31 2015 +0900
----------------------------------------------------------------------
CHANGES | 3 +++
tajo-core/src/main/java/org/apache/tajo/worker/Task.java | 3 +--
.../org/apache/tajo/pullserver/TajoPullServerService.java | 10 +++++-----
3 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/4eb87133/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index efadea8..7ea0b5e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -69,6 +69,9 @@ Release 0.11.0 - unreleased
BUG FIXES
+ TAJO-1510: Change a function name from getFileCunks to getFileChunks.
+ (Contributed by Soonwoong Lee, Committed by jaehwa)
+
TAJO-1360: VALUES_ field in OPTIONS table of catalog store should be longer.
(Contributed by DaeMyung Kang, Committed by jihun)
http://git-wip-us.apache.org/repos/asf/tajo/blob/4eb87133/tajo-core/src/main/java/org/apache/tajo/worker/Task.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/worker/Task.java b/tajo-core/src/main/java/org/apache/tajo/worker/Task.java
index 9ff18dd..b08af2b 100644
--- a/tajo-core/src/main/java/org/apache/tajo/worker/Task.java
+++ b/tajo-core/src/main/java/org/apache/tajo/worker/Task.java
@@ -22,7 +22,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import io.netty.channel.EventLoopGroup;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -791,7 +790,7 @@ public class Task {
boolean last = params.get("final") != null;
try {
- chunk = TajoPullServerService.getFileCunks(path, startKey, endKey, last);
+ chunk = TajoPullServerService.getFileChunks(path, startKey, endKey, last);
} catch (Throwable t) {
LOG.error("getFileChunks() throws exception");
return null;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4eb87133/tajo-pullserver/src/main/java/org/apache/tajo/pullserver/TajoPullServerService.java
----------------------------------------------------------------------
diff --git a/tajo-pullserver/src/main/java/org/apache/tajo/pullserver/TajoPullServerService.java b/tajo-pullserver/src/main/java/org/apache/tajo/pullserver/TajoPullServerService.java
index 6894cc5..29cf719 100644
--- a/tajo-pullserver/src/main/java/org/apache/tajo/pullserver/TajoPullServerService.java
+++ b/tajo-pullserver/src/main/java/org/apache/tajo/pullserver/TajoPullServerService.java
@@ -520,7 +520,7 @@ public class TajoPullServerService extends AbstractService {
FileChunk chunk;
try {
- chunk = getFileCunks(path, startKey, endKey, last);
+ chunk = getFileChunks(path, startKey, endKey, last);
} catch (Throwable t) {
LOG.error("ERROR Request: " + request.getUri(), t);
sendError(ctx, "Cannot get file chunks to be sent", HttpResponseStatus.BAD_REQUEST);
@@ -672,10 +672,10 @@ public class TajoPullServerService extends AbstractService {
}
}
- public static FileChunk getFileCunks(Path outDir,
- String startKey,
- String endKey,
- boolean last) throws IOException {
+ public static FileChunk getFileChunks(Path outDir,
+ String startKey,
+ String endKey,
+ boolean last) throws IOException {
BSTIndex index = new BSTIndex(new TajoConf());
BSTIndex.BSTIndexReader idxReader =
index.getIndexReader(new Path(outDir, "index"));
[08/10] tajo git commit: TAJO-1499: Check the bind status when
EvalNode::eval() is called.
Posted by ji...@apache.org.
TAJO-1499: Check the bind status when EvalNode::eval() is called.
Closes #500
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/72948b63
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/72948b63
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/72948b63
Branch: refs/heads/index_support
Commit: 72948b63a79cd8902381c3443699c887b2740491
Parents: 4eb8713
Author: Jihoon Son <ji...@apache.org>
Authored: Mon Apr 6 13:37:56 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Mon Apr 6 13:37:56 2015 +0900
----------------------------------------------------------------------
CHANGES | 2 +
.../planner/physical/ComparableVector.java | 35 +++---
.../org/apache/tajo/engine/utils/TupleUtil.java | 31 ------
.../apache/tajo/master/exec/QueryExecutor.java | 1 +
.../apache/tajo/engine/eval/TestEvalTree.java | 107 ++++++++++++++-----
.../tajo/engine/eval/TestEvalTreeUtil.java | 12 +--
.../org/apache/tajo/plan/LogicalPlanner.java | 1 +
.../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 +
26 files changed, 165 insertions(+), 87 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 7ea0b5e..90fa245 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,8 @@ Release 0.11.0 - unreleased
IMPROVEMENT
+ TAJO-1499: Check the bind status when EvalNode::eval() is called. (jihoon)
+
TAJO-1400: Add TajoStatement::setMaxRows method support.
(Contributed by YeonSu Han, Committed by jihoon)
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ComparableVector.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ComparableVector.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ComparableVector.java
index 39b8c8a..9940608 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ComparableVector.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ComparableVector.java
@@ -225,24 +225,27 @@ public class ComparableVector {
@Override
public boolean equals(Object obj) {
- ComparableTuple other = (ComparableTuple)obj;
- for (int i = 0; i < keys.length; i++) {
- final boolean n1 = keys[i] == null;
- final boolean n2 = other.keys[i] == null;
- if (n1 && n2) {
- continue;
- }
- if (n1 ^ n2) {
- return false;
- }
- switch (keyTypes[i]) {
- case TEXT:
- case CHAR:
- case BLOB: if (!Arrays.equals((byte[])keys[i], (byte[])other.keys[i])) return false; continue;
- default: if (!keys[i].equals(other.keys[i])) return false; continue;
+ if (obj instanceof ComparableTuple) {
+ ComparableTuple other = (ComparableTuple)obj;
+ for (int i = 0; i < keys.length; i++) {
+ final boolean n1 = keys[i] == null;
+ final boolean n2 = other.keys[i] == null;
+ if (n1 && n2) {
+ continue;
+ }
+ if (n1 ^ n2) {
+ return false;
+ }
+ switch (keyTypes[i]) {
+ case TEXT:
+ case CHAR:
+ case BLOB: if (!Arrays.equals((byte[])keys[i], (byte[])other.keys[i])) return false; continue;
+ default: if (!keys[i].equals(other.keys[i])) return false; continue;
+ }
}
+ return true;
}
- return true;
+ return false;
}
public boolean equals(Tuple tuple) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java b/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
index 6b2c37c..3a0a1c7 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
@@ -193,35 +193,4 @@ public class TupleUtil {
}
return aTuple;
}
-
- @SuppressWarnings("unused")
- public static Collection<Tuple> filterTuple(Schema schema, Collection<Tuple> tupleBlock, EvalNode filterCondition) {
- TupleBlockFilterScanner filter = new TupleBlockFilterScanner(schema, tupleBlock, filterCondition);
- return filter.nextBlock();
- }
-
- private static class TupleBlockFilterScanner {
- private EvalNode qual;
- private Iterator<Tuple> iterator;
- private Schema schema;
-
- public TupleBlockFilterScanner(Schema schema, Collection<Tuple> tuples, EvalNode qual) {
- this.schema = schema;
- this.qual = qual;
- this.iterator = tuples.iterator();
- }
-
- public List<Tuple> nextBlock() {
- List<Tuple> results = Lists.newArrayList();
-
- Tuple tuple;
- while (iterator.hasNext()) {
- tuple = iterator.next();
- if (qual.eval(tuple).isTrue()) {
- results.add(tuple);
- }
- }
- return results;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
index cec1125..2eb3c5f 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
@@ -274,6 +274,7 @@ public class QueryExecutor {
final Tuple outTuple = new VTuple(targets.length);
for (int i = 0; i < targets.length; i++) {
EvalNode eval = targets[i].getEvalTree();
+ eval.bind(null);
outTuple.put(i, eval.eval(null));
}
boolean isInsert = rootNode.getChild() != null && rootNode.getChild().getType() == NodeType.INSERT;
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
index f03988b..a2d0598 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
@@ -19,7 +19,9 @@
package org.apache.tajo.engine.eval;
import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.common.TajoDataTypes.DataType;
import org.apache.tajo.datum.Datum;
import org.apache.tajo.datum.DatumFactory;
@@ -31,6 +33,7 @@ import org.junit.Test;
import static org.apache.tajo.common.TajoDataTypes.Type.*;
import static org.junit.Assert.*;
+import static org.junit.Assert.fail;
public class TestEvalTree extends ExprTestBase {
@Test
@@ -79,6 +82,7 @@ public class TestEvalTree extends ExprTestBase {
@Override
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return DatumFactory.createBool(true);
}
@@ -111,6 +115,7 @@ public class TestEvalTree extends ExprTestBase {
@Override
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return DatumFactory.createBool(false);
}
@@ -156,15 +161,19 @@ public class TestEvalTree extends ExprTestBase {
MockFalseExpr falseExpr = new MockFalseExpr();
BinaryEval andExpr = new BinaryEval(EvalType.AND, trueExpr, trueExpr);
+ andExpr.bind(null);
assertTrue(andExpr.eval(null).asBool());
andExpr = new BinaryEval(EvalType.AND, falseExpr, trueExpr);
+ andExpr.bind(null);
assertFalse(andExpr.eval(null).asBool());
andExpr = new BinaryEval(EvalType.AND, trueExpr, falseExpr);
+ andExpr.bind(null);
assertFalse(andExpr.eval(null).asBool());
andExpr = new BinaryEval(EvalType.AND, falseExpr, falseExpr);
+ andExpr.bind(null);
assertFalse(andExpr.eval(null).asBool());
}
@@ -174,15 +183,19 @@ public class TestEvalTree extends ExprTestBase {
MockFalseExpr falseExpr = new MockFalseExpr();
BinaryEval orExpr = new BinaryEval(EvalType.OR, trueExpr, trueExpr);
+ orExpr.bind(null);
assertTrue(orExpr.eval(null).asBool());
orExpr = new BinaryEval(EvalType.OR, falseExpr, trueExpr);
+ orExpr.bind(null);
assertTrue(orExpr.eval(null).asBool());
orExpr = new BinaryEval(EvalType.OR, trueExpr, falseExpr);
+ orExpr.bind(null);
assertTrue(orExpr.eval(null).asBool());
orExpr = new BinaryEval(EvalType.OR, falseExpr, falseExpr);
+ orExpr.bind(null);
assertFalse(orExpr.eval(null).asBool());
}
@@ -196,41 +209,41 @@ public class TestEvalTree extends ExprTestBase {
e1 = new ConstEval(DatumFactory.createInt4(9));
e2 = new ConstEval(DatumFactory.createInt4(34));
expr = new BinaryEval(EvalType.LTH, e1, e2);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.LEQ, e1, e2);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.LTH, e2, e1);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.LEQ, e2, e1);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GTH, e2, e1);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GEQ, e2, e1);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GTH, e1, e2);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GEQ, e1, e2);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
BinaryEval plus = new BinaryEval(EvalType.PLUS, e1, e2);
expr = new BinaryEval(EvalType.LTH, e1, plus);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.LEQ, e1, plus);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.LTH, plus, e1);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.LEQ, plus, e1);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GTH, plus, e1);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GEQ, plus, e1);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GTH, e1, plus);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
expr = new BinaryEval(EvalType.GEQ, e1, plus);
- assertFalse(expr.eval(null).asBool());
+ assertFalse(expr.bind(null).eval(null).asBool());
}
@Test
@@ -243,28 +256,28 @@ public class TestEvalTree extends ExprTestBase {
e1 = new ConstEval(DatumFactory.createInt4(9));
e2 = new ConstEval(DatumFactory.createInt4(34));
BinaryEval expr = new BinaryEval(EvalType.PLUS, e1, e2);
- assertEquals(expr.eval(null).asInt4(), 43);
+ assertEquals(expr.bind(null).eval(null).asInt4(), 43);
assertCloneEqual(expr);
// MINUS
e1 = new ConstEval(DatumFactory.createInt4(5));
e2 = new ConstEval(DatumFactory.createInt4(2));
expr = new BinaryEval(EvalType.MINUS, e1, e2);
- assertEquals(expr.eval(null).asInt4(), 3);
+ assertEquals(expr.bind(null).eval(null).asInt4(), 3);
assertCloneEqual(expr);
// MULTIPLY
e1 = new ConstEval(DatumFactory.createInt4(5));
e2 = new ConstEval(DatumFactory.createInt4(2));
expr = new BinaryEval(EvalType.MULTIPLY, e1, e2);
- assertEquals(expr.eval(null).asInt4(), 10);
+ assertEquals(expr.bind(null).eval(null).asInt4(), 10);
assertCloneEqual(expr);
// DIVIDE
e1 = new ConstEval(DatumFactory.createInt4(10));
e2 = new ConstEval(DatumFactory.createInt4(5));
expr = new BinaryEval(EvalType.DIVIDE, e1, e2);
- assertEquals(expr.eval(null).asInt4(), 2);
+ assertEquals(expr.bind(null).eval(null).asInt4(), 2);
assertCloneEqual(expr);
}
@@ -280,7 +293,7 @@ public class TestEvalTree extends ExprTestBase {
assertEquals(CatalogUtil.newSimpleDataType(INT4), expr.getValueType());
expr = new BinaryEval(EvalType.LTH, e1, e2);
- assertTrue(expr.eval(null).asBool());
+ assertTrue(expr.bind(null).eval(null).asBool());
assertEquals(CatalogUtil.newSimpleDataType(BOOLEAN), expr.getValueType());
e1 = new ConstEval(DatumFactory.createFloat8(9.3));
@@ -350,11 +363,57 @@ public class TestEvalTree extends ExprTestBase {
assertEquals(e3.getType(), eval.getLeftExpr().getType());
assertEquals(plus3.getType(), eval.getRightExpr().getType());
assertEquals(plus3.getLeftExpr(), ((BinaryEval)eval.getRightExpr()).getLeftExpr());
- assertEquals(plus3.getRightExpr(), ((BinaryEval)eval.getRightExpr()).getRightExpr());
+ assertEquals(plus3.getRightExpr(), ((BinaryEval) eval.getRightExpr()).getRightExpr());
assertEquals(plus2.getLeftExpr(), ((BinaryEval)((BinaryEval)eval.getRightExpr()).getLeftExpr()).getLeftExpr());
assertEquals(plus2.getRightExpr(), ((BinaryEval)((BinaryEval)eval.getRightExpr()).getLeftExpr()).getRightExpr());
- assertEquals(plus1.getLeftExpr(), ((BinaryEval)((BinaryEval)eval.getRightExpr()).getRightExpr()).getLeftExpr());
- assertEquals(plus1.getRightExpr(), ((BinaryEval)((BinaryEval)eval.getRightExpr()).getRightExpr()).getRightExpr());
+ assertEquals(plus1.getLeftExpr(), ((BinaryEval) ((BinaryEval) eval.getRightExpr()).getRightExpr()).getLeftExpr());
+ assertEquals(plus1.getRightExpr(), ((BinaryEval) ((BinaryEval) eval.getRightExpr()).getRightExpr()).getRightExpr());
+ }
+
+ @Test
+ public final void testBindCheck() {
+ ConstEval e1;
+ ConstEval e2;
+ BinaryEval binEval;
+
+ // Constant
+ e1 = new ConstEval(DatumFactory.createInt4(9));
+ e2 = new ConstEval(DatumFactory.createInt4(34));
+ binEval = new BinaryEval(EvalType.LTH, e1, e2);
+ try {
+ binEval.eval(null);
+ fail("EvalNode is not binded");
+ } catch (IllegalStateException e) {
+ assertTrue(binEval.bind(null).eval(null).asBool());
+ }
+
+ CaseWhenEval caseWhenEval = new CaseWhenEval();
+ caseWhenEval.addIfCond(new CaseWhenEval.IfThenEval(binEval, new ConstEval(DatumFactory.createInt4(1))));
+ try {
+ caseWhenEval.eval(null);
+ fail("EvalNode is not binded");
+ } catch (IllegalStateException e) {
+ assertEquals(caseWhenEval.bind(null).eval(null).asInt4(), 1);
+ }
+
+ Schema schema = new Schema(new Column[]{new Column("test", TajoDataTypes.Type.INT4)});
+ Tuple tuple = new VTuple(new Datum[]{DatumFactory.createText("aaa")});
+ RegexPredicateEval regexEval = new RegexPredicateEval(false, new FieldEval("test",
+ CatalogUtil.newSimpleDataType(TajoDataTypes.Type.INT4)), new ConstEval(DatumFactory.createText("a*")), false);
+ try {
+ regexEval.eval(null);
+ fail("EvalNode is not binded");
+ } catch (IllegalStateException e) {
+ assertEquals(regexEval.bind(schema).eval(tuple).asBool(), true);
+ }
+
+ RowConstantEval rowConstantEval = new RowConstantEval(new Datum[]{});
+ try {
+ rowConstantEval.eval(null);
+ fail("EvalNode is not binded");
+ } catch (IllegalStateException e) {
+ assertEquals(rowConstantEval.bind(null).eval(null).isNull(), true);
+ }
}
private void assertCloneEqual(EvalNode eval) throws CloneNotSupportedException {
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
index 61c55e1..e23a34b 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
@@ -265,12 +265,12 @@ public class TestEvalTreeUtil {
FieldEval field = first.getLeftExpr();
assertEquals(col1, field.getColumnRef());
assertEquals(EvalType.LTH, first.getType());
- assertEquals(10, first.getRightExpr().eval(null).asInt4());
+ assertEquals(10, first.getRightExpr().bind(null).eval(null).asInt4());
field = second.getRightExpr();
assertEquals(col1, field.getColumnRef());
assertEquals(EvalType.LTH, second.getType());
- assertEquals(4, second.getLeftExpr().eval(null).asInt4());
+ assertEquals(4, second.getLeftExpr().bind(null).eval(null).asInt4());
}
@Test
@@ -304,10 +304,10 @@ public class TestEvalTreeUtil {
Target [] targets = getRawTargets(QUERIES[0]);
EvalNode node = AlgebraicUtil.eliminateConstantExprs(targets[0].getEvalTree());
assertEquals(EvalType.CONST, node.getType());
- assertEquals(7, node.eval(null).asInt4());
+ assertEquals(7, node.bind(null).eval(null).asInt4());
node = AlgebraicUtil.eliminateConstantExprs(targets[1].getEvalTree());
assertEquals(EvalType.CONST, node.getType());
- assertTrue(7.0d == node.eval(null).asFloat8());
+ assertTrue(7.0d == node.bind(null).eval(null).asFloat8());
Expr expr = analyzer.parse(QUERIES[1]);
LogicalPlan plan = planner.createPlan(defaultContext, expr, true);
@@ -335,7 +335,7 @@ public class TestEvalTreeUtil {
assertEquals(EvalType.GTH, transposed.getType());
FieldEval field = transposed.getLeftExpr();
assertEquals(col1, field.getColumnRef());
- assertEquals(1, transposed.getRightExpr().eval(null).asInt4());
+ assertEquals(1, transposed.getRightExpr().bind(null).eval(null).asInt4());
node = getRootSelection(QUERIES[4]);
// we expect that score < 3
@@ -343,7 +343,7 @@ public class TestEvalTreeUtil {
assertEquals(EvalType.LTH, transposed.getType());
field = transposed.getLeftExpr();
assertEquals(col1, field.getColumnRef());
- assertEquals(2, transposed.getRightExpr().eval(null).asInt4());
+ assertEquals(2, transposed.getRightExpr().bind(null).eval(null).asInt4());
}
@Test
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
index d6a04a6..d7c631b 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
@@ -810,6 +810,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
limitNode.setInSchema(child.getOutSchema());
limitNode.setOutSchema(child.getOutSchema());
+ firstFetNum.bind(null);
limitNode.setFetchFirst(firstFetNum.eval(null).asInt8());
return limitNode;
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AggregationFunctionCallEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AggregationFunctionCallEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AggregationFunctionCallEval.java
index 984d18c..5549e2e 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AggregationFunctionCallEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AggregationFunctionCallEval.java
@@ -50,6 +50,9 @@ public class AggregationFunctionCallEval extends FunctionEval implements Cloneab
}
public void merge(FunctionContext context, Tuple tuple) {
+ if (!isBinded) {
+ throw new IllegalStateException("bind() must be called before merge()");
+ }
mergeParam(context, evalParams(tuple));
}
@@ -68,6 +71,9 @@ public class AggregationFunctionCallEval extends FunctionEval implements Cloneab
}
public Datum terminate(FunctionContext context) {
+ if (!isBinded) {
+ throw new IllegalStateException("bind() must be called before terminate()");
+ }
if (!finalPhase) {
return instance.getPartialResult(context);
} else {
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java
index f697968..fb05f33 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java
@@ -149,7 +149,7 @@ public class AlgebraicUtil {
}
if (lhs.getType() == EvalType.CONST && rhs.getType() == EvalType.CONST) {
- return new ConstEval(binaryEval.eval(null));
+ return new ConstEval(binaryEval.bind(null).eval(null));
}
return binaryEval;
@@ -162,7 +162,7 @@ public class AlgebraicUtil {
stack.pop();
if (child.getType() == EvalType.CONST) {
- return new ConstEval(unaryEval.eval(null));
+ return new ConstEval(unaryEval.bind(null).eval(null));
}
return unaryEval;
@@ -184,7 +184,7 @@ public class AlgebraicUtil {
}
if (constantOfAllDescendents && evalNode.getType() == EvalType.FUNCTION) {
- return new ConstEval(evalNode.eval(null));
+ return new ConstEval(evalNode.bind(null).eval(null));
} else {
return evalNode;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BetweenPredicateEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BetweenPredicateEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BetweenPredicateEval.java
index 3969f63..2db4368 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BetweenPredicateEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BetweenPredicateEval.java
@@ -227,7 +227,8 @@ public class BetweenPredicateEval extends EvalNode implements Cloneable {
}
@Override
- public void bind(Schema schema) {
+ public EvalNode bind(Schema schema) {
+ super.bind(schema);
if (begin.getType() == EvalType.CONST && end.getType() == EvalType.CONST) {
Datum beginValue = ((ConstEval)begin).getValue();
Datum endValue = ((ConstEval)end).getValue();
@@ -245,11 +246,13 @@ public class BetweenPredicateEval extends EvalNode implements Cloneable {
}
}
checker.bind(schema);
+ return this;
}
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return checker.eval(tuple);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BinaryEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BinaryEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BinaryEval.java
index e189a36..531cb9f 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BinaryEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BinaryEval.java
@@ -119,6 +119,7 @@ public class BinaryEval extends EvalNode implements Cloneable {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
Datum lhs = leftExpr.eval(tuple);
Datum rhs = rightExpr.eval(tuple);
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CaseWhenEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CaseWhenEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CaseWhenEval.java
index c25ad45..2f40974 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CaseWhenEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CaseWhenEval.java
@@ -107,6 +107,7 @@ public class CaseWhenEval extends EvalNode implements GsonObject {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
for (IfThenEval eval : whens) {
if (eval.checkIfCondition(tuple)) {
return eval.eval(tuple);
@@ -233,6 +234,7 @@ public class CaseWhenEval extends EvalNode implements GsonObject {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return result.eval(tuple);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
index 5a26593..f174b79 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
@@ -70,6 +70,7 @@ public class CastEval extends UnaryEval {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
Datum operandDatum = child.eval(tuple);
if (operandDatum.isNull()) {
return operandDatum;
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/ConstEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/ConstEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/ConstEval.java
index 82e4e8e..ff964e6 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/ConstEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/ConstEval.java
@@ -45,6 +45,7 @@ public class ConstEval extends EvalNode implements Comparable<ConstEval>, Clonea
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return datum;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/EvalNode.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/EvalNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/EvalNode.java
index f57302a..154b0fd 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/EvalNode.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/EvalNode.java
@@ -35,6 +35,7 @@ import org.apache.tajo.storage.Tuple;
*/
public abstract class EvalNode implements Cloneable, GsonObject, ProtoObject<PlanProto.EvalNodeTree> {
@Expose protected EvalType type;
+ protected boolean isBinded = false;
public EvalNode() {
}
@@ -60,13 +61,20 @@ public abstract class EvalNode implements Cloneable, GsonObject, ProtoObject<Pla
return PlanGsonHelper.toJson(this, EvalNode.class);
}
- public void bind(Schema schema) {
+ public EvalNode bind(Schema schema) {
for (int i = 0; i < childNum(); i++) {
getChild(i).bind(schema);
}
+ isBinded = true;
+ return this;
}
- public abstract <T extends Datum> T eval(Tuple tuple);
+ public <T extends Datum> T eval(Tuple tuple) {
+ if (!isBinded) {
+ throw new IllegalStateException("bind() must be called before eval()");
+ }
+ return null;
+ }
@Deprecated
public abstract void preOrder(EvalNodeVisitor visitor);
@@ -78,6 +86,7 @@ public abstract class EvalNode implements Cloneable, GsonObject, ProtoObject<Pla
public Object clone() throws CloneNotSupportedException {
EvalNode evalNode = (EvalNode) super.clone();
evalNode.type = type;
+ evalNode.isBinded = isBinded;
return evalNode;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FieldEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FieldEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FieldEval.java
index 11b3b6d..83d00b9 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FieldEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FieldEval.java
@@ -40,7 +40,8 @@ public class FieldEval extends EvalNode implements Cloneable {
}
@Override
- public void bind(Schema schema) {
+ public EvalNode bind(Schema schema) {
+ super.bind(schema);
// TODO - column namespace should be improved to simplify name handling and resolving.
if (column.hasQualifier()) {
fieldId = schema.getColumnId(column.getQualifiedName());
@@ -50,11 +51,13 @@ public class FieldEval extends EvalNode implements Cloneable {
if (fieldId == -1) {
throw new IllegalStateException("No Such Column Reference: " + column + ", schema: " + schema);
}
+ return this;
}
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return tuple.get(fieldId);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FunctionEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FunctionEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FunctionEval.java
index 0c60c8d..4ff7548 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FunctionEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/FunctionEval.java
@@ -33,7 +33,7 @@ import static org.apache.tajo.catalog.proto.CatalogProtos.FunctionType.DISTINCT_
import static org.apache.tajo.catalog.proto.CatalogProtos.FunctionType.DISTINCT_UDA;
public abstract class FunctionEval extends EvalNode implements Cloneable {
- public static enum ParamType {
+ public enum ParamType {
CONSTANT, VARIABLE, NULL
}
@@ -49,9 +49,10 @@ public abstract class FunctionEval extends EvalNode implements Cloneable {
}
@Override
- public void bind(Schema schema) {
+ public EvalNode bind(Schema schema) {
super.bind(schema);
this.params = new VTuple(argEvals.length);
+ return this;
}
protected final Tuple evalParams(Tuple tuple) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/GeneralFunctionEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/GeneralFunctionEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/GeneralFunctionEval.java
index 747e8ba..2ce7850 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/GeneralFunctionEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/GeneralFunctionEval.java
@@ -42,6 +42,7 @@ public class GeneralFunctionEval extends FunctionEval {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return instance.eval(evalParams(tuple));
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/InEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/InEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/InEval.java
index c222bef..c968bda 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/InEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/InEval.java
@@ -58,6 +58,9 @@ public class InEval extends BinaryEval {
@Override
public Datum eval(Tuple tuple) {
+ if (!isBinded) {
+ throw new IllegalStateException("bind() must be called before eval()");
+ }
if (values == null) {
values = Sets.newHashSet(((RowConstantEval)rightExpr).getValues());
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/IsNullEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/IsNullEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/IsNullEval.java
index 496f64d..72b36eb 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/IsNullEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/IsNullEval.java
@@ -58,6 +58,7 @@ public class IsNullEval extends UnaryEval {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
boolean isNull = child.eval(tuple).isNull();
return DatumFactory.createBool(isNot ^ isNull);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/NotEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/NotEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/NotEval.java
index ccec0fe..088f3a5 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/NotEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/NotEval.java
@@ -45,6 +45,7 @@ public class NotEval extends UnaryEval implements Cloneable {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
Datum datum = child.eval(tuple);
return !datum.isNull() ? DatumFactory.createBool(!datum.asBool()) : datum;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/PatternMatchPredicateEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/PatternMatchPredicateEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/PatternMatchPredicateEval.java
index a5d055d..6faa667 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/PatternMatchPredicateEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/PatternMatchPredicateEval.java
@@ -74,13 +74,17 @@ public abstract class PatternMatchPredicateEval extends BinaryEval {
}
@Override
- public void bind(Schema schema) {
+ public EvalNode bind(Schema schema) {
super.bind(schema);
compile(pattern);
+ return this;
}
@Override
public Datum eval(Tuple tuple) {
+ if (!isBinded) {
+ throw new IllegalStateException("bind() must be called before eval()");
+ }
Datum predicand = leftExpr.eval(tuple);
if (predicand.isNull()) {
return NullDatum.get();
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/RowConstantEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/RowConstantEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/RowConstantEval.java
index b81c352..153a150 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/RowConstantEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/RowConstantEval.java
@@ -61,6 +61,7 @@ public class RowConstantEval extends EvalNode {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
return NullDatum.get();
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SignedEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SignedEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SignedEval.java
index 9d077ba..baa78a2 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SignedEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SignedEval.java
@@ -50,6 +50,7 @@ public class SignedEval extends UnaryEval implements Cloneable {
@Override
@SuppressWarnings("unchecked")
public Datum eval(Tuple tuple) {
+ super.eval(tuple);
NumericDatum result = child.eval(tuple);
if (negative) {
return result.inverseSign();
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/UnaryEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/UnaryEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/UnaryEval.java
index 237db00..4db2b90 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/UnaryEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/UnaryEval.java
@@ -67,6 +67,7 @@ public abstract class UnaryEval extends EvalNode implements Cloneable {
@Override
public <T extends Datum> T eval(Tuple tuple) {
+ super.eval(tuple);
return null;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/72948b63/tajo-plan/src/main/java/org/apache/tajo/plan/expr/WindowFunctionEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/WindowFunctionEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/WindowFunctionEval.java
index 33f9a3d..a72d826 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/WindowFunctionEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/WindowFunctionEval.java
@@ -65,6 +65,9 @@ public class WindowFunctionEval extends AggregationFunctionCallEval implements C
@Override
public Datum terminate(FunctionContext context) {
+ if (!isBinded) {
+ throw new IllegalStateException("bind() must be called before terminate()");
+ }
return instance.terminate(context);
}
[02/10] tajo git commit: TAJO-1421: Add 'ALTER TABLE SET PROPERTY'
statement.
Posted by ji...@apache.org.
TAJO-1421: Add 'ALTER TABLE SET PROPERTY' statement.
Closes #450
Signed-off-by: JaeHwa Jung <bl...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/dd433734
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/dd433734
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/dd433734
Branch: refs/heads/index_support
Commit: dd43373418b1857a1f694a08c06da77a86d3cfeb
Parents: b0abff8
Author: Yongjin Choi <su...@gmail.com>
Authored: Sun Apr 5 22:13:25 2015 +0900
Committer: JaeHwa Jung <bl...@apache.org>
Committed: Sun Apr 5 22:13:25 2015 +0900
----------------------------------------------------------------------
CHANGES | 3 +
.../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 | 16 +++++
.../org/apache/tajo/catalog/TestCatalog.java | 19 ++++++
.../org/apache/tajo/engine/parser/SQLLexer.g4 | 1 +
.../org/apache/tajo/engine/parser/SQLParser.g4 | 9 +++
.../apache/tajo/engine/parser/SQLAnalyzer.java | 23 +++++++
.../apache/tajo/master/exec/DDLExecutor.java | 3 +
.../java/org/apache/tajo/QueryTestCaseBase.java | 5 ++
.../tajo/engine/parser/TestSQLAnalyzer.java | 39 +++++++++++
.../tajo/engine/query/TestAlterTable.java | 16 ++++-
.../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 +
.../org/apache/tajo/plan/LogicalPlanner.java | 1 +
.../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 +
34 files changed, 313 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 3def16c..e8a2c1f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@ Release 0.11.0 - unreleased
IMPROVEMENT
+ TAJO-1421: Add 'ALTER TABLE SET PROPERTY' statement.
+ (Contributed by Yongjin Choi. Committed by jaehwa)
+
TAJO-1501: Too many log message of HashShuffleAppenderManager.
(Contributed by Jongyoung Park. Committed by jaehwa)
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
index dc68fc1..3ca9a7b 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
@@ -24,6 +24,9 @@ import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import org.apache.tajo.util.TUtil;
+import java.util.HashMap;
+import java.util.Map;
+
public class AlterTable extends Expr {
@Expose @SerializedName("OldTableName")
@@ -38,6 +41,8 @@ public class AlterTable extends Expr {
private ColumnDefinition addNewColumn;
@Expose @SerializedName("AlterTableType")
private AlterTableOpType alterTableOpType;
+ @Expose @SerializedName("TableProperties")
+ private Map<String, String> params;
@Expose @SerializedName("Columns")
ColumnReferenceExpr [] columns;
@@ -112,6 +117,18 @@ public class AlterTable extends Expr {
public void setLocation(String location) { this.location = location; }
+ public boolean hasParams() {
+ return params != null;
+ }
+
+ public Map<String, String> getParams() {
+ return params;
+ }
+
+ public void setParams(Map<String, String> params) {
+ this.params = params;
+ }
+
@Override
public int hashCode() {
return Objects.hashCode(tableName,
@@ -122,7 +139,8 @@ public class AlterTable extends Expr {
null != alterTableOpType ? Objects.hashCode(alterTableOpType) : alterTableOpType,
null != columns ? Objects.hashCode(columns) : columns,
null != values ? Objects.hashCode(values) : values,
- null != location ? Objects.hashCode(location) : location
+ null != location ? Objects.hashCode(location) : location,
+ null != params ? Objects.hashCode(params) : params
);
}
@@ -138,7 +156,8 @@ public class AlterTable extends Expr {
TUtil.checkEquals(alterTableOpType, another.alterTableOpType) &&
TUtil.checkEquals(columns, another.columns) &&
TUtil.checkEquals(values, another.values) &&
- TUtil.checkEquals(location, another.location)
+ TUtil.checkEquals(location, another.location) &&
+ TUtil.checkEquals(params, another.params)
;
}
@@ -154,6 +173,7 @@ public class AlterTable extends Expr {
alter.columns = columns;
alter.values = values;
alter.location = location;
+ alter.params = new HashMap<String, String>(params);
return alter;
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java
index 5d4f381..679ab4b 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java
@@ -18,5 +18,5 @@
package org.apache.tajo.algebra;
public enum AlterTableOpType {
- RENAME_TABLE, RENAME_COLUMN, ADD_COLUMN, ADD_PARTITION, DROP_PARTITION
+ RENAME_TABLE, RENAME_COLUMN, ADD_COLUMN, ADD_PARTITION, DROP_PARTITION, SET_PROPERTY
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
index f1265fb..9133b6f 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
@@ -25,6 +25,7 @@ import org.apache.tajo.catalog.partition.PartitionDesc;
import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.common.ProtoObject;
import org.apache.tajo.json.GsonObject;
+import org.apache.tajo.util.KeyValueSet;
import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTableDescProto;
@@ -44,10 +45,16 @@ public class AlterTableDesc implements ProtoObject<AlterTableDescProto>, GsonObj
protected Column addColumn = null; //optional
@Expose
protected PartitionDesc partitionDesc; //optional
+ @Expose
+ protected KeyValueSet properties;
public AlterTableDesc() {
+ init();
}
+ private void init() {
+ this.properties = new KeyValueSet();
+ }
public String getTableName() {
return tableName;
@@ -101,6 +108,22 @@ public class AlterTableDesc implements ProtoObject<AlterTableDescProto>, GsonObj
public void setPartitionDesc(PartitionDesc partitionDesc) { this.partitionDesc = partitionDesc; }
+ public void setProperties(KeyValueSet properties) {
+ this.properties = properties;
+ }
+
+ public KeyValueSet getProperties() {
+ return properties;
+ }
+
+ public void setProperty(String key, String value) {
+ this.properties.set(key, value);
+ }
+
+ public String getProperty(String key) {
+ return this.properties.get(key);
+ }
+
@Override
public String toString() {
Gson gson = new GsonBuilder().setPrettyPrinting().
@@ -117,6 +140,7 @@ public class AlterTableDesc implements ProtoObject<AlterTableDescProto>, GsonObj
newAlter.columnName = newColumnName;
newAlter.addColumn = addColumn;
newAlter.partitionDesc = partitionDesc;
+ newAlter.properties = (KeyValueSet)properties.clone();
return newAlter;
}
@@ -144,6 +168,9 @@ public class AlterTableDesc implements ProtoObject<AlterTableDescProto>, GsonObj
if (null != this.addColumn) {
builder.setAddColumn(addColumn.getProto());
}
+ if (null != this.properties) {
+ builder.setParams(properties.getProto());
+ }
switch (alterTableType) {
case RENAME_TABLE:
@@ -155,6 +182,9 @@ public class AlterTableDesc implements ProtoObject<AlterTableDescProto>, GsonObj
case ADD_COLUMN:
builder.setAlterTableType(CatalogProtos.AlterTableType.ADD_COLUMN);
break;
+ case SET_PROPERTY:
+ builder.setAlterTableType(CatalogProtos.AlterTableType.SET_PROPERTY);
+ break;
case ADD_PARTITION:
builder.setAlterTableType(CatalogProtos.AlterTableType.ADD_PARTITION);
break;
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java
index 7e3be91..a562d9f 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java
@@ -18,5 +18,5 @@
package org.apache.tajo.catalog;
public enum AlterTableType {
- RENAME_TABLE, RENAME_COLUMN, ADD_COLUMN, ADD_PARTITION, DROP_PARTITION
+ RENAME_TABLE, RENAME_COLUMN, ADD_COLUMN, ADD_PARTITION, DROP_PARTITION, SET_PROPERTY
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
index afcff2d..628d710 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
@@ -764,6 +764,14 @@ public class CatalogUtil {
return alterTableDesc;
}
+ public static AlterTableDesc setProperty(String tableName, KeyValueSet params, AlterTableType alterTableType) {
+ final AlterTableDesc alterTableDesc = new AlterTableDesc();
+ alterTableDesc.setTableName(tableName);
+ alterTableDesc.setProperties(params);
+ alterTableDesc.setAlterTableType(alterTableType);
+ return alterTableDesc;
+ }
+
/* It is the relationship graph of type conversions. */
public static final Map<Type, Map<Type, Type>> OPERATION_CASTING_MAP = Maps.newHashMap();
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto b/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
index 3abd840..1402bbc 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
+++ b/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
@@ -60,6 +60,7 @@ enum AlterTableType {
ADD_COLUMN = 2;
ADD_PARTITION = 3;
DROP_PARTITION = 4;
+ SET_PROPERTY = 5;
}
message ColumnProto {
@@ -357,6 +358,7 @@ message AlterTableDescProto {
optional AlterColumnProto alterColumnName = 4;
required AlterTableType alterTableType = 5;
optional PartitionDescProto partitionDesc = 6;
+ optional KeyValueSetProto params = 7;
}
message AlterColumnProto {
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java b/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
index 2761517..e829b94 100644
--- a/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
+++ b/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
@@ -646,6 +646,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
}
dropPartition(databaseName, tableName, partitionDesc);
break;
+ case SET_PROPERTY:
+ // TODO - not implemented yet
+ break;
default:
//TODO
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
index 518b499..1773033 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
@@ -1015,6 +1015,9 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
dropPartition(tableId, alterTableDescProto.getPartitionDesc().getPartitionName());
break;
+ case SET_PROPERTY:
+ setProperties(tableId, alterTableDescProto.getParams());
+ break;
default:
}
} catch (SQLException sqlException) {
@@ -1023,6 +1026,75 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
+ private Map<String, String> getTableOptions(final int tableId) throws CatalogException {
+ Connection conn = null;
+ PreparedStatement pstmt = null;
+ ResultSet res = null;
+ Map<String, String> options = TUtil.newHashMap();
+
+ try {
+ String tidSql = "SELECT key_, value_ FROM " + TB_OPTIONS + " WHERE TID=?";
+
+ conn = getConnection();
+ pstmt = conn.prepareStatement(tidSql);
+ pstmt.setInt(1, tableId);
+ res = pstmt.executeQuery();
+
+ while (res.next()) {
+ options.put(res.getString("KEY_"), res.getString("VALUE_"));
+ }
+ } catch (SQLException se) {
+ throw new CatalogException(se);
+ } finally {
+ CatalogUtil.closeQuietly(pstmt, res);
+ }
+
+ return options;
+ }
+
+ private void setProperties(final int tableId, final KeyValueSetProto properties) {
+ final String updateSql = "UPDATE " + TB_OPTIONS + " SET VALUE_=? WHERE TID=? AND KEY_=?";
+ final String insertSql = "INSERT INTO " + TB_OPTIONS + " (TID, KEY_, VALUE_) VALUES(?, ?, ?)";
+
+ Connection conn;
+ PreparedStatement pstmt = null;
+
+ Map<String, String> oldProperties = getTableOptions(tableId);
+
+ try {
+ conn = getConnection();
+ conn.setAutoCommit(false);
+
+ for (KeyValueProto entry : properties.getKeyvalList()) {
+ if (oldProperties.containsKey(entry.getKey())) {
+ // replace old property with new one
+ pstmt = conn.prepareStatement(updateSql);
+
+ pstmt.setString(1, entry.getValue());
+ pstmt.setInt(2, tableId);
+ pstmt.setString(3, entry.getKey());
+ pstmt.executeUpdate();
+ pstmt.close();
+ } else {
+ // insert new property
+ pstmt = conn.prepareStatement(insertSql);
+
+ pstmt.setInt(1, tableId);
+ pstmt.setString(2, entry.getKey());
+ pstmt.setString(3, entry.getValue());
+ pstmt.executeUpdate();
+ pstmt.close();
+ }
+ }
+
+ conn.commit();
+ } catch (SQLException sqlException) {
+ throw new CatalogException(sqlException);
+ } finally {
+ CatalogUtil.closeQuietly(pstmt);
+ }
+ }
+
private void renameTable(final int tableId, final String tableName) throws CatalogException {
final String updtaeRenameTableSql = "UPDATE " + TB_TABLES + " SET " + COL_TABLES_NAME + " = ? " + " WHERE TID = ?";
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
index 470f09d..b058504 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
@@ -28,6 +28,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.tajo.TajoConstants;
import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.FunctionDesc;
+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;
@@ -41,6 +42,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.TableOptionProto;
import org.apache.tajo.catalog.proto.CatalogProtos.TablePartitionProto;
import org.apache.tajo.catalog.proto.CatalogProtos.TableStatsProto;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto;
+import org.apache.tajo.util.KeyValueSet;
import org.apache.tajo.util.TUtil;
import java.io.IOException;
@@ -350,6 +352,20 @@ public class MemStore implements CatalogStore {
partitions.remove(partitionName);
}
break;
+ case SET_PROPERTY:
+ KeyValueSet properties = new KeyValueSet(tableDescProto.getMeta().getParams());
+ KeyValueSet newProperties = new KeyValueSet(alterTableDescProto.getParams());
+
+ for (String key : newProperties.getAllKeyValus().keySet()) {
+ if (properties.containsKey(key))
+ properties.remove(key);
+ properties.set(key, newProperties.get(key));
+ }
+
+ TableMeta newMeta = new TableMeta(tableDescProto.getMeta().getStoreType(), properties);
+ newTableDescProto = tableDescProto.toBuilder().setMeta(newMeta.getProto()).build();
+ database.put(tableName, newTableDescProto);
+ break;
default:
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
index 48a11ee..cef4027 100644
--- a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
+++ b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
@@ -995,6 +995,17 @@ public class TestCatalog {
TableDesc addColumnDesc = catalog.getTableDesc("default","mynewcooltable");
assertTrue(addColumnDesc.getSchema().containsByName("mynewcol"));
+ //SET_PROPERTY
+ TableDesc setPropertyDesc = catalog.getTableDesc("default","mynewcooltable");
+ KeyValueSet options = new KeyValueSet();
+ options.set("timezone", "GMT+9"); // Seoul, Korea
+ setPropertyDesc.setMeta(new TableMeta(StoreType.CSV, options));
+ String prevTimeZone = setPropertyDesc.getMeta().getOption("timezone");
+ String newTimeZone = "GMT-7"; // Silicon Valley, California
+ catalog.alterTable(createMockAlterTableSetProperty(newTimeZone));
+ setPropertyDesc = catalog.getTableDesc("default","mynewcooltable");
+ assertNotEquals(prevTimeZone, setPropertyDesc.getMeta().getOption("timezone"));
+ assertEquals(newTimeZone, setPropertyDesc.getMeta().getOption("timezone"));
}
private AlterTableDesc createMockAlterTableName(){
@@ -1022,6 +1033,14 @@ public class TestCatalog {
return alterTableDesc;
}
+ private AlterTableDesc createMockAlterTableSetProperty(String newTimeZone) {
+ AlterTableDesc alterTableDesc = new AlterTableDesc();
+ alterTableDesc.setTableName("default.mynewcooltable");
+ alterTableDesc.setProperty("timezone", newTimeZone);
+ alterTableDesc.setAlterTableType(AlterTableType.SET_PROPERTY);
+ return alterTableDesc;
+ }
+
public static class TestIntFunc extends Function {
public TestIntFunc() {
super(
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4 b/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
index 6fccaad..d1daeb6 100644
--- a/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
+++ b/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
@@ -280,6 +280,7 @@ PERCENT_RANK : P E R C E N T UNDERLINE R A N K;
PRECEDING : P R E C E D I N G;
PRECISION : P R E C I S I O N;
PURGE : P U R G E;
+PROPERTY : P R O P E R T Y;
QUARTER : Q U A R T E R;
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4 b/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
index 9ac3f8c..1a63470 100644
--- a/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
+++ b/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
@@ -1604,6 +1604,7 @@ alter_table_statement
| ALTER TABLE table_name ADD COLUMN field_element
| ALTER TABLE table_name (if_not_exists)? ADD PARTITION LEFT_PAREN partition_column_value_list RIGHT_PAREN (LOCATION path=Character_String_Literal)?
| ALTER TABLE table_name (if_exists)? DROP PARTITION LEFT_PAREN partition_column_value_list RIGHT_PAREN
+ | ALTER TABLE table_name SET PROPERTY property_list
;
partition_column_value_list
@@ -1613,3 +1614,11 @@ partition_column_value_list
partition_column_value
: identifier EQUAL row_value_predicand
;
+
+property_list
+ : property (COMMA property)*
+ ;
+
+property
+ : key=Character_String_Literal EQUAL value=Character_String_Literal
+ ;
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
index 23c2eec..673b22f 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
@@ -1831,11 +1831,24 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
}
}
+ if (checkIfExist(ctx.property_list())) {
+ alterTable.setParams(getProperties(ctx.property_list()));
+ }
+
alterTable.setAlterTableOpType(determineAlterTableType(ctx));
return alterTable;
}
+ private Map<String, String> getProperties(SQLParser.Property_listContext ctx) {
+ Map<String, String> params = new HashMap<String, String>();
+ for (int i = 0; i < ctx.property().size(); i++) {
+ params.put(stripQuote(ctx.property(i).key.getText()), stripQuote(ctx.property(i).value.getText()));
+ }
+
+ return params;
+ }
+
private AlterTableOpType determineAlterTableType(SQLParser.Alter_table_statementContext ctx) {
final int RENAME_MASK = 00000001;
@@ -1844,6 +1857,8 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
final int ADD_MASK = 00001000;
final int DROP_MASK = 00001001;
final int PARTITION_MASK = 00000020;
+ final int SET_MASK = 00000002;
+ final int PROPERTY_MASK = 00010000;
int val = 00000000;
@@ -1869,6 +1884,12 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
case PARTITION:
val = val | PARTITION_MASK;
break;
+ case SET:
+ val = val | SET_MASK;
+ break;
+ case PROPERTY:
+ val = val | PROPERTY_MASK;
+ break;
default:
break;
}
@@ -1890,6 +1911,8 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
return AlterTableOpType.ADD_PARTITION;
case 529:
return AlterTableOpType.DROP_PARTITION;
+ case 4098:
+ return AlterTableOpType.SET_PROPERTY;
default:
return null;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
----------------------------------------------------------------------
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 2030b55..9264c68 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
@@ -421,6 +421,9 @@ public class DDLExecutor {
}
catalog.alterTable(CatalogUtil.addNewColumn(qualifiedName, alterTable.getAddNewColumn(), AlterTableType.ADD_COLUMN));
break;
+ case SET_PROPERTY:
+ catalog.alterTable(CatalogUtil.setProperty(qualifiedName, alterTable.getProperties(), AlterTableType.SET_PROPERTY));
+ break;
default:
//TODO
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
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 4e104dd..727192a 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -546,6 +546,11 @@ public class QueryTestCaseBase {
return client.getTableDesc(tableName);
}
+ public void assertTablePropertyEquals(String tableName, String key, String expectedValue) throws ServiceException {
+ TableDesc tableDesc = fetchTableMetaData(tableName);
+ assertEquals(expectedValue, tableDesc.getMeta().getOption(key));
+ }
+
/**
* It transforms a ResultSet instance to rows represented as strings.
*
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java b/tajo-core/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
index d223554..f698ed5 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
@@ -485,6 +485,45 @@ public class TestSQLAnalyzer {
}
@Test
+ public void testAlterTableSetProperty1() throws IOException {
+ String sql = FileUtil.readTextFileFromResource("queries/default/alter_table_set_property_1.sql");
+ Expr expr = parseQuery(sql);
+ assertEquals(OpType.AlterTable, expr.getType());
+ AlterTable alterTable = (AlterTable)expr;
+ assertEquals(alterTable.getAlterTableOpType(), AlterTableOpType.SET_PROPERTY);
+ assertTrue(alterTable.hasParams());
+ assertTrue(alterTable.getParams().containsKey("timezone"));
+ assertEquals("GMT-7", alterTable.getParams().get("timezone"));
+ }
+
+ @Test
+ public void testAlterTableSetProperty2() throws IOException {
+ String sql = FileUtil.readTextFileFromResource("queries/default/alter_table_set_property_2.sql");
+ Expr expr = parseQuery(sql);
+ assertEquals(OpType.AlterTable, expr.getType());
+ AlterTable alterTable = (AlterTable)expr;
+ assertEquals(alterTable.getAlterTableOpType(), AlterTableOpType.SET_PROPERTY);
+ assertTrue(alterTable.hasParams());
+ assertTrue(alterTable.getParams().containsKey("text.delimiter"));
+ assertEquals("&", alterTable.getParams().get("text.delimiter"));
+ }
+
+ @Test
+ public void testAlterTableSetProperty3() throws IOException {
+ // update multiple table properties with a single 'SET PROPERTY' sql
+ String sql = FileUtil.readTextFileFromResource("queries/default/alter_table_set_property_3.sql");
+ Expr expr = parseQuery(sql);
+ assertEquals(OpType.AlterTable, expr.getType());
+ AlterTable alterTable = (AlterTable)expr;
+ assertEquals(alterTable.getAlterTableOpType(), AlterTableOpType.SET_PROPERTY);
+ assertTrue(alterTable.hasParams());
+ assertTrue(alterTable.getParams().containsKey("compression.type"));
+ assertEquals("RECORD", alterTable.getParams().get("compression.type"));
+ assertTrue(alterTable.getParams().containsKey("compression.codec"));
+ assertEquals("org.apache.hadoop.io.compress.SnappyCodec", alterTable.getParams().get("compression.codec"));
+ }
+
+ @Test
public void testTableSubQuery1() throws IOException {
String sql = FileUtil.readTextFileFromResource("queries/default/table_subquery1.sql");
parseQuery(sql);
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
index 57d8b32..44fa1f3 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
@@ -23,6 +23,7 @@ import org.apache.tajo.QueryTestCaseBase;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import java.sql.ResultSet;
import java.util.List;
@Category(IntegrationTest.class)
@@ -39,7 +40,7 @@ public class TestAlterTable extends QueryTestCaseBase {
public final void testAlterTableColumnName() throws Exception {
List<String> createdNames = executeDDL("table1_ddl.sql", "table1.tbl", "XYZ");
executeDDL("alter_table_rename_column_ddl.sql", null);
- assertColumnExists(createdNames.get(0),"renum");
+ assertColumnExists(createdNames.get(0), "renum");
}
@Test
@@ -49,4 +50,17 @@ public class TestAlterTable extends QueryTestCaseBase {
assertColumnExists(createdNames.get(0),"cool");
}
+ @Test
+ public final void testAlterTableSetProperty() throws Exception {
+ executeDDL("table2_ddl.sql", "table2.tbl", "ALTX");
+ ResultSet before_res = executeQuery();
+ assertResultSet(before_res, "before_set_property_delimiter.result");
+ cleanupQuery(before_res);
+
+ executeDDL("alter_table_set_property_delimiter.sql", null);
+
+ ResultSet after_res = executeQuery();
+ assertResultSet(after_res, "after_set_property_delimiter.result");
+ cleanupQuery(after_res);
+ }
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/dataset/TestAlterTable/table2.tbl
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/dataset/TestAlterTable/table2.tbl b/tajo-core/src/test/resources/dataset/TestAlterTable/table2.tbl
new file mode 100644
index 0000000..59f652e
--- /dev/null
+++ b/tajo-core/src/test/resources/dataset/TestAlterTable/table2.tbl
@@ -0,0 +1 @@
+aaa+AAA|bbb+BBB|ccc
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_delimiter.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_delimiter.sql b/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_delimiter.sql
new file mode 100644
index 0000000..031e700
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_delimiter.sql
@@ -0,0 +1 @@
+ALTER TABLE ALTX SET PROPERTY 'text.delimiter'='|';
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_timezone.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_timezone.sql b/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_timezone.sql
new file mode 100644
index 0000000..24b237e
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestAlterTable/alter_table_set_property_timezone.sql
@@ -0,0 +1 @@
+ALTER TABLE ALTY SET PROPERTY 'timezone'='GMT-7';
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/TestAlterTable/table2_ddl.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestAlterTable/table2_ddl.sql b/tajo-core/src/test/resources/queries/TestAlterTable/table2_ddl.sql
new file mode 100644
index 0000000..ae563e7
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestAlterTable/table2_ddl.sql
@@ -0,0 +1 @@
+CREATE EXTERNAL TABLE ${0} (xx text, yy text, zz text) USING CSV WITH('text.delimiter'='+') LOCATION ${table.path};
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty.sql b/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty.sql
new file mode 100644
index 0000000..dd0bd83
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty.sql
@@ -0,0 +1 @@
+select * from ALTX;
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty2.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty2.sql b/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty2.sql
new file mode 100644
index 0000000..2e854aa
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestAlterTable/testAlterTableSetProperty2.sql
@@ -0,0 +1 @@
+select * from ALTY;
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/default/alter_table_set_property_1.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/default/alter_table_set_property_1.sql b/tajo-core/src/test/resources/queries/default/alter_table_set_property_1.sql
new file mode 100644
index 0000000..ac7aa4d
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/default/alter_table_set_property_1.sql
@@ -0,0 +1 @@
+ALTER TABLE table1 SET PROPERTY 'timezone' = 'GMT-7'
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/default/alter_table_set_property_2.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/default/alter_table_set_property_2.sql b/tajo-core/src/test/resources/queries/default/alter_table_set_property_2.sql
new file mode 100644
index 0000000..77df213
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/default/alter_table_set_property_2.sql
@@ -0,0 +1 @@
+ALTER TABLE table1 SET PROPERTY 'text.delimiter' = '&'
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/queries/default/alter_table_set_property_3.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/default/alter_table_set_property_3.sql b/tajo-core/src/test/resources/queries/default/alter_table_set_property_3.sql
new file mode 100644
index 0000000..6230a34
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/default/alter_table_set_property_3.sql
@@ -0,0 +1 @@
+ALTER TABLE table1 SET PROPERTY 'compression.type'='RECORD','compression.codec'='org.apache.hadoop.io.compress.SnappyCodec'
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/results/TestAlterTable/after_set_property_delimiter.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestAlterTable/after_set_property_delimiter.result b/tajo-core/src/test/resources/results/TestAlterTable/after_set_property_delimiter.result
new file mode 100644
index 0000000..6729298
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestAlterTable/after_set_property_delimiter.result
@@ -0,0 +1,3 @@
+xx,yy,zz
+-------------------------------
+aaa+AAA,bbb+BBB,ccc
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-core/src/test/resources/results/TestAlterTable/before_set_property_delimiter.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestAlterTable/before_set_property_delimiter.result b/tajo-core/src/test/resources/results/TestAlterTable/before_set_property_delimiter.result
new file mode 100644
index 0000000..af74e40
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestAlterTable/before_set_property_delimiter.result
@@ -0,0 +1,3 @@
+xx,yy,zz
+-------------------------------
+aaa,AAA|bbb,BBB|ccc
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
index 7edf74a..d6a04a6 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
@@ -1928,6 +1928,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
alterTableNode.setNewTableName(alterTable.getNewTableName());
alterTableNode.setColumnName(alterTable.getColumnName());
alterTableNode.setNewColumnName(alterTable.getNewColumnName());
+ alterTableNode.setProperties(new KeyValueSet(alterTable.getParams()));
if (null != alterTable.getAddNewColumn()) {
alterTableNode.setAddNewColumn(convertColumn(alterTable.getAddNewColumn()));
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-plan/src/main/java/org/apache/tajo/plan/logical/AlterTableNode.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/AlterTableNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/AlterTableNode.java
index 69cff54..9cbde0c 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/AlterTableNode.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/AlterTableNode.java
@@ -24,6 +24,7 @@ import com.google.gson.annotations.Expose;
import org.apache.tajo.algebra.AlterTableOpType;
import org.apache.tajo.catalog.Column;
import org.apache.tajo.plan.PlanString;
+import org.apache.tajo.util.KeyValueSet;
public class AlterTableNode extends LogicalNode {
@@ -38,6 +39,8 @@ public class AlterTableNode extends LogicalNode {
@Expose
private Column addNewColumn;
@Expose
+ private KeyValueSet properties = new KeyValueSet();
+ @Expose
private AlterTableOpType alterTableOpType;
public AlterTableNode(int pid) {
@@ -102,6 +105,18 @@ public class AlterTableNode extends LogicalNode {
this.alterTableOpType = alterTableOpType;
}
+ public boolean hasProperties() {
+ return this.properties != null;
+ }
+
+ public KeyValueSet getProperties() {
+ return this.properties;
+ }
+
+ public void setProperties(KeyValueSet properties) {
+ this.properties = properties;
+ }
+
@Override
public PlanString getPlanString() {
return new PlanString(this);
@@ -117,6 +132,7 @@ public class AlterTableNode extends LogicalNode {
result = prime * result + ((newColumnName == null) ? 0 : newColumnName.hashCode());
result = prime * result + ((newTableName == null) ? 0 : newTableName.hashCode());
result = prime * result + ((tableName == null) ? 0 : tableName.hashCode());
+ result = prime * result + ((properties == null) ? 0 : properties.hashCode());
return result;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
index 3387157..f96626b 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
@@ -583,6 +583,9 @@ public class LogicalNodeDeserializer {
alterTable.setColumnName(alterTableProto.getRenameColumn().getOldName());
alterTable.setNewColumnName(alterTableProto.getRenameColumn().getNewName());
break;
+ case SET_PROPERTY:
+ alterTable.setProperties(new KeyValueSet(alterTableProto.getProperties()));
+ break;
default:
throw new UnimplementedException("Unknown SET type in ALTER TABLE: " + alterTableProto.getSetType().name());
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
index 1bde955..60171de 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
@@ -567,6 +567,10 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
.setOldName(node.getColumnName())
.setNewName(node.getNewColumnName()));
break;
+ case SET_PROPERTY:
+ alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.SET_PROPERTY);
+ alterTableBuilder.setProperties(node.getProperties().getProto());
+ break;
default:
throw new UnimplementedException("Unknown SET type in ALTER TABLE: " + node.getAlterTableOpType().name());
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/dd433734/tajo-plan/src/main/proto/Plan.proto
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/proto/Plan.proto b/tajo-plan/src/main/proto/Plan.proto
index 02f52ff..c555a1a 100644
--- a/tajo-plan/src/main/proto/Plan.proto
+++ b/tajo-plan/src/main/proto/Plan.proto
@@ -280,6 +280,7 @@ message AlterTableNode {
RENAME_TABLE = 0;
RENAME_COLUMN = 1;
ADD_COLUMN = 2;
+ SET_PROPERTY = 3;
}
message RenameTable {
@@ -300,6 +301,7 @@ message AlterTableNode {
optional RenameTable renameTable = 3;
optional RenameColumn renameColumn = 4;
optional AddColumn addColumn = 5;
+ optional KeyValueSetProto properties = 6;
}
enum EvalType {
[06/10] tajo git commit: TAJO-1338: Defines RESTful API for Clients
Posted by ji...@apache.org.
TAJO-1338: Defines RESTful API for Clients
Closes #490
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/32b524d7
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/32b524d7
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/32b524d7
Branch: refs/heads/index_support
Commit: 32b524d74f5e4a6a37a4b99c43830f8401fc9e45
Parents: 696d2aa
Author: Jihun Kang <ji...@apache.org>
Authored: Mon Apr 6 11:48:46 2015 +0900
Committer: Jihun Kang <ji...@apache.org>
Committed: Mon Apr 6 11:48:46 2015 +0900
----------------------------------------------------------------------
CHANGES | 2 +
.../java/org/apache/tajo/catalog/TableDesc.java | 1 +
.../java/org/apache/tajo/conf/TajoConf.java | 3 +
tajo-core/pom.xml | 8 +
.../java/org/apache/tajo/master/TajoMaster.java | 17 +
.../exec/NonForwardQueryResultFileScanner.java | 5 +
.../exec/NonForwardQueryResultScanner.java | 2 +
.../NonForwardQueryResultSystemScanner.java | 5 +
.../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 | 448 +++++++++++++++++++
.../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 ++++
.../org/apache/tajo/TajoTestingCluster.java | 5 +
.../apache/tajo/ha/TestHAServiceHDFSImpl.java | 2 +
.../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 ++++++++
tajo-project/pom.xml | 5 +
tajo-rpc/tajo-ws-rs/pom.xml | 4 +
.../apache/tajo/ws/rs/ResourceConfigUtil.java | 38 ++
.../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 +-
50 files changed, 4807 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 4ec678f..efadea8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -155,6 +155,8 @@ Release 0.11.0 - unreleased
SUB TASKS
+ TAJO-1338: Defines RESTful API for Clients. (jihun)
+
TAJO-1284: Add alter partition method to CatalogStore. (jaehwa)
TAJO-1392: Resolve findbug warnings on Tajo Plan Module. (jihun)
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
index ec679f9..ee096a2 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/TableDesc.java
@@ -22,6 +22,7 @@ import com.google.common.base.Objects;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tajo.catalog.json.CatalogGsonHelper;
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
index 221b341..e892dc9 100644
--- a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
+++ b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
@@ -135,6 +135,9 @@ public class TajoConf extends Configuration {
Validators.networkAddr()),
TAJO_MASTER_INFO_ADDRESS("tajo.master.info-http.address", "0.0.0.0:26080", Validators.networkAddr()),
+ // Tajo Rest Service
+ REST_SERVICE_PORT("tajo.rest.service.port", 26880),
+
// High availability configurations
TAJO_MASTER_HA_ENABLE("tajo.master.ha.enable", false, Validators.bool()),
TAJO_MASTER_HA_MONITOR_INTERVAL("tajo.master.ha.monitor.interval", 5 * 1000), // 5 sec
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-core/pom.xml b/tajo-core/pom.xml
index 61a156b..19c9ba3 100644
--- a/tajo-core/pom.xml
+++ b/tajo-core/pom.xml
@@ -283,6 +283,10 @@
<groupId>org.apache.tajo</groupId>
<artifactId>tajo-thirdparty-asm</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.tajo</groupId>
+ <artifactId>tajo-ws-rs</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
@@ -368,6 +372,10 @@
<artifactId>antlr4</artifactId>
</dependency>
<dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
----------------------------------------------------------------------
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 371dfb4..51f82f8 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
@@ -59,6 +59,7 @@ import org.apache.tajo.util.history.HistoryWriter;
import org.apache.tajo.util.metrics.TajoSystemMetrics;
import org.apache.tajo.webapp.QueryExecutorServlet;
import org.apache.tajo.webapp.StaticHttpServer;
+import org.apache.tajo.ws.rs.TajoRestService;
import java.io.*;
import java.lang.management.ManagementFactory;
@@ -119,6 +120,7 @@ public class TajoMaster extends CompositeService {
private WorkerResourceManager resourceManager;
//Web Server
private StaticHttpServer webServer;
+ private TajoRestService restServer;
private QueryManager queryManager;
@@ -193,6 +195,9 @@ public class TajoMaster extends CompositeService {
tajoMasterService = new QueryCoordinatorService(context);
addIfService(tajoMasterService);
+
+ restServer = new TajoRestService(context);
+ addIfService(restServer);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw e;
@@ -375,6 +380,14 @@ public class TajoMaster extends CompositeService {
LOG.error(e, e);
}
}
+
+ if (restServer != null) {
+ try {
+ restServer.stop();
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ }
+ }
if (webServer != null) {
try {
@@ -474,6 +487,10 @@ public class TajoMaster extends CompositeService {
public HistoryReader getHistoryReader() {
return historyReader;
}
+
+ public TajoRestService getRestServer() {
+ return restServer;
+ }
}
String getThreadTaskName(long id, String name) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultFileScanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultFileScanner.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultFileScanner.java
index 6c02aa9..804821b 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultFileScanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultFileScanner.java
@@ -143,6 +143,11 @@ public class NonForwardQueryResultFileScanner implements NonForwardQueryResultSc
return tableDesc;
}
+ @Override
+ public int getCurrentRowNumber() {
+ return currentNumRows;
+ }
+
public void close() throws Exception {
if (scanExec != null) {
scanExec.close();
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultScanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultScanner.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultScanner.java
index 86d2843..75608df 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultScanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultScanner.java
@@ -43,4 +43,6 @@ public interface NonForwardQueryResultScanner {
public void init() throws IOException;
+ public int getCurrentRowNumber();
+
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
index 80bdb86..958c252 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
@@ -620,6 +620,11 @@ public class NonForwardQueryResultSystemScanner implements NonForwardQueryResult
public Schema getLogicalSchema() {
return outSchema;
}
+
+ @Override
+ public int getCurrentRowNumber() {
+ return currentRow;
+ }
class SimplePhysicalPlannerImpl extends PhysicalPlannerImpl {
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/ClientApplication.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/ClientApplication.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/ClientApplication.java
new file mode 100644
index 0000000..943f356
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/ClientApplication.java
@@ -0,0 +1,179 @@
+/**
+ * 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;
+
+import org.apache.tajo.QueryId;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+import org.apache.tajo.master.exec.NonForwardQueryResultScanner;
+import org.apache.tajo.ws.rs.resources.ClusterResource;
+import org.apache.tajo.ws.rs.resources.DatabasesResource;
+import org.apache.tajo.ws.rs.resources.FunctionsResource;
+import org.apache.tajo.ws.rs.resources.QueryResource;
+import org.apache.tajo.ws.rs.resources.SessionsResource;
+import org.apache.tajo.ws.rs.resources.TablesResource;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+import javax.ws.rs.core.Application;
+
+import java.security.SecureRandom;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * It loads client classes for Tajo REST protocol.
+ */
+public class ClientApplication extends Application {
+
+ private final MasterContext masterContext;
+ private final ConcurrentMap<QueryId, Long> queryIdToResultSetCacheIdMap;
+ private final Cache<Long, NonForwardQueryResultScanner> queryResultScannerCache;
+
+ private final SecureRandom secureRandom;
+
+ public ClientApplication(MasterContext masterContext) {
+ this.masterContext = masterContext;
+
+ this.secureRandom = new SecureRandom();
+
+ this.queryIdToResultSetCacheIdMap = new ConcurrentHashMap<QueryId, Long>();
+ this.queryResultScannerCache = CacheBuilder.newBuilder()
+ .concurrencyLevel(4)
+ .maximumSize(1000)
+ .expireAfterAccess(30, TimeUnit.MINUTES)
+ .build();
+ }
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+
+ classes.add(SessionsResource.class);
+ classes.add(DatabasesResource.class);
+ classes.add(TablesResource.class);
+ classes.add(FunctionsResource.class);
+ classes.add(ClusterResource.class);
+ classes.add(QueryResource.class);
+
+ return classes;
+ }
+
+ public MasterContext getMasterContext() {
+ return masterContext;
+ }
+
+ /**
+ * It returns generated 8-byte size integer.
+ *
+ * @return
+ */
+ private long generateCacheId() {
+ byte[] generatedBytes = new byte[8];
+ long generatedId = 0;
+
+ secureRandom.nextBytes(generatedBytes);
+ for (byte generatedByte: generatedBytes) {
+ generatedId = (generatedId << 8) + (generatedByte & 0xff);
+ }
+
+ return generatedId;
+ }
+
+ /**
+ * If cannot find any cache id for supplied query id, it will generate a new cache id.
+ *
+ * @param queryId
+ * @return
+ */
+ public long generateCacheIdIfAbsent(QueryId queryId) {
+ Long cacheId = this.queryIdToResultSetCacheIdMap.get(queryId);
+ long newCacheId = 0;
+
+ if (cacheId == null) {
+ boolean generated = false;
+ do {
+ newCacheId = generateCacheId();
+ if (queryResultScannerCache.getIfPresent(newCacheId) == null) {
+ generated = true;
+ }
+ } while (!generated);
+ cacheId = this.queryIdToResultSetCacheIdMap.putIfAbsent(queryId, newCacheId);
+ if (cacheId != null) {
+ newCacheId = cacheId.longValue();
+ }
+ } else {
+ newCacheId = cacheId.longValue();
+ }
+
+ return newCacheId;
+ }
+
+ /**
+ * get cached NonForwardResultScanner instance by query id and cache id.
+ *
+ * @param queryId
+ * @param cacheId
+ * @return
+ */
+ public NonForwardQueryResultScanner getCachedNonForwardResultScanner(QueryId queryId, long cacheId) {
+ Long cachedCacheId = queryIdToResultSetCacheIdMap.get(queryId);
+
+ if (cachedCacheId == null) {
+ throw new RuntimeException("Supplied cache id " + cacheId + " was expired or invalid.");
+ }
+
+ if (cacheId != cachedCacheId.longValue()) {
+ throw new RuntimeException("Supplied cache id " + cacheId + " was expired or invalid. " +
+ "Please use the valid cache id.");
+ }
+
+ return queryResultScannerCache.getIfPresent(cachedCacheId);
+ }
+
+ /**
+ * Store NonForwardResultScanner instance to cached memory if not present.
+ *
+ * @param queryId
+ * @param cacheId
+ * @param resultScanner
+ */
+ public NonForwardQueryResultScanner setCachedNonForwardResultScanner(QueryId queryId, long cacheId,
+ NonForwardQueryResultScanner resultScanner) {
+ NonForwardQueryResultScanner cachedScanner = null;
+
+ if (cacheId == 0) {
+ cacheId = generateCacheIdIfAbsent(queryId);
+ }
+
+ cachedScanner = getCachedNonForwardResultScanner(queryId, cacheId);
+ if (cachedScanner == null) {
+ cachedScanner = this.queryResultScannerCache.asMap().putIfAbsent(cacheId, resultScanner);
+ if (cachedScanner == null) {
+ cachedScanner = resultScanner;
+ }
+ }
+
+ return cachedScanner;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegate.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegate.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegate.java
new file mode 100644
index 0000000..89f7a28
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegate.java
@@ -0,0 +1,31 @@
+/**
+ * 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;
+
+import javax.ws.rs.core.Response;
+
+/**
+ * Implements business flows for jersey resource
+ *
+ */
+public interface JerseyResourceDelegate {
+
+ public Response run(JerseyResourceDelegateContext context);
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContext.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContext.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContext.java
new file mode 100644
index 0000000..9f1fb4a
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContext.java
@@ -0,0 +1,64 @@
+/**
+ * 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;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * It holds variables for running deletegates
+ */
+public class JerseyResourceDelegateContext {
+
+ private final ConcurrentMap<JerseyResourceDelegateContextKey<?>, Object> contextMap =
+ new ConcurrentHashMap<JerseyResourceDelegateContextKey<?>, Object>();
+
+ /**
+ * Add value to Context. If value exists, it will overwrite.
+ *
+ * @param key
+ * @param value
+ * @return
+ */
+ public <T> JerseyResourceDelegateContext put(JerseyResourceDelegateContextKey<T> key, T value) {
+ contextMap.put(key, value);
+ return this;
+ }
+
+ public <T> T get(JerseyResourceDelegateContextKey<T> key) {
+ Class<T> keyTypeClass = key.getType();
+ Object object = contextMap.get(key);
+ if (object != null) {
+ return keyTypeClass.cast(contextMap.get(key));
+ } else {
+ if (Boolean.class.isAssignableFrom(keyTypeClass)) {
+ return keyTypeClass.cast(false);
+ } else if (Number.class.isAssignableFrom(keyTypeClass)) {
+ try {
+ return keyTypeClass.getConstructor(String.class).newInstance("0");
+ } catch (Throwable e) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContextKey.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContextKey.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContextKey.java
new file mode 100644
index 0000000..3c059d4
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateContextKey.java
@@ -0,0 +1,87 @@
+/**
+ * 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;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.ws.rs.core.GenericType;
+
+public class JerseyResourceDelegateContextKey<T> {
+
+ private static final ConcurrentMap<String, JerseyResourceDelegateContextKey<?>> keyMap =
+ new ConcurrentHashMap<String, JerseyResourceDelegateContextKey<?>>();
+
+ private final String name;
+ private final Class<T> type;
+
+ private JerseyResourceDelegateContextKey(String name, Class<T> type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ public static <T> JerseyResourceDelegateContextKey<T> valueOf(String name, Class<T> type) {
+ if (name == null || name.isEmpty()) {
+ throw new RuntimeException("name cannnot be null or empty.");
+ }
+
+ JerseyResourceDelegateContextKey<T> key = (JerseyResourceDelegateContextKey<T>) keyMap.get(name);
+ if (key == null) {
+ key = new JerseyResourceDelegateContextKey<T>(name, type);
+ keyMap.putIfAbsent(name, key);
+ }
+
+ return key;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> JerseyResourceDelegateContextKey<T> valueOf(String name, GenericType<T> genericType) {
+ return (JerseyResourceDelegateContextKey<T>) valueOf(name, genericType.getRawType());
+ }
+
+ public Class<T> getType() {
+ return type;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ JerseyResourceDelegateContextKey other = (JerseyResourceDelegateContextKey) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateUtil.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateUtil.java
new file mode 100644
index 0000000..365f3b8
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/JerseyResourceDelegateUtil.java
@@ -0,0 +1,61 @@
+/**
+ * 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;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.logging.Log;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+import org.apache.tajo.ws.rs.ResourcesUtil;
+
+public class JerseyResourceDelegateUtil {
+
+ public static final String ClientApplicationKey = "ClientApplication";
+ public static final String MasterContextKey = "MasterContextKey";
+ public static final String UriInfoKey = "UriInfoKey";
+
+ public static Response runJerseyResourceDelegate(JerseyResourceDelegate delegate,
+ Application application,
+ JerseyResourceDelegateContext context,
+ Log log) {
+ Application localApp = ResourceConfigUtil.getJAXRSApplication(application);
+
+ if ((localApp != null) && (localApp instanceof ClientApplication)) {
+ ClientApplication clientApplication = (ClientApplication) localApp;
+ JerseyResourceDelegateContextKey<ClientApplication> clientApplicationKey =
+ JerseyResourceDelegateContextKey.valueOf(ClientApplicationKey, ClientApplication.class);
+ context.put(clientApplicationKey, clientApplication);
+
+ MasterContext masterContext = clientApplication.getMasterContext();
+
+ if (masterContext != null) {
+ JerseyResourceDelegateContextKey<MasterContext> key =
+ JerseyResourceDelegateContextKey.valueOf(MasterContextKey, MasterContext.class);
+ context.put(key, masterContext);
+
+ return delegate.run(context);
+ } else {
+ return ResourcesUtil.createExceptionResponse(log, "MasterContext is null.");
+ }
+ } else {
+ return ResourcesUtil.createExceptionResponse(log, "Invalid injection on SessionsResource.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/ResourcesUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/ResourcesUtil.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/ResourcesUtil.java
new file mode 100644
index 0000000..5794636
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/ResourcesUtil.java
@@ -0,0 +1,47 @@
+/**
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.tajo.ws.rs.responses.ExceptionResponse;
+
+import javax.ws.rs.core.Response;
+
+public class ResourcesUtil {
+
+ public static Response createExceptionResponse(Log log, String message) {
+ if (log != null) {
+ log.error(message);
+ }
+
+ ExceptionResponse response = new ExceptionResponse();
+ response.setMessage(message);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(response).build();
+ }
+
+ public static Response createBadRequestResponse(Log log, String message) {
+ if (log != null) {
+ log.error(message);
+ }
+
+ ExceptionResponse response = new ExceptionResponse();
+ response.setMessage(message);
+ return Response.status(Response.Status.BAD_REQUEST).entity(response).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/TajoRestService.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/TajoRestService.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/TajoRestService.java
new file mode 100644
index 0000000..6da2b32
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/TajoRestService.java
@@ -0,0 +1,136 @@
+/**
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.service.CompositeService;
+import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.json.FunctionAdapter;
+import org.apache.tajo.catalog.json.TableMetaAdapter;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.function.Function;
+import org.apache.tajo.json.ClassNameSerializer;
+import org.apache.tajo.json.DataTypeAdapter;
+import org.apache.tajo.json.DatumAdapter;
+import org.apache.tajo.json.GsonSerDerAdapter;
+import org.apache.tajo.json.PathSerializer;
+import org.apache.tajo.json.TimeZoneGsonSerdeAdapter;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+import org.apache.tajo.plan.expr.EvalNode;
+import org.apache.tajo.plan.function.AggFunction;
+import org.apache.tajo.plan.function.GeneralFunction;
+import org.apache.tajo.plan.logical.LogicalNode;
+import org.apache.tajo.plan.serder.EvalNodeAdapter;
+import org.apache.tajo.plan.serder.LogicalNodeAdapter;
+import org.apache.tajo.util.TUtil;
+import org.apache.tajo.ws.rs.netty.NettyRestServer;
+import org.apache.tajo.ws.rs.netty.NettyRestServerFactory;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+
+import java.lang.reflect.Type;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class TajoRestService extends CompositeService {
+
+ private final Log LOG = LogFactory.getLog(getClass());
+
+ private MasterContext masterContext;
+ private NettyRestServer restServer;
+
+ public TajoRestService(MasterContext masterContext) {
+ super(TajoRestService.class.getName());
+
+ this.masterContext = masterContext;
+ }
+
+ private Map<Type, GsonSerDerAdapter<?>> registerTypeAdapterMap() {
+ Map<Type, GsonSerDerAdapter<?>> adapters = TUtil.newHashMap();
+ adapters.put(Path.class, new PathSerializer());
+ adapters.put(Class.class, new ClassNameSerializer());
+ adapters.put(LogicalNode.class, new LogicalNodeAdapter());
+ adapters.put(EvalNode.class, new EvalNodeAdapter());
+ adapters.put(TableMeta.class, new TableMetaAdapter());
+ adapters.put(Function.class, new FunctionAdapter());
+ adapters.put(GeneralFunction.class, new FunctionAdapter());
+ adapters.put(AggFunction.class, new FunctionAdapter());
+ adapters.put(Datum.class, new DatumAdapter());
+ adapters.put(DataType.class, new DataTypeAdapter());
+ adapters.put(TimeZone.class, new TimeZoneGsonSerdeAdapter());
+
+ return adapters;
+ }
+
+ @Override
+ protected void serviceInit(Configuration conf) throws Exception {
+ GsonFeature gsonFeature = new GsonFeature(registerTypeAdapterMap());
+
+ ClientApplication clientApplication = new ClientApplication(masterContext);
+ ResourceConfig resourceConfig = ResourceConfig.forApplication(clientApplication)
+ .register(gsonFeature)
+ .register(LoggingFilter.class)
+ .property(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true);
+ TajoConf tajoConf = (TajoConf) conf;
+
+ int port = TajoConf.getIntVar(tajoConf, TajoConf.ConfVars.REST_SERVICE_PORT);
+ URI restServiceURI = new URI("http", null, "0.0.0.0", port, "/rest", null, null);
+ int workerCount = TajoConf.getIntVar(tajoConf, TajoConf.ConfVars.REST_SERVICE_RPC_SERVER_WORKER_THREAD_NUM);
+ restServer = NettyRestServerFactory.createNettyRestServer(restServiceURI, resourceConfig, workerCount, false);
+
+ super.serviceInit(conf);
+
+ LOG.info("Tajo Rest Service initialized.");
+ }
+
+ @Override
+ protected void serviceStart() throws Exception {
+ restServer.start();
+
+ super.serviceStart();
+
+ LOG.info("Tajo Rest Service started.");
+ }
+
+ @Override
+ protected void serviceStop() throws Exception {
+ super.serviceStop();
+
+ if (restServer != null) {
+ restServer.shutdown();
+ }
+
+ LOG.info("Tajo Rest Service stopped.");
+ }
+
+ public InetSocketAddress getBindAddress() {
+ return restServer.getListenAddress();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewDatabaseRequest.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewDatabaseRequest.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewDatabaseRequest.java
new file mode 100644
index 0000000..85f68d5
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewDatabaseRequest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.requests;
+
+import com.google.gson.annotations.Expose;
+
+public class NewDatabaseRequest {
+ @Expose private String databaseName;
+
+ public String getDatabaseName() {
+ return databaseName;
+ }
+
+ public void setDatabaseName(String databaseName) {
+ this.databaseName = databaseName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewSessionRequest.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewSessionRequest.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewSessionRequest.java
new file mode 100644
index 0000000..8069179
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/NewSessionRequest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.requests;
+
+import com.google.gson.annotations.Expose;
+
+public class NewSessionRequest {
+
+ @Expose private String userName;
+ @Expose private String databaseName;
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getDatabaseName() {
+ return databaseName;
+ }
+
+ public void setDatabaseName(String databaseName) {
+ this.databaseName = databaseName;
+ }
+
+ @Override
+ public String toString() {
+ return "NewSessionRequest [userName=" + userName + ", databaseName=" + databaseName + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/SubmitQueryRequest.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/SubmitQueryRequest.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/SubmitQueryRequest.java
new file mode 100644
index 0000000..0bf5678
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/requests/SubmitQueryRequest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.requests;
+
+import com.google.gson.annotations.Expose;
+
+public class SubmitQueryRequest {
+
+ @Expose private String query;
+
+ public String getQuery() {
+ return query;
+ }
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/ClusterResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/ClusterResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/ClusterResource.java
new file mode 100644
index 0000000..349fa4c
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/ClusterResource.java
@@ -0,0 +1,117 @@
+/**
+ * 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.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+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.UriInfo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+import org.apache.tajo.master.rm.Worker;
+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.responses.WorkerResponse;
+
+@Path("/cluster")
+public class ClusterResource {
+
+ private static final Log LOG = LogFactory.getLog(ClusterResource.class);
+
+ @Context
+ UriInfo uriInfo;
+
+ @Context
+ Application application;
+
+ JerseyResourceDelegateContext context;
+
+ private static final String workersName = "workers";
+
+ private void initializeContext() {
+ context = new JerseyResourceDelegateContext();
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ context.put(uriInfoKey, uriInfo);
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getClusterInfo() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a get cluster info request.");
+ }
+
+ Response response = null;
+
+ try {
+ initializeContext();
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetClusterInfoDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetClusterInfoDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+
+ Map<Integer, Worker> workerMap = masterContext.getResourceManager().getWorkers();
+ List<WorkerResponse> workerList = new ArrayList<WorkerResponse>();
+
+ for (Worker worker: workerMap.values()) {
+ workerList.add(new WorkerResponse(worker));
+ }
+
+ Map<String, List<WorkerResponse>> workerResponseMap = new HashMap<String, List<WorkerResponse>>();
+ workerResponseMap.put(workersName, workerList);
+
+ return Response.ok(workerResponseMap).build();
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
new file mode 100644
index 0000000..3868cab
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/DatabasesResource.java
@@ -0,0 +1,339 @@
+/**
+ * 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.Collection;
+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.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+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.TajoConstants;
+import org.apache.tajo.catalog.CatalogService;
+import org.apache.tajo.catalog.proto.CatalogProtos.DatabaseProto;
+import org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+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.NewDatabaseRequest;
+import org.apache.tajo.ws.rs.responses.DatabaseInfoResponse;
+
+/**
+ * Deals with Database Management
+ */
+@Path("/databases")
+public class DatabasesResource {
+
+ private static final Log LOG = LogFactory.getLog(DatabasesResource.class);
+
+ @Context
+ UriInfo uriInfo;
+
+ @Context
+ Application application;
+
+ JerseyResourceDelegateContext context;
+
+ private static final String databasesKeyName = "databases";
+ private static final String newDatabaseRequestKeyName = "NewDatabaseKey";
+ private static final String databaseNameKeyName = "databaseName";
+
+ private void initializeContext() {
+ context = new JerseyResourceDelegateContext();
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ context.put(uriInfoKey, uriInfo);
+ }
+
+ /**
+ * Get all databases from catalog server
+ *
+ * @return
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getAllDatabases() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent retrieve all databases request.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetAllDatabasesDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetAllDatabasesDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+
+ Collection<String> databaseNames = masterContext.getCatalog().getAllDatabaseNames();
+ Map<String, Collection<String>> databaseNamesMap = new HashMap<String, Collection<String>>();
+ databaseNamesMap.put(databasesKeyName, databaseNames);
+ return Response.ok(databaseNamesMap).build();
+ }
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response createNewDatabase(NewDatabaseRequest request) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a new database creation request");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<NewDatabaseRequest> newDatabaseRequestKey =
+ JerseyResourceDelegateContextKey.valueOf(newDatabaseRequestKeyName, NewDatabaseRequest.class);
+ context.put(newDatabaseRequestKey, request);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new CreateNewDatabaseDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class CreateNewDatabaseDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<NewDatabaseRequest> newDatabaseRequestKey =
+ JerseyResourceDelegateContextKey.valueOf(newDatabaseRequestKeyName, NewDatabaseRequest.class);
+ NewDatabaseRequest request = context.get(newDatabaseRequestKey);
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ UriInfo uriInfo = context.get(uriInfoKey);
+
+ if (request.getDatabaseName() == null || request.getDatabaseName().isEmpty()) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "databaseName is null or empty.");
+ }
+
+ boolean databaseCreated =
+ masterContext.getCatalog().createDatabase(request.getDatabaseName(),
+ TajoConstants.DEFAULT_TABLESPACE_NAME);
+
+ if (databaseCreated) {
+ URI newDatabaseURI = uriInfo.getBaseUriBuilder()
+ .path(DatabasesResource.class)
+ .path(DatabasesResource.class, "getDatabase")
+ .build(request.getDatabaseName());
+ return Response.created(newDatabaseURI).build();
+ } else {
+ return ResourcesUtil.createExceptionResponse(LOG, "Failed to create a new database.");
+ }
+ }
+ }
+
+ /**
+ *
+ * @param databaseName
+ * @return
+ */
+ @GET
+ @Path("/{databaseName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getDatabase(@PathParam("databaseName") String databaseName) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a getDatabase request.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetDatabaseDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetDatabaseDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+
+ if (databaseName.isEmpty()) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "DatabaseName is empty string.");
+ }
+
+ CatalogService catalogService = masterContext.getCatalog();
+ List<DatabaseProto> databasesList = catalogService.getAllDatabases();
+ DatabaseProto selectedDatabase = null;
+ for (DatabaseProto database: databasesList) {
+ if (database.getName().equals(databaseName)) {
+ selectedDatabase = database;
+ break;
+ }
+ }
+
+ if (selectedDatabase != null) {
+ List<TablespaceProto> tablespacesList = catalogService.getAllTablespaces();
+ TablespaceProto selectedTablespace = null;
+
+ for (TablespaceProto tablespace: tablespacesList) {
+ if (tablespace.hasId() && tablespace.getId() == selectedDatabase.getSpaceId()) {
+ selectedTablespace = tablespace;
+ break;
+ }
+ }
+
+ DatabaseInfoResponse databaseInfo = new DatabaseInfoResponse();
+ databaseInfo.setId(selectedDatabase.getId());
+ databaseInfo.setName(selectedDatabase.getName());
+ databaseInfo.setTablespace(selectedTablespace.getUri());
+ return Response.ok(databaseInfo).build();
+ } else {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ }
+ }
+ }
+
+ /**
+ *
+ * @param databaseName
+ * @return
+ */
+ @DELETE
+ @Path("/{databaseName}")
+ public Response deleteDatabase(@PathParam("databaseName") String databaseName) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a delete database request.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+
+ return JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new DeleteDatabaseDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class DeleteDatabaseDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+
+ if (databaseName.isEmpty()) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "DatabaseName is empty string.");
+ }
+
+ CatalogService catalogService = masterContext.getCatalog();
+
+ if (!catalogService.existDatabase(databaseName)) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ boolean databaseDropped = catalogService.dropDatabase(databaseName);
+
+ if (databaseDropped) {
+ return Response.ok().build();
+ } else {
+ return ResourcesUtil.createExceptionResponse(LOG, "Unable to drop a database " + databaseName);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/FunctionsResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/FunctionsResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/FunctionsResource.java
new file mode 100644
index 0000000..9545b1a
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/FunctionsResource.java
@@ -0,0 +1,121 @@
+/**
+ * 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.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+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.catalog.FunctionDesc;
+import org.apache.tajo.function.FunctionSignature;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+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;
+
+@Path("/databases/{databaseName}/functions")
+public class FunctionsResource {
+
+ private static final Log LOG = LogFactory.getLog(TablesResource.class);
+
+ @Context
+ UriInfo uriInfo;
+
+ @Context
+ Application application;
+
+ @PathParam("databaseName")
+ String databaseName;
+
+ JerseyResourceDelegateContext context;
+
+ private static final String databaseNameKeyName = "databaseName";
+
+ private void initializeContext() {
+ context = new JerseyResourceDelegateContext();
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ context.put(uriInfoKey, uriInfo);
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getAllFunctions() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a retrieve all functions request.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetAllFunctionsDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+ return response;
+ }
+
+ private static class GetAllFunctionsDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+
+ Collection<FunctionDesc> functionDescriptors = masterContext.getCatalog().getFunctions();
+ if (functionDescriptors.size() > 0) {
+ List<FunctionSignature> functionSignature =
+ new ArrayList<FunctionSignature>(functionDescriptors.size());
+ for (FunctionDesc functionDesc : functionDescriptors) {
+ functionSignature.add(functionDesc.getSignature());
+ }
+
+ return Response.ok(functionSignature).build();
+ } else {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
----------------------------------------------------------------------
diff --git 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
new file mode 100644
index 0000000..99609d7
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResource.java
@@ -0,0 +1,448 @@
+/**
+ * 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());
+ } 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;
+ }
+}
[09/10] tajo git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/tajo into index_support
Posted by ji...@apache.org.
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
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/37b2abb3
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/37b2abb3
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/37b2abb3
Branch: refs/heads/index_support
Commit: 37b2abb303ddbcac3391d779dfe6b9223f35d56a
Parents: 3c18234 72948b6
Author: Jihoon Son <ji...@apache.org>
Authored: Mon Apr 6 13:42:34 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Mon Apr 6 13:42:34 2015 +0900
----------------------------------------------------------------------
CHANGES | 22 +
.../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 | 3 +
tajo-core/pom.xml | 8 +
.../org/apache/tajo/engine/parser/SQLLexer.g4 | 1 +
.../org/apache/tajo/engine/parser/SQLParser.g4 | 9 +
.../tajo/engine/function/builtin/MaxDate.java | 47 ++
.../tajo/engine/function/builtin/MaxTime.java | 47 ++
.../engine/function/builtin/MaxTimestamp.java | 47 ++
.../tajo/engine/function/builtin/MinDate.java | 48 ++
.../tajo/engine/function/builtin/MinTime.java | 48 ++
.../engine/function/builtin/MinTimestamp.java | 48 ++
.../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 +
.../main/java/org/apache/tajo/worker/Task.java | 3 +-
.../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 +-
.../engine/function/TestBuiltinFunctions.java | 146 ++++++
.../tajo/engine/parser/TestSQLAnalyzer.java | 39 ++
.../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/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/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 | 5 +
.../tajo/pullserver/TajoPullServerService.java | 10 +-
tajo-rpc/tajo-ws-rs/pom.xml | 4 +
.../apache/tajo/ws/rs/ResourceConfigUtil.java | 38 ++
.../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 +-
.../storage/HashShuffleAppenderManager.java | 4 +-
129 files changed, 5935 insertions(+), 236 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/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/37b2abb3/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/37b2abb3/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/37b2abb3/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-core/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-core/src/main/java/org/apache/tajo/master/exec/DDLExecutor.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-core/src/main/java/org/apache/tajo/master/exec/NonForwardQueryResultSystemScanner.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-core/src/main/java/org/apache/tajo/master/exec/QueryExecutor.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-core/src/main/java/org/apache/tajo/worker/Task.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/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/37b2abb3/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/37b2abb3/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;
[05/10] tajo git commit: TAJO-1338: Defines RESTful API for Clients
Posted by ji...@apache.org.
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
new file mode 100644
index 0000000..0f83189
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/QueryResultResource.java
@@ -0,0 +1,415 @@
+/**
+ * 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 com.google.protobuf.ByteString;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.QueryId;
+import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.master.QueryInfo;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+import org.apache.tajo.master.exec.NonForwardQueryResultFileScanner;
+import org.apache.tajo.master.exec.NonForwardQueryResultScanner;
+import org.apache.tajo.plan.LogicalPlan;
+import org.apache.tajo.plan.logical.PartitionedTableScanNode;
+import org.apache.tajo.plan.logical.ScanNode;
+import org.apache.tajo.session.Session;
+import org.apache.tajo.util.TajoIdUtils;
+import org.apache.tajo.ws.rs.*;
+import org.apache.tajo.ws.rs.responses.GetQueryResultDataResponse;
+import org.apache.tajo.ws.rs.responses.ResultSetInfoResponse;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.*;
+import javax.ws.rs.core.Response.Status;
+import java.io.BufferedOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+
+public class QueryResultResource {
+
+ private static final Log LOG = LogFactory.getLog(QueryResultResource.class);
+
+ private UriInfo uriInfo;
+
+ private Application application;
+
+ private String databaseName;
+
+ private String queryId;
+
+ private JerseyResourceDelegateContext context;
+
+ private static final String databaseNameKeyName = "databaseName";
+ private static final String queryIdKeyName = "queryId";
+ private static final String sessionIdKeyName = "sessionId";
+ private static final String cacheIdKeyName = "cacheId";
+ private static final String offsetKeyName = "offset";
+ private static final String countKeyName = "count";
+
+ private static final String tajoDigestHeaderName = "X-Tajo-Digest";
+
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ public void setUriInfo(UriInfo uriInfo) {
+ this.uriInfo = uriInfo;
+ }
+
+ public Application getApplication() {
+ return application;
+ }
+
+ public void setApplication(Application application) {
+ this.application = application;
+ }
+
+ public String getDatabaseName() {
+ return databaseName;
+ }
+
+ public void setDatabaseName(String databaseName) {
+ this.databaseName = databaseName;
+ }
+
+ public String getQueryId() {
+ return queryId;
+ }
+
+ public void setQueryId(String queryId) {
+ this.queryId = 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);
+ JerseyResourceDelegateContextKey<String> queryIdKey =
+ JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+ context.put(queryIdKey, queryId);
+ }
+
+ private static NonForwardQueryResultScanner getNonForwardQueryResultScanner(
+ MasterContext masterContext,
+ Session session,
+ QueryId queryId) throws IOException {
+ NonForwardQueryResultScanner resultScanner = session.getNonForwardQueryResultScanner(queryId);
+ if (resultScanner == null) {
+ QueryInfo queryInfo = masterContext.getQueryJobManager().getFinishedQuery(queryId);
+ if (queryInfo == null) {
+ throw new RuntimeException("QueryInfo isnull.");
+ }
+
+ TableDesc resultTableDesc = queryInfo.getResultDesc();
+ if (resultTableDesc == null) {
+ throw new RuntimeException("Result Table Desc is null.");
+ }
+
+ ScanNode scanNode;
+ if (resultTableDesc.hasPartition()) {
+ scanNode = LogicalPlan.createNodeWithoutPID(PartitionedTableScanNode.class);
+ scanNode.init(resultTableDesc);
+ } else {
+ scanNode = LogicalPlan.createNodeWithoutPID(ScanNode.class);
+ scanNode.init(resultTableDesc);
+ }
+
+ resultScanner = new NonForwardQueryResultFileScanner(masterContext.getConf(), session.getSessionId(), queryId,
+ scanNode, resultTableDesc, Integer.MAX_VALUE);
+ resultScanner.init();
+ session.addNonForwardQueryResultScanner(resultScanner);
+ }
+
+ return resultScanner;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getQueryResult(@HeaderParam(QueryResource.tajoSessionIdHeaderName) String sessionId) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a get query result request.");
+ }
+
+ Response response = null;
+
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ context.put(sessionIdKey, sessionId);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetQueryResultDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetQueryResultDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ String sessionId = context.get(sessionIdKey);
+ JerseyResourceDelegateContextKey<String> queryIdKey =
+ JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+ String queryId = context.get(queryIdKey);
+ JerseyResourceDelegateContextKey<ClientApplication> clientApplicationKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.ClientApplicationKey, ClientApplication.class);
+ ClientApplication clientApplication = context.get(clientApplicationKey);
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ UriInfo uriInfo = context.get(uriInfoKey);
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+
+ try {
+ masterContext.getSessionManager().touch(sessionId);
+ Session session = masterContext.getSessionManager().getSession(sessionId);
+ QueryId queryIdObj = TajoIdUtils.parseQueryId(queryId);
+
+ masterContext.getSessionManager().touch(sessionId);
+
+ QueryInfo queryInfo = masterContext.getQueryJobManager().getFinishedQuery(queryIdObj);
+ GetQueryResultDataResponse response = new GetQueryResultDataResponse();
+
+ if (queryInfo == null) {
+ response.setResultCode(ResultCode.ERROR);
+ response.setErrorMessage("Unable to find a query info for requested id : " + queryId);
+ return Response.status(Status.NOT_FOUND).entity(response).build();
+ }
+
+ NonForwardQueryResultScanner queryResultScanner = getNonForwardQueryResultScanner(masterContext, session, queryIdObj);
+
+ if (queryInfo.getResultDesc() != null && queryInfo.getResultDesc().getSchema() != null) {
+ response.setSchema(queryInfo.getResultDesc().getSchema());
+ } else {
+ response.setSchema(queryResultScanner.getLogicalSchema());
+ }
+
+ long cacheId = clientApplication.generateCacheIdIfAbsent(queryIdObj);
+ clientApplication.setCachedNonForwardResultScanner(queryIdObj, cacheId, queryResultScanner);
+ URI resultSetCacheUri = uriInfo.getBaseUriBuilder()
+ .path(QueryResource.class)
+ .path(QueryResource.class, "getQueryResult")
+ .path(QueryResultResource.class, "getQueryResultSet")
+ .build(databaseName, queryId, cacheId);
+ ResultSetInfoResponse resultSetInfoResponse = new ResultSetInfoResponse();
+ resultSetInfoResponse.setId(cacheId);
+ resultSetInfoResponse.setLink(resultSetCacheUri);
+ response.setResultset(resultSetInfoResponse);
+ response.setResultCode(ResultCode.OK);
+
+ return Response.status(Status.OK).entity(response).build();
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ GetQueryResultDataResponse response = new GetQueryResultDataResponse();
+ response.setResultCode(ResultCode.ERROR);
+ response.setErrorMessage(e.getMessage());
+ response.setErrorTrace(org.apache.hadoop.util.StringUtils.stringifyException(e));
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(response).build();
+ }
+ }
+ }
+
+ @GET
+ @Path("{cacheId}")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response getQueryResultSet(@HeaderParam(QueryResource.tajoSessionIdHeaderName) String sessionId,
+ @PathParam("cacheId") String cacheId,
+ @DefaultValue("-1") @QueryParam("offset") int offset,
+ @DefaultValue("-1") @QueryParam("count") int count) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a get query result set request.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ context.put(sessionIdKey, sessionId);
+ JerseyResourceDelegateContextKey<Long> cacheIdKey =
+ JerseyResourceDelegateContextKey.valueOf(cacheIdKeyName, Long.class);
+ context.put(cacheIdKey, Long.valueOf(cacheId));
+ JerseyResourceDelegateContextKey<Integer> offsetKey =
+ JerseyResourceDelegateContextKey.valueOf(offsetKeyName, Integer.class);
+ context.put(offsetKey, offset);
+ JerseyResourceDelegateContextKey<Integer> countKey =
+ JerseyResourceDelegateContextKey.valueOf(countKeyName, Integer.class);
+ context.put(countKey, count);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetQueryResultSetDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetQueryResultSetDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ String sessionId = context.get(sessionIdKey);
+ JerseyResourceDelegateContextKey<String> queryIdKey =
+ JerseyResourceDelegateContextKey.valueOf(queryIdKeyName, String.class);
+ String queryId = context.get(queryIdKey);
+ JerseyResourceDelegateContextKey<Long> cacheIdKey =
+ JerseyResourceDelegateContextKey.valueOf(cacheIdKeyName, Long.class);
+ Long cacheId = context.get(cacheIdKey);
+ JerseyResourceDelegateContextKey<ClientApplication> clientApplicationKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.ClientApplicationKey, ClientApplication.class);
+ ClientApplication clientApplication = context.get(clientApplicationKey);
+ JerseyResourceDelegateContextKey<Integer> offsetKey =
+ JerseyResourceDelegateContextKey.valueOf(offsetKeyName, Integer.class);
+ int offset = context.get(offsetKey);
+ JerseyResourceDelegateContextKey<Integer> countKey =
+ JerseyResourceDelegateContextKey.valueOf(countKeyName, Integer.class);
+ int count = context.get(countKey);
+
+ if (sessionId == null || sessionId.isEmpty()) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "Session id is required. Please refer the header " +
+ QueryResource.tajoSessionIdHeaderName);
+ }
+
+ if (queryId == null || queryId.isEmpty()) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "Query id is required. Please specify the query id");
+ }
+
+ QueryId queryIdObj;
+ try {
+ queryIdObj = TajoIdUtils.parseQueryId(queryId);
+ } catch (Throwable e) {
+ return ResourcesUtil.createExceptionResponse(LOG, "Invalid query id : " + queryId);
+ }
+
+ if (cacheId == null || cacheId.longValue() == 0) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "Cache id is null or empty.");
+ }
+
+ if (count < 0) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "Invalid count value : " + count);
+ }
+
+ NonForwardQueryResultScanner cachedQueryResultScanner =
+ clientApplication.getCachedNonForwardResultScanner(queryIdObj, cacheId.longValue());
+
+ try {
+ skipOffsetRow(cachedQueryResultScanner, offset);
+
+ List<ByteString> output = cachedQueryResultScanner.getNextRows(count);
+ String digestString = getEncodedBase64DigestString(output);
+
+ return Response.ok(new QueryResultStreamingOutput(output))
+ .header(tajoDigestHeaderName, digestString)
+ .build();
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+
+ return ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ } catch (NoSuchAlgorithmException e) {
+ LOG.error(e.getMessage(), e);
+
+ return ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+ }
+
+ private void skipOffsetRow(NonForwardQueryResultScanner queryResultScanner, int offset) throws IOException {
+ if (offset < 0) {
+ return;
+ }
+
+ int currentRow = queryResultScanner.getCurrentRowNumber();
+
+ if (offset < (currentRow+1)) {
+ throw new RuntimeException("Offset must be over the current row number");
+ }
+
+ queryResultScanner.getNextRows(offset - currentRow - 1);
+ }
+
+ private String getEncodedBase64DigestString(List<ByteString> outputList) throws NoSuchAlgorithmException {
+ MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
+
+ for (ByteString byteString: outputList) {
+ messageDigest.update(byteString.toByteArray());
+ }
+
+ return Base64.encodeBase64String(messageDigest.digest());
+ }
+ }
+
+ private static class QueryResultStreamingOutput implements StreamingOutput {
+
+ private final List<ByteString> outputList;
+
+ public QueryResultStreamingOutput(List<ByteString> outputList) {
+ this.outputList = outputList;
+ }
+
+ @Override
+ public void write(OutputStream outputStream) throws IOException, WebApplicationException {
+ DataOutputStream streamingOutputStream = new DataOutputStream(new BufferedOutputStream(outputStream));
+
+ for (ByteString byteString: outputList) {
+ byte[] byteStringArray = byteString.toByteArray();
+ streamingOutputStream.writeInt(byteStringArray.length);
+ streamingOutputStream.write(byteStringArray);
+ }
+
+ streamingOutputStream.flush();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
new file mode 100644
index 0000000..25aa798
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/SessionsResource.java
@@ -0,0 +1,380 @@
+/**
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.ipc.ClientProtos;
+import org.apache.tajo.master.TajoMaster;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+import org.apache.tajo.session.InvalidSessionException;
+import org.apache.tajo.session.Session;
+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.NewSessionRequest;
+import org.apache.tajo.ws.rs.responses.ExceptionResponse;
+import org.apache.tajo.ws.rs.responses.NewSessionResponse;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.*;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+@Path("/sessions")
+public class SessionsResource {
+
+ private static final Log LOG = LogFactory.getLog(SessionsResource.class);
+
+ @Context
+ UriInfo uriInfo;
+
+ @Context
+ Application application;
+
+ JerseyResourceDelegateContext context;
+
+ private static final String newSessionRequestKeyName = "NewSessionRequest";
+ private static final String sessionIdKeyName = "SessionId";
+ private static final String variablesKeyName = "VariablesMap";
+
+ private static final String variablesOutputKeyName = "variables";
+
+ private void initializeContext() {
+ context = new JerseyResourceDelegateContext();
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ context.put(uriInfoKey, uriInfo);
+ }
+
+ /**
+ * Creates a new client session.
+ *
+ * @param request
+ * @return
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createNewSession(NewSessionRequest request) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a new session request. : " + request);
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<NewSessionRequest> newSessionRequestKey =
+ JerseyResourceDelegateContextKey.valueOf(newSessionRequestKeyName, NewSessionRequest.class);
+ context.put(newSessionRequestKey, request);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new CreateNewSessionDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+ return response;
+ }
+
+ private static class CreateNewSessionDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ try {
+ JerseyResourceDelegateContextKey<NewSessionRequest> sessionRequestKey =
+ JerseyResourceDelegateContextKey.valueOf(newSessionRequestKeyName, NewSessionRequest.class);
+ NewSessionRequest request = context.get(sessionRequestKey);
+
+ if (request.getUserName() == null || request.getUserName().isEmpty()) {
+ return ResourcesUtil.createBadRequestResponse(LOG, "userName is null or empty.");
+ }
+
+ String userName = request.getUserName();
+ String databaseName = request.getDatabaseName();
+ if (databaseName == null || databaseName.isEmpty()) {
+ databaseName = TajoConstants.DEFAULT_DATABASE_NAME;
+ }
+
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ TajoMaster.MasterContext masterContext = context.get(masterContextKey);
+
+ NewSessionResponse sessionResponse = new NewSessionResponse();
+ String sessionId = masterContext.getSessionManager().createSession(userName, databaseName);
+
+ LOG.info("Session " + sessionId + " is created. ");
+
+ sessionResponse.setId(sessionId);
+ sessionResponse.setResultCode(ClientProtos.ResultCode.OK);
+ sessionResponse.setVariables(masterContext.getSessionManager().getAllVariables(sessionId));
+
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ UriInfo uriInfo = context.get(uriInfoKey);
+
+ URI newSessionUri = uriInfo.getBaseUriBuilder()
+ .path(SessionsResource.class).path(sessionId).build();
+
+ return Response.created(newSessionUri).entity(sessionResponse).build();
+ } catch (InvalidSessionException e) {
+ LOG.error(e.getMessage(), e);
+
+ NewSessionResponse sessionResponse = new NewSessionResponse();
+ sessionResponse.setResultCode(ClientProtos.ResultCode.ERROR);
+ sessionResponse.setMessage(e.getMessage());
+
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(sessionResponse).build();
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ NewSessionResponse sessionResponse = new NewSessionResponse();
+ sessionResponse.setResultCode(ClientProtos.ResultCode.ERROR);
+ sessionResponse.setMessage(e.getMessage());
+
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(sessionResponse).build();
+ }
+ }
+
+ }
+
+ /**
+ * Removes existing sessions.
+ *
+ * @param sessionId
+ * @return
+ */
+ @DELETE
+ @Path("/{session-id}")
+ public Response removeSession(@PathParam("session-id") String sessionId) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent remove session request : Session Id (" + sessionId + ")");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ context.put(sessionIdKey, sessionId);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new RemoveSessionDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class RemoveSessionDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ TajoMaster.MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ String sessionId = context.get(sessionIdKey);
+
+ Session session = masterContext.getSessionManager().removeSession(sessionId);
+
+ if (session != null) {
+ LOG.info("Session " + sessionId + " is removed.");
+
+ return Response.status(Response.Status.OK).build();
+ } else {
+ ExceptionResponse response = new ExceptionResponse();
+ response.setMessage("Unable to find a session (" + sessionId + ")");
+
+ return Response.status(Response.Status.NOT_FOUND).entity(response).build();
+ }
+ }
+
+ }
+
+ /**
+ * Retrieves all session variables
+ *
+ * @param sessionId
+ * @return
+ */
+ @GET
+ @Path("/{session-id}/variables")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getAllSessionVariables(@PathParam("session-id") String sessionId) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a GetAllSessionVariables request for a session : " + sessionId);
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ context.put(sessionIdKey, sessionId);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetAllSessionVariablesDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetAllSessionVariablesDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ TajoMaster.MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ String sessionId = context.get(sessionIdKey);
+
+ try {
+ Map<String, Map<String, String>> variablesMap = new HashMap<String, Map<String, String>>();
+ variablesMap.put(variablesOutputKeyName,
+ masterContext.getSessionManager().getAllVariables(sessionId));
+ GenericEntity<Map<String, Map<String, String>>> variablesEntity =
+ new GenericEntity<Map<String, Map<String, String>>>(variablesMap, Map.class);
+ return Response.ok(variablesEntity).build();
+ } catch (InvalidSessionException e) {
+ LOG.error("Unable to find a session : " + sessionId);
+
+ return Response.status(Response.Status.NOT_FOUND).build();
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ return ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+ }
+
+ }
+
+ /**
+ * Updates the specified session varaible or variables
+ *
+ * @param sessionId
+ * @param variables
+ * @return
+ */
+ @PUT
+ @Path("/{session-id}/variables")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateSessionVariables(@PathParam("session-id") String sessionId,
+ Map<String, Object> variables) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a update session variables request for a session : " + sessionId);
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ context.put(sessionIdKey, sessionId);
+ JerseyResourceDelegateContextKey<Map> variablesMapKey =
+ JerseyResourceDelegateContextKey.valueOf(variablesKeyName, Map.class);
+ context.put(variablesMapKey, variables);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new UpdateSessionVariablesDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class UpdateSessionVariablesDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<String> sessionIdKey =
+ JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class);
+ String sessionId = context.get(sessionIdKey);
+ JerseyResourceDelegateContextKey<Map> variablesKey =
+ JerseyResourceDelegateContextKey.valueOf(variablesKeyName, Map.class);
+ Map<String, Object> variables = context.get(variablesKey);
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ TajoMaster.MasterContext masterContext = context.get(masterContextKey);
+
+ try {
+ if (variables.containsKey(variablesOutputKeyName)) {
+ Map<String, String> variablesMap = (Map<String, String>) variables.get(variablesOutputKeyName);
+ for (Map.Entry<String, String> variableEntry: variablesMap.entrySet()) {
+ masterContext.getSessionManager().setVariable(sessionId, variableEntry.getKey(), variableEntry.getValue());
+ }
+
+ return Response.ok().build();
+ } else {
+ Iterator<Map.Entry<String, Object>> iterator = variables.entrySet().iterator();
+ if (iterator.hasNext()) {
+ Map.Entry<String, Object> entry = iterator.next();
+
+ masterContext.getSessionManager().setVariable(sessionId, entry.getKey(), (String) entry.getValue());
+
+ return Response.ok().build();
+ } else {
+ return ResourcesUtil.createBadRequestResponse(LOG, "At least one variable is required.");
+ }
+ }
+ } catch (InvalidSessionException e) {
+ LOG.error("Unable to find a session : " + sessionId);
+
+ return Response.status(Response.Status.NOT_FOUND).build();
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ return ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
new file mode 100644
index 0000000..3e638d6
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/resources/TablesResource.java
@@ -0,0 +1,350 @@
+/**
+ * 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.Collection;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+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.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.catalog.CatalogService;
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.master.TajoMaster.MasterContext;
+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;
+
+@Path("/databases/{databaseName}/tables")
+public class TablesResource {
+
+ private static final Log LOG = LogFactory.getLog(TablesResource.class);
+
+ @Context
+ UriInfo uriInfo;
+
+ @Context
+ Application application;
+
+ @PathParam("databaseName")
+ String databaseName;
+
+ JerseyResourceDelegateContext context;
+
+ private static final String databaseNameKeyName = "databaseName";
+ private static final String tableNameKeyName = "tableName";
+ private static final String tableDescKeyName = "tableDesc";
+
+ private void initializeContext() {
+ context = new JerseyResourceDelegateContext();
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ context.put(uriInfoKey, uriInfo);
+ }
+
+ public void setDatabaseName(String databaseName) {
+ this.databaseName = databaseName;
+ }
+
+ public void setUriInfo(UriInfo uriInfo) {
+ this.uriInfo = uriInfo;
+ }
+
+ public void setApplication(Application application) {
+ this.application = application;
+ }
+
+ /**
+ *
+ * @param databaseName
+ * @param tableMeta
+ * @return
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response createNewTable(TableDesc tableDesc) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a create table request on " + databaseName + " database.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+ JerseyResourceDelegateContextKey<TableDesc> tableDescKey =
+ JerseyResourceDelegateContextKey.valueOf(tableDescKeyName, TableDesc.class);
+ context.put(tableDescKey, tableDesc);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new CreateNewTableDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class CreateNewTableDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+ JerseyResourceDelegateContextKey<TableDesc> tableDescKey =
+ JerseyResourceDelegateContextKey.valueOf(tableDescKeyName, TableDesc.class);
+ TableDesc tableDesc = context.get(tableDescKey);
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+
+ if (!CatalogUtil.isFQTableName(tableDesc.getName())) {
+ tableDesc.setName(CatalogUtil.getCanonicalTableName(databaseName, tableDesc.getName()));
+ }
+
+ CatalogService catalogService = masterContext.getCatalog();
+ boolean tableCreated = catalogService.createTable(tableDesc);
+ if (tableCreated) {
+ JerseyResourceDelegateContextKey<UriInfo> uriInfoKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.UriInfoKey, UriInfo.class);
+ UriInfo uriInfo = context.get(uriInfoKey);
+
+ URI tableUri = uriInfo.getBaseUriBuilder()
+ .path(TablesResource.class)
+ .path(TablesResource.class, "getTable")
+ .build(databaseName, CatalogUtil.extractSimpleName(tableDesc.getName()));
+ return Response.created(tableUri).build();
+ } else {
+ return ResourcesUtil.createExceptionResponse(LOG, "Table Creation has been failed.");
+ }
+ }
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getAllTables() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a get all tables request.");
+ }
+
+ Response response = null;
+
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetAllTablesDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetAllTablesDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+
+ CatalogService catalogService = masterContext.getCatalog();
+
+ if (!catalogService.existDatabase(databaseName)) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ Collection<String> tableNames = catalogService.getAllTableNames(databaseName);
+ List<TableDesc> tables = new ArrayList<TableDesc>();
+
+ for (String tableName: tableNames) {
+ tables.add(new TableDesc(tableName, null, null, null));
+ }
+
+ return Response.ok(tables).build();
+ }
+
+ }
+
+ @GET
+ @Path("/{tableName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getTable(@PathParam("tableName") String tableName) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a get table request.");
+ }
+
+ Response response = null;
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+ JerseyResourceDelegateContextKey<String> tableNameKey =
+ JerseyResourceDelegateContextKey.valueOf(tableNameKeyName, String.class);
+ context.put(tableNameKey, tableName);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new GetTableDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class GetTableDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+ JerseyResourceDelegateContextKey<String> tableNameKey =
+ JerseyResourceDelegateContextKey.valueOf(tableNameKeyName, String.class);
+ String tableName = context.get(tableNameKey);
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+
+ if (CatalogUtil.isFQTableName(tableName)) {
+ tableName = CatalogUtil.extractSimpleName(tableName);
+ }
+
+ CatalogService catalogService = masterContext.getCatalog();
+ if (!catalogService.existDatabase(databaseName) ||
+ !catalogService.existsTable(databaseName, tableName)) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ TableDesc tableDesc = catalogService.getTableDesc(databaseName, tableName);
+ return Response.ok(tableDesc).build();
+ }
+ }
+
+ @DELETE
+ @Path("/{tableName}")
+ public Response deleteTable(@PathParam("tableName") String tableName) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Client sent a drop table request for the table " + tableName);
+ }
+
+ Response response = null;
+
+ try {
+ initializeContext();
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ context.put(databaseNameKey, databaseName);
+ JerseyResourceDelegateContextKey<String> tableNameKey =
+ JerseyResourceDelegateContextKey.valueOf(tableNameKeyName, String.class);
+ context.put(tableNameKey, tableName);
+
+ response = JerseyResourceDelegateUtil.runJerseyResourceDelegate(
+ new DeleteTableDelegate(),
+ application,
+ context,
+ LOG);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
+
+ response = ResourcesUtil.createExceptionResponse(null, e.getMessage());
+ }
+
+ return response;
+ }
+
+ private static class DeleteTableDelegate implements JerseyResourceDelegate {
+
+ @Override
+ public Response run(JerseyResourceDelegateContext context) {
+ JerseyResourceDelegateContextKey<String> databaseNameKey =
+ JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class);
+ String databaseName = context.get(databaseNameKey);
+ JerseyResourceDelegateContextKey<String> tableNameKey =
+ JerseyResourceDelegateContextKey.valueOf(tableNameKeyName, String.class);
+ String tableName = context.get(tableNameKey);
+ JerseyResourceDelegateContextKey<MasterContext> masterContextKey =
+ JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class);
+ MasterContext masterContext = context.get(masterContextKey);
+
+ if (CatalogUtil.isFQTableName(tableName)) {
+ tableName = CatalogUtil.extractSimpleName(tableName);
+ }
+
+ CatalogService catalogService = masterContext.getCatalog();
+ if (!catalogService.existDatabase(databaseName) ||
+ !catalogService.existsTable(databaseName, tableName)) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ String canonicalTableName = CatalogUtil.getCanonicalTableName(databaseName, tableName);
+ boolean tableDropped =
+ catalogService.dropTable(canonicalTableName);
+ if (tableDropped) {
+ return Response.ok().build();
+ } else {
+ return ResourcesUtil.createExceptionResponse(LOG, "Unable to drop a " + canonicalTableName + " table.");
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/DatabaseInfoResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/DatabaseInfoResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/DatabaseInfoResponse.java
new file mode 100644
index 0000000..846ba2d
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/DatabaseInfoResponse.java
@@ -0,0 +1,48 @@
+/**
+ * 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.responses;
+
+import com.google.gson.annotations.Expose;
+
+public class DatabaseInfoResponse {
+
+ @Expose private int id;
+ @Expose private String tablespace;
+ @Expose private String name;
+
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getTablespace() {
+ return tablespace;
+ }
+ public void setTablespace(String tablespace) {
+ this.tablespace = tablespace;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ExceptionResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ExceptionResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ExceptionResponse.java
new file mode 100644
index 0000000..36046b1
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ExceptionResponse.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.ws.rs.responses;
+
+import com.google.gson.annotations.Expose;
+
+public class ExceptionResponse {
+ @Expose private String message;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
new file mode 100644
index 0000000..512f20f
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/GetQueryResultDataResponse.java
@@ -0,0 +1,72 @@
+/**
+ * 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.responses;
+
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.ipc.ClientProtos;
+
+import com.google.gson.annotations.Expose;
+
+public class GetQueryResultDataResponse {
+
+ @Expose private ClientProtos.ResultCode resultCode;
+ @Expose private Schema schema;
+ @Expose private int bytesNum;
+ @Expose private ResultSetInfoResponse resultset;
+ @Expose private String errorMessage;
+ @Expose private String errorTrace;
+
+ public ClientProtos.ResultCode getResultCode() {
+ return resultCode;
+ }
+ public void setResultCode(ClientProtos.ResultCode resultCode) {
+ this.resultCode = resultCode;
+ }
+ public Schema getSchema() {
+ return schema;
+ }
+ public void setSchema(Schema schema) {
+ this.schema = schema;
+ }
+ public int getBytesNum() {
+ return bytesNum;
+ }
+ public void setBytesNum(int bytesNum) {
+ this.bytesNum = bytesNum;
+ }
+ public ResultSetInfoResponse getResultset() {
+ return resultset;
+ }
+ public void setResultset(ResultSetInfoResponse resultset) {
+ this.resultset = resultset;
+ }
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+ public String getErrorTrace() {
+ return errorTrace;
+ }
+ public void setErrorTrace(String errorTrace) {
+ this.errorTrace = errorTrace;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
new file mode 100644
index 0000000..67b5b33
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/NewSessionResponse.java
@@ -0,0 +1,76 @@
+/**
+ * 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.responses;
+
+import org.apache.tajo.ipc.ClientProtos;
+import org.apache.tajo.util.TUtil;
+
+import com.google.gson.annotations.Expose;
+
+import java.util.Map;
+
+public class NewSessionResponse {
+
+ @Expose private String id;
+ @Expose private String message;
+ @Expose private ClientProtos.ResultCode resultCode;
+ @Expose private Map<String, String> variables;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public ClientProtos.ResultCode getResultCode() {
+ return resultCode;
+ }
+
+ public void setResultCode(ClientProtos.ResultCode resultCode) {
+ this.resultCode = resultCode;
+ }
+
+ public Map<String, String> getVariables() {
+ if (variables == null) {
+ variables = TUtil.newHashMap();
+ }
+ return variables;
+ }
+
+ public void setVariables(Map<String, String> variables) {
+ getVariables().putAll(variables);
+ }
+
+ @Override
+ public String toString() {
+ return "NewSessionResponse [id=" + id + ", message=" + message + ", resultCode=" + resultCode + ", variables="
+ + variables + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ResultSetInfoResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ResultSetInfoResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ResultSetInfoResponse.java
new file mode 100644
index 0000000..93d79c9
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/ResultSetInfoResponse.java
@@ -0,0 +1,43 @@
+/**
+ * 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.responses;
+
+import java.net.URI;
+
+import com.google.gson.annotations.Expose;
+
+public class ResultSetInfoResponse {
+
+ @Expose private long id;
+ @Expose private URI link;
+
+ public long getId() {
+ return id;
+ }
+ public void setId(long id) {
+ this.id = id;
+ }
+ public URI getLink() {
+ return link;
+ }
+ public void setLink(URI link) {
+ this.link = link;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerConnectionInfoResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerConnectionInfoResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerConnectionInfoResponse.java
new file mode 100644
index 0000000..3c8cb8b
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerConnectionInfoResponse.java
@@ -0,0 +1,67 @@
+/**
+ * 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.responses;
+
+import org.apache.tajo.master.cluster.WorkerConnectionInfo;
+
+import com.google.gson.annotations.Expose;
+
+public class WorkerConnectionInfoResponse {
+
+ @Expose private int id;
+
+ @Expose private String host;
+
+ @Expose private int peerRpcPort;
+
+ @Expose private int pullServerPort;
+
+ @Expose private int queryMasterPort;
+
+ @Expose private int clientPort;
+
+ @Expose private int httpInfoPort;
+
+ public WorkerConnectionInfoResponse(WorkerConnectionInfo connectionInfo) {
+ this.id = connectionInfo.getId();
+ this.host = connectionInfo.getHost();
+ this.peerRpcPort = connectionInfo.getPeerRpcPort();
+ this.pullServerPort = connectionInfo.getPullServerPort();
+ this.clientPort = connectionInfo.getClientPort();
+ this.queryMasterPort = connectionInfo.getQueryMasterPort();
+ this.httpInfoPort = connectionInfo.getHttpInfoPort();
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerResponse.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerResponse.java b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerResponse.java
new file mode 100644
index 0000000..84b81f8
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/ws/rs/responses/WorkerResponse.java
@@ -0,0 +1,76 @@
+/**
+ * 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.responses;
+
+import org.apache.tajo.master.rm.Worker;
+import org.apache.tajo.master.rm.WorkerResource;
+
+import com.google.gson.annotations.Expose;
+
+public class WorkerResponse {
+
+ @Expose private WorkerConnectionInfoResponse connectionInfo;
+
+ @Expose private float diskSlots;
+ @Expose private int cpuCoreSlots;
+ @Expose private int memoryMB;
+
+ @Expose private float usedDiskSlots;
+ @Expose private int usedMemoryMB;
+ @Expose private int usedCpuCoreSlots;
+
+ @Expose private long maxHeap;
+ @Expose private long freeHeap;
+ @Expose private long totalHeap;
+
+ @Expose private int numRunningTasks;
+ @Expose private int numQueryMasterTasks;
+
+ @Expose private long lastHeartbeatTime;
+
+ public WorkerResponse(Worker worker) {
+ this(worker.getResource());
+
+ this.connectionInfo = new WorkerConnectionInfoResponse(worker.getConnectionInfo());
+
+ this.lastHeartbeatTime = worker.getLastHeartbeatTime();
+ }
+
+ private WorkerResponse(WorkerResource resource) {
+ this.cpuCoreSlots = resource.getCpuCoreSlots();
+ this.memoryMB = resource.getMemoryMB();
+ this.usedDiskSlots = resource.getUsedDiskSlots();
+ this.usedMemoryMB = resource.getUsedMemoryMB();
+ this.usedCpuCoreSlots = resource.getUsedCpuCoreSlots();
+ this.maxHeap = resource.getMaxHeap();
+ this.freeHeap = resource.getFreeHeap();
+ this.totalHeap = resource.getTotalHeap();
+ this.numRunningTasks = resource.getNumRunningTasks();
+ this.numQueryMasterTasks = resource.getNumQueryMasterTasks();
+ }
+
+ public WorkerConnectionInfoResponse getConnectionInfo() {
+ return connectionInfo;
+ }
+
+ public void setConnectionInfo(WorkerConnectionInfoResponse connectionInfo) {
+ this.connectionInfo = connectionInfo;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java b/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
index 9d9310e..f7fb2f2 100644
--- a/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
+++ b/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
@@ -336,6 +336,7 @@ public class TajoTestingCluster {
c.setVar(ConfVars.RESOURCE_TRACKER_RPC_ADDRESS, "localhost:0");
c.setVar(ConfVars.WORKER_PEER_RPC_ADDRESS, "localhost:0");
c.setVar(ConfVars.WORKER_TEMPORAL_DIR, "file://" + testBuildDir.getAbsolutePath() + "/tajo-localdir");
+ c.setIntVar(ConfVars.REST_SERVICE_PORT, 0);
LOG.info("derby repository is set to "+conf.get(CatalogConstants.CATALOG_URI));
@@ -361,6 +362,10 @@ public class TajoTestingCluster {
tajoMasterAddress.getHostName() + ":" + tajoMasterAddress.getPort());
this.conf.setVar(ConfVars.RESOURCE_TRACKER_RPC_ADDRESS, c.getVar(ConfVars.RESOURCE_TRACKER_RPC_ADDRESS));
this.conf.setVar(ConfVars.CATALOG_ADDRESS, c.getVar(ConfVars.CATALOG_ADDRESS));
+
+ InetSocketAddress tajoRestAddress = tajoMaster.getContext().getRestServer().getBindAddress();
+
+ this.conf.setIntVar(ConfVars.REST_SERVICE_PORT, tajoRestAddress.getPort());
startTajoWorkers(numSlaves);
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ha/TestHAServiceHDFSImpl.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ha/TestHAServiceHDFSImpl.java b/tajo-core/src/test/java/org/apache/tajo/ha/TestHAServiceHDFSImpl.java
index 7c91e22..6415588 100644
--- a/tajo-core/src/test/java/org/apache/tajo/ha/TestHAServiceHDFSImpl.java
+++ b/tajo-core/src/test/java/org/apache/tajo/ha/TestHAServiceHDFSImpl.java
@@ -108,6 +108,8 @@ public class TestHAServiceHDFSImpl {
masterAddress + ":" + NetUtils.getFreeSocketPort());
conf.setVar(TajoConf.ConfVars.TAJO_MASTER_INFO_ADDRESS,
masterAddress + ":" + NetUtils.getFreeSocketPort());
+ conf.setIntVar(TajoConf.ConfVars.REST_SERVICE_PORT,
+ NetUtils.getFreeSocketPort());
conf.setBoolVar(TajoConf.ConfVars.TAJO_MASTER_HA_ENABLE, true);
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/RestTestUtils.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/RestTestUtils.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/RestTestUtils.java
new file mode 100644
index 0000000..e0d9db3
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/RestTestUtils.java
@@ -0,0 +1,64 @@
+/**
+ * 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.lang.reflect.Type;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.json.FunctionAdapter;
+import org.apache.tajo.catalog.json.TableMetaAdapter;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.function.Function;
+import org.apache.tajo.json.ClassNameSerializer;
+import org.apache.tajo.json.DataTypeAdapter;
+import org.apache.tajo.json.DatumAdapter;
+import org.apache.tajo.json.GsonSerDerAdapter;
+import org.apache.tajo.json.PathSerializer;
+import org.apache.tajo.json.TimeZoneGsonSerdeAdapter;
+import org.apache.tajo.plan.expr.EvalNode;
+import org.apache.tajo.plan.function.AggFunction;
+import org.apache.tajo.plan.function.GeneralFunction;
+import org.apache.tajo.plan.logical.LogicalNode;
+import org.apache.tajo.plan.serder.EvalNodeAdapter;
+import org.apache.tajo.plan.serder.LogicalNodeAdapter;
+import org.apache.tajo.util.TUtil;
+
+public class RestTestUtils {
+
+ public static Map<Type, GsonSerDerAdapter<?>> registerTypeAdapterMap() {
+ Map<Type, GsonSerDerAdapter<?>> adapters = TUtil.newHashMap();
+ adapters.put(Path.class, new PathSerializer());
+ adapters.put(Class.class, new ClassNameSerializer());
+ adapters.put(LogicalNode.class, new LogicalNodeAdapter());
+ adapters.put(EvalNode.class, new EvalNodeAdapter());
+ adapters.put(TableMeta.class, new TableMetaAdapter());
+ adapters.put(Function.class, new FunctionAdapter());
+ adapters.put(GeneralFunction.class, new FunctionAdapter());
+ adapters.put(AggFunction.class, new FunctionAdapter());
+ adapters.put(Datum.class, new DatumAdapter());
+ adapters.put(DataType.class, new DataTypeAdapter());
+ adapters.put(TimeZone.class, new TimeZoneGsonSerdeAdapter());
+
+ return adapters;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestClusterResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestClusterResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestClusterResource.java
new file mode 100644
index 0000000..c572eee
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestClusterResource.java
@@ -0,0 +1,84 @@
+/**
+ * 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.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.GenericType;
+
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestClusterResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI clusterURI;
+ private Client restClient;
+
+ public TestClusterResource() {
+ super(TajoConstants.DEFAULT_DATABASE_NAME);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ clusterURI = new URI(restServiceURI + "/cluster");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ @Test
+ public void testGetCluster() throws Exception {
+ Map<String, List<Object>> workerMap =
+ restClient.target(clusterURI)
+ .request().get(new GenericType<Map<String, List<Object>>>(Map.class));
+
+ assertNotNull(workerMap);
+ assertFalse(workerMap.isEmpty());
+ assertNotNull(workerMap.get("workers"));
+
+ List<Object> workerList = workerMap.get("workers");
+
+ assertTrue(workerList.size() > 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestDatabasesResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestDatabasesResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestDatabasesResource.java
new file mode 100644
index 0000000..59c53f1
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestDatabasesResource.java
@@ -0,0 +1,189 @@
+/**
+ * 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.Collection;
+import java.util.Map;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.apache.tajo.ws.rs.requests.NewDatabaseRequest;
+import org.apache.tajo.ws.rs.responses.DatabaseInfoResponse;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestDatabasesResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI databasesURI;
+ private Client restClient;
+
+ public TestDatabasesResource() {
+ super(TajoConstants.DEFAULT_DATABASE_NAME);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ databasesURI = new URI(restServiceURI + "/databases");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ @Test
+ public void testGetAllDatabases() throws Exception {
+ Map<String, Collection<String>> databaseNames = restClient.target(databasesURI)
+ .request().get(new GenericType<Map<String, Collection<String>>>(Map.class));
+
+ assertNotNull(databaseNames);
+ assertFalse(databaseNames.isEmpty());
+ assertNotNull(databaseNames.get("databases"));
+
+ Collection<String> databaseNamesCollection = databaseNames.get("databases");
+
+ assertTrue(databaseNamesCollection.contains(TajoConstants.DEFAULT_DATABASE_NAME));
+ }
+
+ @Test
+ public void testCreateDatabase() throws Exception {
+ String databaseName = "TestDatabasesResource";
+ NewDatabaseRequest request = new NewDatabaseRequest();
+
+ request.setDatabaseName(databaseName);
+
+ Response response = restClient.target(databasesURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+
+ Map<String, Collection<String>> databaseNames = restClient.target(databasesURI)
+ .request().get(new GenericType<Map<String, Collection<String>>>(Map.class));
+
+ assertNotNull(databaseNames);
+ assertFalse(databaseNames.isEmpty());
+ assertNotNull(databaseNames.get("databases"));
+
+ Collection<String> databaseNamesCollection = databaseNames.get("databases");
+
+ assertTrue(databaseNamesCollection.contains(databaseName));
+ }
+
+ @Test
+ public void testCreateDatabaseBadRequest() throws Exception {
+ NewDatabaseRequest request = new NewDatabaseRequest();
+
+ Response response = restClient.target(databasesURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testGetDatabase() throws Exception {
+ DatabaseInfoResponse response =
+ restClient.target(databasesURI).path("/{databaseName}")
+ .resolveTemplate("databaseName", TajoConstants.DEFAULT_DATABASE_NAME)
+ .request().get(new GenericType<DatabaseInfoResponse>(DatabaseInfoResponse.class));
+
+ assertNotNull(response);
+ assertEquals(TajoConstants.DEFAULT_DATABASE_NAME, response.getName());
+ assertTrue(response.getTablespace() != null && !response.getTablespace().isEmpty());
+ }
+
+ @Test
+ public void testGetDatabaseNotFound() throws Exception {
+ Response response =
+ restClient.target(databasesURI).path("/{databaseName}")
+ .resolveTemplate("databaseName", "testGetDatabaseNotFound")
+ .request().get();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testDropDatabase() throws Exception {
+ String databaseName = "TestDropDatabase";
+ NewDatabaseRequest request = new NewDatabaseRequest();
+
+ request.setDatabaseName(databaseName);
+
+ Response response = restClient.target(databasesURI)
+ .request().post(Entity.entity(request, MediaType.APPLICATION_JSON));
+
+ assertNotNull(response);
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+
+ Map<String, Collection<String>> databaseNames = restClient.target(databasesURI)
+ .request().get(new GenericType<Map<String, Collection<String>>>(Map.class));
+
+ assertNotNull(databaseNames);
+ assertFalse(databaseNames.isEmpty());
+ assertNotNull(databaseNames.get("databases"));
+
+ Collection<String> databaseNamesCollection = databaseNames.get("databases");
+
+ assertTrue(databaseNamesCollection.contains(databaseName));
+
+ response = restClient.target(databasesURI)
+ .path("/{databaseName}").resolveTemplate("databaseName", databaseName)
+ .request().delete();
+
+ assertNotNull(response);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testDropDatabaseNotFound() throws Exception {
+ Response response = restClient.target(databasesURI)
+ .path("/{databaseName}").resolveTemplate("databaseName", "TestDropDatabaseNotFound")
+ .request().delete();
+
+ assertNotNull(response);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/32b524d7/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestFunctionsResource.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestFunctionsResource.java b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestFunctionsResource.java
new file mode 100644
index 0000000..2794ded
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/ws/rs/resources/TestFunctionsResource.java
@@ -0,0 +1,78 @@
+/**
+ * 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.List;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.GenericType;
+
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.function.FunctionSignature;
+import org.apache.tajo.ws.rs.netty.gson.GsonFeature;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.filter.LoggingFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestFunctionsResource extends QueryTestCaseBase {
+
+ private URI restServiceURI;
+ private URI functionsURI;
+ private Client restClient;
+
+ public TestFunctionsResource() {
+ super(TajoConstants.DEFAULT_DATABASE_NAME);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ int restPort = testBase.getTestingCluster().getConfiguration().getIntVar(ConfVars.REST_SERVICE_PORT);
+ restServiceURI = new URI("http", null, "127.0.0.1", restPort, "/rest", null, null);
+ functionsURI = new URI(restServiceURI + "/databases/" + TajoConstants.DEFAULT_DATABASE_NAME + "/functions");
+ restClient = ClientBuilder.newBuilder()
+ .register(new GsonFeature(RestTestUtils.registerTypeAdapterMap()))
+ .register(LoggingFilter.class)
+ .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
+ .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ restClient.close();
+ }
+
+ @Test
+ public void testGetAllFunctions() throws Exception {
+ List<FunctionSignature> functionSignatures =
+ restClient.target(functionsURI)
+ .request().get(new GenericType<List<FunctionSignature>>(List.class));
+
+ assertNotNull(functionSignatures);
+ assertTrue(functionSignatures.size() > 0);
+ }
+}
[10/10] tajo git commit: Merge branch 'index_support' of
https://git-wip-us.apache.org/repos/asf/tajo into index_support
Posted by ji...@apache.org.
Merge branch 'index_support' of https://git-wip-us.apache.org/repos/asf/tajo into index_support
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/62fd83bc
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/62fd83bc
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/62fd83bc
Branch: refs/heads/index_support
Commit: 62fd83bc92a7d33e22620cf0d03f66cc06b249f6
Parents: 37b2abb 79b3cb2
Author: Jihoon Son <ji...@apache.org>
Authored: Mon Apr 6 13:42:53 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Mon Apr 6 13:42:53 2015 +0900
----------------------------------------------------------------------
----------------------------------------------------------------------