You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2015/08/04 03:31:26 UTC
[1/4] tajo git commit: TAJO-1699: Tajo Java Client version 2.
Repository: tajo
Updated Branches:
refs/heads/master d8ce56263 -> 4253f1b60
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
index 7f402a1..366d8ed 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
@@ -22,16 +22,15 @@ package org.apache.tajo.engine.function;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
import static org.apache.tajo.common.TajoDataTypes.Type.*;
public class TestStringOperatorsAndFunctions extends ExprTestBase {
@Test
- public void testConcatenateOnLiteral() throws IOException {
+ public void testConcatenateOnLiteral() throws TajoException {
testSimpleEval("select ('abc' || 'def') col1 ", new String[]{"abcdef"});
testSimpleEval("select 'abc' || 'def' as col1 ", new String[]{"abcdef"});
testSimpleEval("select 1 || 'def' as col1 ", new String[]{"1def"});
@@ -39,7 +38,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testConcatenateOnExpressions() throws IOException {
+ public void testConcatenateOnExpressions() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TEXT);
schema.addColumn("col2", INT4);
@@ -52,7 +51,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testFunctionCallIngoreCases() throws IOException {
+ public void testFunctionCallIngoreCases() throws TajoException {
testSimpleEval("select ltrim(' trim') ", new String[]{"trim"});
testSimpleEval("select LTRIM(' trim') ", new String[]{"trim"});
testSimpleEval("select lTRim(' trim') ", new String[]{"trim"});
@@ -60,7 +59,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testLTrim() throws IOException {
+ public void testLTrim() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TEXT);
schema.addColumn("col2", TEXT);
@@ -81,7 +80,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testRTrim() throws IOException {
+ public void testRTrim() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TEXT);
schema.addColumn("col2", TEXT);
@@ -102,7 +101,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testTrim() throws IOException {
+ public void testTrim() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TEXT);
schema.addColumn("col2", TEXT);
@@ -123,7 +122,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testRegexReplace() throws IOException {
+ public void testRegexReplace() throws TajoException {
testSimpleEval("select regexp_replace('abcdef','bc','--') as col1 ", new String[]{"a--def"});
// null test
@@ -148,7 +147,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testLeft() throws IOException {
+ public void testLeft() throws TajoException {
testSimpleEval("select left('abcdef',1) as col1 ", new String[]{"a"});
testSimpleEval("select left('abcdef',2) as col1 ", new String[]{"ab"});
testSimpleEval("select left('abcdef',3) as col1 ", new String[]{"abc"});
@@ -177,7 +176,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testRight() throws IOException {
+ public void testRight() throws TajoException {
testSimpleEval("select right('abcdef',1) as col1 ", new String[]{"f"});
testSimpleEval("select right('abcdef',2) as col1 ", new String[]{"ef"});
testSimpleEval("select right('abcdef',3) as col1 ", new String[]{"def"});
@@ -206,7 +205,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testReverse() throws IOException {
+ public void testReverse() throws TajoException {
testSimpleEval("select reverse('abcdef') as col1 ", new String[]{"fedcba"});
testSimpleEval("select reverse('가') as col1 ", new String[]{"가"});
@@ -219,7 +218,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testRepeat() throws IOException {
+ public void testRepeat() throws TajoException {
testSimpleEval("select repeat('ab',4) as col1 ", new String[]{"abababab"});
testSimpleEval("select repeat('가',3) as col1 ", new String[]{"가가가"});
testSimpleEval("select repeat('a',2) as col1 ", new String[]{"aa"});
@@ -233,7 +232,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
@Test
- public void testUpper() throws IOException {
+ public void testUpper() throws TajoException {
testSimpleEval("select upper('abcdef') as col1 ", new String[]{"ABCDEF"});
Schema schema = new Schema();
@@ -246,7 +245,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testLower() throws IOException {
+ public void testLower() throws TajoException {
testSimpleEval("select lower('ABCdEF') as col1 ", new String[]{"abcdef"});
Schema schema = new Schema();
@@ -259,7 +258,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testCharLength() throws IOException {
+ public void testCharLength() throws TajoException {
testSimpleEval("select char_length('123456') as col1 ", new String[]{"6"});
Schema schema = new Schema();
@@ -271,7 +270,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testLength() throws IOException {
+ public void testLength() throws TajoException {
testSimpleEval("select length('123456') as col1 ", new String[]{"6"});
Schema schema = new Schema();
@@ -283,7 +282,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testMd5() throws IOException {
+ public void testMd5() throws TajoException {
testSimpleEval("select md5('1') as col1 ", new String[]{"c4ca4238a0b923820dcc509a6f75849b"});
testSimpleEval("select md5('tajo') as col1 ", new String[]{"742721b3a79f71a9491681b8e8a7ce85"});
@@ -296,7 +295,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testDigest() throws IOException {
+ public void testDigest() throws TajoException {
testSimpleEval("select digest('tajo', 'md2') as col1 ", new String[]{"bf523bce8241982f6bea9af0f7fd37ff"});
testSimpleEval("select digest('tajo', 'md5') as col1 ", new String[]{"742721b3a79f71a9491681b8e8a7ce85"});
testSimpleEval("select digest('tajo', 'sha1') as col1 ", new String[]{"02b0e20540b89f0b735092bbac8093eb2e3804cf"});
@@ -310,7 +309,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testHex() throws IOException {
+ public void testHex() throws TajoException {
testSimpleEval("select to_hex(1) as col1 ", new String[]{"1"});
testSimpleEval("select to_hex(10) as col1 ", new String[]{"a"});
testSimpleEval("select to_hex(1234) as col1 ", new String[]{"4d2"});
@@ -325,7 +324,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testBin() throws IOException {
+ public void testBin() throws TajoException {
testSimpleEval("select to_bin(1) as col1 ", new String[]{"1"});
testSimpleEval("select to_bin(10) as col1 ", new String[]{"1010"});
testSimpleEval("select to_bin(1234) as col1 ", new String[]{"10011010010"});
@@ -339,7 +338,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testOctetLength() throws IOException {
+ public void testOctetLength() throws TajoException {
testSimpleEval("select octet_length('123456') as col1 ", new String[]{"6"});
testSimpleEval("select octet_length('1') as col1 ", new String[]{"1"});
testSimpleEval("select octet_length('가') as col1 ", new String[]{"3"});
@@ -353,7 +352,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testSplitPart() throws IOException {
+ public void testSplitPart() throws TajoException {
testSimpleEval("select split_part('1386577650.123', '.', 1) as col1 ", new String[]{"1386577650"});
testSimpleEval("select split_part('1386577650.123', '.', 2) as col1 ", new String[]{"123"});
// If part is larger than the number of string portions, it will returns NULL.
@@ -372,7 +371,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testSubstr() throws IOException {
+ public void testSubstr() throws TajoException {
testSimpleEval("select substr('abcdef', 3, 2) as col1 ", new String[]{"cd"});
testSimpleEval("select substr('abcdef', 3) as col1 ", new String[]{"cdef"});
testSimpleEval("select substr('abcdef', 1, 1) as col1 ", new String[]{"a"});
@@ -398,7 +397,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testLocate() throws IOException {
+ public void testLocate() throws TajoException {
// normal case
testSimpleEval("select locate('abcdef', 'a') as col1 ", new String[]{"1"});
testSimpleEval("select locate('abcdef', 'a', 0) as col1 ", new String[]{"1"});
@@ -447,7 +446,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testBitLength() throws IOException {
+ public void testBitLength() throws TajoException {
testSimpleEval("select bit_length('123456') as col1 ", new String[]{"48"});
Schema schema = new Schema();
@@ -459,7 +458,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testStrpos() throws IOException {
+ public void testStrpos() throws TajoException {
testSimpleEval("select strpos('tajo','jo') as col1 ", new String[]{"3"});
testSimpleEval("select strpos('tajo','') as col1 ", new String[]{"1"});
testSimpleEval("select strpos('tajo','abcdef') as col1 ", new String[]{"0"});
@@ -475,7 +474,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testStrposb() throws IOException {
+ public void testStrposb() throws TajoException {
testSimpleEval("select strposb('tajo','jo') as col1 ", new String[]{"3"});
testSimpleEval("select strposb('tajo','') as col1 ", new String[]{"1"});
testSimpleEval("select strposb('tajo','abcdef') as col1 ", new String[]{"0"});
@@ -491,13 +490,13 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testInitcap() throws IOException {
+ public void testInitcap() throws TajoException {
testSimpleEval("select initcap('hi bro') ", new String[]{"Hi Bro"});
testSimpleEval("select initcap('HI BRO') ", new String[]{"Hi Bro"});
}
@Test
- public void testAscii() throws IOException {
+ public void testAscii() throws TajoException {
testSimpleEval("select ascii('abc') as col1 ", new String[]{"97"});
Schema schema = new Schema();
@@ -510,7 +509,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testChr() throws IOException {
+ public void testChr() throws TajoException {
testSimpleEval("select chr(48) as col1 ", new String[]{"0"});
testSimpleEval("select chr(49) as col1 ", new String[]{"1"});
testSimpleEval("select chr(50) as col1 ", new String[]{"2"});
@@ -524,7 +523,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testLpad() throws IOException {
+ public void testLpad() throws TajoException {
testSimpleEval("select lpad('hi', 5, 'xy') ", new String[]{"xyxhi"});
testSimpleEval("select LPAD('hello', 7, 'xy') ", new String[]{"xyhello"});
testSimpleEval("select LPAD('hello', 3, 'xy') ", new String[]{"hel"});
@@ -534,7 +533,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testRpad() throws IOException {
+ public void testRpad() throws TajoException {
testSimpleEval("select rpad('hi', 5, 'xy') ", new String[]{"hixyx"});
testSimpleEval("select RPAD('hello', 7, 'xy') ", new String[]{"helloxy"});
testSimpleEval("select RPAD('hello', 3, 'xy') ", new String[]{"hel"});
@@ -544,13 +543,13 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testQuote_ident() throws IOException {
+ public void testQuote_ident() throws TajoException {
testSimpleEval("select quote_ident('Foo bar') ", new String[]{"\"Foo bar\""});
testSimpleEval("select QUOTE_IDENT('Tajo Function') ", new String[]{"\"Tajo Function\""});
}
@Test
- public void testEncode() throws IOException {
+ public void testEncode() throws TajoException {
testSimpleEval("select encode('Hello\nworld', 'base64') ", new String[]{"SGVsbG8Kd29ybGQ="});
testSimpleEval("select encode('Hello\nworld', 'hex') ",
new String[]{"0x480x650x6c0x6c0x6f0x0a0x770x6f0x720x6c0x64"});
@@ -562,7 +561,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
@Test
- public void testDecode() throws IOException {
+ public void testDecode() throws TajoException {
testSimpleEval("select decode('SGVsbG8Kd29ybGQ=', 'base64') ",
new String[]{StringEscapeUtils.escapeJava("Hello\nworld")});
testSimpleEval("select decode('0x480x650x6c0x6c0x6f0x0a0x770x6f0x720x6c0x64', 'hex') ",
@@ -574,7 +573,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testFindInSet() throws IOException {
+ public void testFindInSet() throws TajoException {
// abnormal cases
testSimpleEval("select find_in_set('cr','crt') as col1 ", new String[]{"0"}); // there is no matched string
testSimpleEval("select find_in_set('c,r','crt,c,cr,c,def') as col1 ", new String[]{"0"}); // abnormal parameter
@@ -597,7 +596,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testConcat() throws IOException {
+ public void testConcat() throws TajoException {
testSimpleEval("select concat('333', '22') ", new String[]{"33322"});
testSimpleEval("select concat('한글', '22') ", new String[]{"한글22"});
testSimpleEval("select concat(null, '22') ", new String[]{"22"});
@@ -606,7 +605,7 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
- public void testConcat_ws() throws IOException {
+ public void testConcat_ws() throws TajoException {
testSimpleEval("select concat_ws(',', '333', '22') ", new String[]{"333,22"});
testSimpleEval("select concat_ws(',', '한글', '22') ", new String[]{"한글,22"});
testSimpleEval("select concat_ws(',', '22', null) ", new String[]{"22"});
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/query/TestIndexScan.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestIndexScan.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestIndexScan.java
index 75127d2..a255c6d 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestIndexScan.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestIndexScan.java
@@ -23,6 +23,7 @@ import org.apache.tajo.IntegrationTest;
import org.apache.tajo.QueryTestCaseBase;
import org.apache.tajo.SessionVars;
import org.apache.tajo.TajoConstants;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -34,7 +35,7 @@ import java.util.Map;
@Category(IntegrationTest.class)
public class TestIndexScan extends QueryTestCaseBase {
- public TestIndexScan() throws ServiceException, SQLException {
+ public TestIndexScan() throws ServiceException, SQLException, NoSuchSessionVariableException {
super(TajoConstants.DEFAULT_DATABASE_NAME);
Map<String,String> sessionVars = new HashMap<String, String>();
sessionVars.put(SessionVars.INDEX_ENABLED.keyname(), "true");
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
index 4ef5e9b..4fb2d31 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
@@ -31,11 +31,13 @@ import org.apache.tajo.catalog.Column;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.conf.TajoConf.ConfVars;
import org.apache.tajo.datum.Datum;
import org.apache.tajo.datum.Int4Datum;
import org.apache.tajo.datum.TextDatum;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.storage.*;
import org.apache.tajo.util.FileUtil;
import org.apache.tajo.util.KeyValueSet;
@@ -211,7 +213,7 @@ public class TestJoinQuery extends QueryTestCaseBase {
Tuple createTuple(String[] columnDatas);
}
- private static String buildSchemaString(String tableName) throws ServiceException, SQLException {
+ private static String buildSchemaString(String tableName) throws TajoException {
TableDesc desc = client.getTableDesc(tableName);
StringBuffer sb = new StringBuffer();
for (Column column : desc.getSchema().getRootColumns()) {
@@ -226,7 +228,7 @@ public class TestJoinQuery extends QueryTestCaseBase {
return sb.toString();
}
- private static String buildMultifileDDlString(String tableName) throws ServiceException, SQLException {
+ private static String buildMultifileDDlString(String tableName) throws TajoException {
String multiTableName = tableName + "_multifile";
StringBuilder sb = new StringBuilder("create table ").append(multiTableName).append(" (");
sb.append(buildSchemaString(tableName)).append(" )");
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 1adad41..acbc1a8 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
@@ -401,96 +401,6 @@ public class TestTajoJdbc extends QueryTestCaseBase {
}
@Test
- public void testSetStatement() throws Exception {
- assertTrue(TajoStatement.isSetVariableQuery("Set JOIN_TASK_INPUT_SIZE 123"));
- assertTrue(TajoStatement.isSetVariableQuery("SET JOIN_TASK_INPUT_SIZE 123"));
- assertFalse(TajoStatement.isSetVariableQuery("--SET JOIN_TASK_INPUT_SIZE 123"));
-
- String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(),
- DEFAULT_DATABASE_NAME);
-
- Connection conn = DriverManager.getConnection(connUri);
-
- Statement stmt = null;
- ResultSet res = null;
- try {
- stmt = conn.createStatement();
- res = stmt.executeQuery("Set JOIN_TASK_INPUT_SIZE 123");
- assertFalse(res.next());
- ResultSetMetaData rsmd = res.getMetaData();
- assertNotNull(rsmd);
- assertEquals(0, rsmd.getColumnCount());
-
- QueryClient connTajoClient = ((JdbcConnection) stmt.getConnection()).getQueryClient();
- Map<String, String> variables = connTajoClient.getAllSessionVariables();
- String value = variables.get("JOIN_TASK_INPUT_SIZE");
- assertNotNull(value);
- assertEquals("123", value);
-
- res.close();
-
- res = stmt.executeQuery("unset JOIN_TASK_INPUT_SIZE");
- variables = connTajoClient.getAllSessionVariables();
- value = variables.get("JOIN_TASK_INPUT_SIZE");
- assertNull(value);
- } finally {
- if (res != null) {
- res.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- if (conn != null) {
- conn.close();
- }
- }
- }
-
- @Test
- public void testSetPreparedStatement() throws Exception {
- String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(),
- DEFAULT_DATABASE_NAME);
-
- Connection conn = DriverManager.getConnection(connUri);
-
- PreparedStatement stmt = null;
- ResultSet res = null;
- try {
- stmt = conn.prepareStatement("Set JOIN_TASK_INPUT_SIZE 123");
- res = stmt.executeQuery();
- assertFalse(res.next());
- ResultSetMetaData rsmd = res.getMetaData();
- assertNotNull(rsmd);
- assertEquals(0, rsmd.getColumnCount());
-
- QueryClient connTajoClient = ((JdbcConnection) stmt.getConnection()).getQueryClient();
- Map<String, String> variables = connTajoClient.getAllSessionVariables();
- String value = variables.get("JOIN_TASK_INPUT_SIZE");
- assertNotNull(value);
- assertEquals("123", value);
-
- res.close();
- stmt.close();
-
- stmt = conn.prepareStatement("unset JOIN_TASK_INPUT_SIZE");
- res = stmt.executeQuery();
- variables = connTajoClient.getAllSessionVariables();
- value = variables.get("JOIN_TASK_INPUT_SIZE");
- assertNull(value);
- } finally {
- if (res != null) {
- res.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- if (conn != null) {
- conn.close();
- }
- }
- }
-
- @Test
public void testCreateTableWithDateAndTimestamp() throws Exception {
String tableName = CatalogUtil.normalizeIdentifier("testCreateTableWithDateAndTimestamp");
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result
new file mode 100644
index 0000000..ec6b911
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsync.result
@@ -0,0 +1,7 @@
+l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment
+-------------------------------
+1,1,7706,1,17.0,21168.23,0.04,0.02,N,O,1996-03-13,1996-02-12,1996-03-22,DELIVER IN PERSON,TRUCK,egular courts above the
+1,1,7311,2,36.0,45983.16,0.09,0.06,N,O,1996-04-12,1996-02-28,1996-04-20,TAKE BACK RETURN,MAIL,ly final dependencies: slyly bold
+2,2,1191,1,38.0,44694.46,0.0,0.05,N,O,1997-01-28,1997-01-14,1997-02-02,TAKE BACK RETURN,RAIL,ven requests. deposits breach a
+3,2,1798,1,45.0,54058.05,0.06,0.0,R,F,1994-02-02,1994-01-04,1994-02-23,NONE,AIR,ongside of the furiously brave acco
+3,3,6540,2,49.0,46796.47,0.1,0.0,R,F,1993-11-09,1993-12-20,1993-11-24,TAKE BACK RETURN,RAIL, unusual accounts. eve
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result
new file mode 100644
index 0000000..7a51ca3
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryAsyncWithListener.result
@@ -0,0 +1,2 @@
+l_orderkey,?sleep
+-------------------------------
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result
new file mode 100644
index 0000000..ec6b911
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType1.result
@@ -0,0 +1,7 @@
+l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment
+-------------------------------
+1,1,7706,1,17.0,21168.23,0.04,0.02,N,O,1996-03-13,1996-02-12,1996-03-22,DELIVER IN PERSON,TRUCK,egular courts above the
+1,1,7311,2,36.0,45983.16,0.09,0.06,N,O,1996-04-12,1996-02-28,1996-04-20,TAKE BACK RETURN,MAIL,ly final dependencies: slyly bold
+2,2,1191,1,38.0,44694.46,0.0,0.05,N,O,1997-01-28,1997-01-14,1997-02-02,TAKE BACK RETURN,RAIL,ven requests. deposits breach a
+3,2,1798,1,45.0,54058.05,0.06,0.0,R,F,1994-02-02,1994-01-04,1994-02-23,NONE,AIR,ongside of the furiously brave acco
+3,3,6540,2,49.0,46796.47,0.1,0.0,R,F,1993-11-09,1993-12-20,1993-11-24,TAKE BACK RETURN,RAIL, unusual accounts. eve
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result
new file mode 100644
index 0000000..fd79944
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType2.result
@@ -0,0 +1,4 @@
+l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment
+-------------------------------
+3,2,1798,1,45.0,54058.05,0.06,0.0,R,F,1994-02-02,1994-01-04,1994-02-23,NONE,AIR,ongside of the furiously brave acco
+3,3,6540,2,49.0,46796.47,0.1,0.0,R,F,1993-11-09,1993-12-20,1993-11-24,TAKE BACK RETURN,RAIL, unusual accounts. eve
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result
new file mode 100644
index 0000000..5407d9d
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoClientV2/testExecuteQueryType3.result
@@ -0,0 +1,4 @@
+table_name
+-------------------------------
+t1
+t2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
----------------------------------------------------------------------
diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
index 6db1447..b098b16 100644
--- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/JdbcConnection.java
@@ -28,6 +28,8 @@ import org.apache.tajo.client.QueryClient;
import org.apache.tajo.client.TajoClient;
import org.apache.tajo.client.TajoClientImpl;
import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.exception.SQLExceptionUtil;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.jdbc.util.QueryStringDecoder;
import org.apache.tajo.rpc.RpcUtils;
import org.apache.tajo.util.KeyValueSet;
@@ -267,14 +269,18 @@ public class JdbcConnection implements Connection {
@Override
public boolean isValid(int timeout) throws SQLException {
- if (tajoClient.isConnected()) {
- ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;");
- boolean next = resultSet.next();
- boolean valid = next && resultSet.getLong(1) == 1;
- resultSet.close();
- return valid;
- } else {
- return false;
+ try {
+ if (tajoClient.isConnected()) {
+ ResultSet resultSet = tajoClient.executeQueryAndGetResult("SELECT 1;");
+ boolean next = resultSet.next();
+ boolean valid = next && resultSet.getLong(1) == 1;
+ resultSet.close();
+ return valid;
+ } else {
+ return false;
+ }
+ } catch (TajoException e) {
+ throw SQLExceptionUtil.toSQLException(e);
}
}
@@ -357,7 +363,11 @@ public class JdbcConnection implements Connection {
@Override
public void setCatalog(String catalog) throws SQLException {
- tajoClient.selectDatabase(catalog);
+ try {
+ tajoClient.selectDatabase(catalog);
+ } catch (TajoException e) {
+ throw SQLExceptionUtil.toSQLException(e);
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java
----------------------------------------------------------------------
diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java
index fad285c..28b6b3c 100644
--- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/MetaDataTuple.java
@@ -23,6 +23,7 @@ import org.apache.tajo.datum.Datum;
import org.apache.tajo.datum.IntervalDatum;
import org.apache.tajo.datum.NullDatum;
import org.apache.tajo.datum.ProtobufDatum;
+import org.apache.tajo.exception.TajoRuntimeException;
import org.apache.tajo.exception.UnsupportedException;
import org.apache.tajo.storage.Tuple;
import org.apache.tajo.util.datetime.TimeMeta;
@@ -94,7 +95,7 @@ public class MetaDataTuple implements Tuple {
@Override
public void clearOffset() {
- throw new UnsupportedException("clearOffset");
+ throw new UnsupportedException();
}
@Override
@@ -104,12 +105,12 @@ public class MetaDataTuple implements Tuple {
@Override
public void setOffset(long offset) {
- throw new UnsupportedException("setOffset");
+ throw new UnsupportedException();
}
@Override
public long getOffset() {
- throw new UnsupportedException("getOffset");
+ throw new UnsupportedException();
}
@Override
@@ -129,7 +130,7 @@ public class MetaDataTuple implements Tuple {
@Override
public byte [] getBytes(int fieldId) {
- throw new UnsupportedException("BlobDatum");
+ throw new UnsupportedException();
}
@Override
@@ -174,12 +175,12 @@ public class MetaDataTuple implements Tuple {
@Override
public ProtobufDatum getProtobufDatum(int fieldId) {
- throw new UnsupportedException("getProtobufDatum");
+ throw new UnsupportedException();
}
@Override
public IntervalDatum getInterval(int fieldId) {
- throw new UnsupportedException("getInterval");
+ throw new UnsupportedException();
}
@Override
@@ -189,11 +190,11 @@ public class MetaDataTuple implements Tuple {
@Override
public Tuple clone() throws CloneNotSupportedException {
- throw new UnsupportedException("clone");
+ throw new UnsupportedException();
}
@Override
public Datum[] getValues(){
- throw new UnsupportedException("getValues");
+ throw new UnsupportedException();
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 22a4817..5354e60 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
@@ -148,17 +148,9 @@ public class TajoStatement implements Statement {
public ResultSet executeQuery(String sql) throws SQLException {
checkConnection("Can't execute");
return executeSQL(sql);
-
}
protected ResultSet executeSQL(String sql) throws SQLException {
- if (isSetVariableQuery(sql)) {
- return setSessionVariable(tajoClient, sql);
- }
- if (isUnSetVariableQuery(sql)) {
- return unSetSessionVariable(tajoClient, sql);
- }
-
ClientProtos.SubmitQueryResponse response = tajoClient.executeQuery(sql);
SQLExceptionUtil.throwIfError(response.getState());
@@ -187,53 +179,6 @@ public class TajoStatement implements Statement {
}
}
- public static boolean isSetVariableQuery(String sql) {
- if (sql == null || sql.trim().isEmpty()) {
- return false;
- }
-
- return sql.trim().toLowerCase().startsWith("set");
- }
-
- public static boolean isUnSetVariableQuery(String sql) {
- if (sql == null || sql.trim().isEmpty()) {
- return false;
- }
-
- return sql.trim().toLowerCase().startsWith("unset");
- }
-
- private ResultSet setSessionVariable(TajoClient client, String sql) throws SQLException {
- int index = sql.toLowerCase().indexOf("set");
- if (index < 0) {
- throw new SQLException("SET statement should be started 'SET' keyword: " + sql);
- }
-
- String[] tokens = sql.substring(index + 3).trim().split(" ");
- if (tokens.length != 2) {
- throw new SQLException("SET statement should be <KEY> <VALUE>: " + sql);
- }
- Map<String, String> variable = new HashMap<String, String>();
- variable.put(tokens[0].trim(), tokens[1].trim());
- client.updateSessionVariables(variable);
- return NULL_RESULT_SET;
- }
-
- private ResultSet unSetSessionVariable(TajoClient client, String sql) throws SQLException {
- int index = sql.toLowerCase().indexOf("unset");
- if (index < 0) {
- throw new SQLException("UNSET statement should be started 'UNSET' keyword: " + sql);
- }
-
- String key = sql.substring(index + 5).trim();
- if (key.isEmpty()) {
- throw new SQLException("UNSET statement should be <KEY>: " + sql);
- }
- client.unsetSessionVariables(Lists.newArrayList(key));
-
- return NULL_RESULT_SET;
- }
-
@Override
public int executeUpdate(String sql) throws SQLException {
checkConnection("Can't execute update");
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java
index 81b0f8e..128cc7c 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/BasicEvalNodeVisitor.java
@@ -18,6 +18,7 @@
package org.apache.tajo.plan.expr;
+import org.apache.tajo.exception.TajoInternalError;
import org.apache.tajo.exception.UnsupportedException;
import java.util.Stack;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java
index e706391..61a25a9 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/SimpleEvalNodeVisitor.java
@@ -19,6 +19,7 @@
package org.apache.tajo.plan.expr;
import com.google.common.base.Preconditions;
+import org.apache.tajo.exception.TajoInternalError;
import org.apache.tajo.exception.UnsupportedException;
import java.util.Stack;
@@ -76,7 +77,7 @@ public abstract class SimpleEvalNodeVisitor<CONTEXT> {
break;
default:
- throw new UnsupportedException("Unknown EvalType: " + evalNode);
+ throw new TajoInternalError("Unknown EvalType: " + evalNode);
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java
index 78404b0..77f0a03 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/function/stream/CSVLineSerializer.java
@@ -110,7 +110,6 @@ public class CSVLineSerializer extends TextLineSerializer {
@Override
public void release() {
-
}
public static String getTypeString(Datum val) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java
index 392d308..a6f3d35 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java
@@ -149,7 +149,9 @@ public abstract class NameResolver {
* @throws PlanningException
*/
static Column resolveFromRelsWithinBlock(LogicalPlan plan, LogicalPlan.QueryBlock block,
- ColumnReferenceExpr columnRef) throws AmbiguousColumnException {
+ ColumnReferenceExpr columnRef)
+ throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException {
+
String qualifier;
String canonicalName;
@@ -306,7 +308,7 @@ public abstract class NameResolver {
*/
static Pair<String, String> lookupQualifierAndCanonicalName(LogicalPlan.QueryBlock block,
ColumnReferenceExpr columnRef)
- throws AmbiguousColumnException {
+ throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException {
Preconditions.checkArgument(columnRef.hasQualifier(), "ColumnReferenceExpr must be qualified.");
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java
index aa0d7f5..3bbb2be 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByLegacy.java
@@ -99,7 +99,8 @@ public class ResolverByLegacy extends NameResolver {
}
static Column resolveColumnWithoutQualifier(LogicalPlan plan, LogicalPlan.QueryBlock block,
- ColumnReferenceExpr columnRef) throws AmbiguousColumnException {
+ ColumnReferenceExpr columnRef)
+ throws AmbiguousColumnException, UndefinedColumnException {
Column found = lookupColumnFromAllRelsInBlock(block, columnRef.getName());
if (found != null) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java
index fa9fe84..aee131b 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRels.java
@@ -20,7 +20,9 @@ package org.apache.tajo.plan.nameresolver;
import org.apache.tajo.algebra.ColumnReferenceExpr;
import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.exception.AmbiguousTableException;
import org.apache.tajo.catalog.exception.UndefinedColumnException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
import org.apache.tajo.exception.AmbiguousColumnException;
import org.apache.tajo.plan.LogicalPlan;
import org.apache.tajo.plan.PlanningException;
@@ -28,7 +30,7 @@ import org.apache.tajo.plan.PlanningException;
public class ResolverByRels extends NameResolver {
@Override
public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef)
- throws AmbiguousColumnException {
+ throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException {
Column column = resolveFromRelsWithinBlock(plan, block, columnRef);
if (column == null) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java
index cafba7d..560ae50 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverByRelsAndSubExprs.java
@@ -20,7 +20,9 @@ package org.apache.tajo.plan.nameresolver;
import org.apache.tajo.algebra.ColumnReferenceExpr;
import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.exception.AmbiguousTableException;
import org.apache.tajo.catalog.exception.UndefinedColumnException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
import org.apache.tajo.exception.AmbiguousColumnException;
import org.apache.tajo.plan.LogicalPlan;
import org.apache.tajo.plan.PlanningException;
@@ -28,7 +30,7 @@ import org.apache.tajo.plan.PlanningException;
public class ResolverByRelsAndSubExprs extends NameResolver {
@Override
public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef)
- throws AmbiguousColumnException {
+ throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException {
Column column = resolveFromRelsWithinBlock(plan, block, columnRef);
if (column == null) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java
index c16bbe2..39458ec 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/ResolverBySubExprsAndRels.java
@@ -20,7 +20,9 @@ package org.apache.tajo.plan.nameresolver;
import org.apache.tajo.algebra.ColumnReferenceExpr;
import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.exception.AmbiguousTableException;
import org.apache.tajo.catalog.exception.UndefinedColumnException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
import org.apache.tajo.exception.AmbiguousColumnException;
import org.apache.tajo.plan.LogicalPlan;
import org.apache.tajo.plan.PlanningException;
@@ -28,7 +30,7 @@ import org.apache.tajo.plan.PlanningException;
public class ResolverBySubExprsAndRels extends NameResolver {
@Override
public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef)
- throws AmbiguousColumnException{
+ throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException {
Column column = resolveFromCurrentAndChildNode(block, columnRef);
if (column == null) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
index 78a5dad..18e001e 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
@@ -21,7 +21,6 @@ package org.apache.tajo.plan.rewrite.rules;
import com.google.common.collect.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.tajo.OverridableConf;
import org.apache.tajo.annotation.Nullable;
import org.apache.tajo.catalog.Column;
import org.apache.tajo.catalog.Schema;
@@ -197,7 +196,7 @@ public class ProjectionPushDownRule extends
* Add an expression with a specified name, which is usually an alias.
* Later, you can refer this expression by the specified name.
*/
- private String add(String specifiedName, EvalNode evalNode) {
+ private String add(String specifiedName, EvalNode evalNode) throws DuplicateColumnException {
// if a name already exists, it only just keeps an actual
// expression instead of a column reference.
@@ -255,7 +254,7 @@ public class ProjectionPushDownRule extends
* Adds an expression without any name. It returns an automatically
* generated name. It can be also used for referring this expression.
*/
- public String add(EvalNode evalNode) {
+ public String add(EvalNode evalNode) throws DuplicateColumnException {
String name;
if (evalNode.getType() == EvalType.FIELD) {
@@ -285,7 +284,7 @@ public class ProjectionPushDownRule extends
return nameToIdBiMap.keySet();
}
- public String add(Target target) {
+ public String add(Target target) throws DuplicateColumnException {
return add(target.getCanonicalName(), target.getEvalTree());
}
@@ -421,13 +420,13 @@ public class ProjectionPushDownRule extends
targetListMgr = upperContext.targetListMgr;
}
- public String addExpr(Target target) {
+ public String addExpr(Target target) throws DuplicateColumnException {
String reference = targetListMgr.add(target);
addNecessaryReferences(target.getEvalTree());
return reference;
}
- public String addExpr(EvalNode evalNode) {
+ public String addExpr(EvalNode evalNode) throws DuplicateColumnException {
String reference = targetListMgr.add(evalNode);
addNecessaryReferences(evalNode);
return reference;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java
index 05f95df..73a07d5 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/EvalNodeDeserializer.java
@@ -33,6 +33,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.FunctionSignatureProto;
import org.apache.tajo.common.TajoDataTypes.DataType;
import org.apache.tajo.datum.*;
import org.apache.tajo.exception.InternalException;
+import org.apache.tajo.exception.TajoInternalError;
import org.apache.tajo.plan.expr.*;
import org.apache.tajo.plan.function.python.PythonScriptEngine;
import org.apache.tajo.plan.logical.WindowSpec;
@@ -237,10 +238,10 @@ public class EvalNodeDeserializer {
parameterTypes = funcSignatureProto.getParameterTypesList().toArray(
new DataType[funcSignatureProto.getParameterTypesCount()]);
}
- throw new UndefinedFunctionException(functionName, parameterTypes);
+ throw new TajoInternalError(new UndefinedFunctionException(functionName, parameterTypes));
}
} else {
- throw new RuntimeException("Unknown EvalType: " + type.name());
+ throw new TajoInternalError("Unknown EvalType: " + type.name());
}
evalNodeMap.put(protoNode.getId(), current);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java b/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java
index d20f8f9..fd16d11 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/VerificationState.java
@@ -21,6 +21,7 @@ package org.apache.tajo.plan.verifier;
import com.google.common.collect.Lists;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.exception.TajoError;
import org.apache.tajo.exception.TajoException;
import org.apache.tajo.exception.TajoExceptionInterface;
import org.apache.tajo.exception.TajoRuntimeException;
@@ -32,6 +33,11 @@ public class VerificationState {
private static final Log LOG = LogFactory.getLog(VerificationState.class);
List<Throwable> errorMessages = Lists.newArrayList();
+ public void addVerification(TajoError error) {
+ LOG.warn(TUtil.getCurrentCodePoint(1) + " causes: " + error.getMessage());
+ errorMessages.add(error);
+ }
+
public void addVerification(TajoException error) {
LOG.warn(TUtil.getCurrentCodePoint(1) + " causes: " + error.getMessage());
errorMessages.add(error);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java
index 83d8e24..46b1726 100644
--- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java
+++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/NullScanner.java
@@ -1,4 +1,4 @@
-package org.apache.tajo.storage; /**
+/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,6 +16,8 @@ package org.apache.tajo.storage; /**
* limitations under the License.
*/
+package org.apache.tajo.storage;
+
import org.apache.hadoop.conf.Configuration;
import org.apache.tajo.catalog.Column;
import org.apache.tajo.catalog.Schema;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java
index 51cedb2..bfe4e55 100644
--- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java
+++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/RowStoreUtil.java
@@ -381,7 +381,7 @@ public class RowStoreUtil {
writer.skipField();
break;
default:
- throw new UnsupportedException("Unknown data type: " + writer.dataTypes()[i]);
+ throw new UnsupportedException("data type " + writer.dataTypes()[i]);
}
}
writer.endRow();
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java
index 4d7fac4..968601c 100644
--- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java
+++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/storage/Tablespace.java
@@ -107,8 +107,7 @@ public abstract class Tablespace {
* @return Root URI
*/
public URI getRootUri() {
- throw new UnsupportedException(
- String.format("Tablespace '%s' does not allow the use of artibrary paths", uri.toString()));
+ throw new UnsupportedException(String.format("artibrary path '%s'", uri.toString()));
}
/**
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java
index 8f36b35..97be316 100644
--- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java
+++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/HeapTuple.java
@@ -20,7 +20,6 @@ package org.apache.tajo.tuple.offheap;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
-
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.datum.*;
import org.apache.tajo.exception.UnsupportedException;
@@ -29,7 +28,6 @@ import org.apache.tajo.storage.VTuple;
import org.apache.tajo.util.SizeOf;
import org.apache.tajo.util.StringUtils;
import org.apache.tajo.util.UnsafeUtil;
-
import org.apache.tajo.util.datetime.TimeMeta;
import sun.misc.Unsafe;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java
index fd427ca..167519b 100644
--- a/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java
+++ b/tajo-storage/tajo-storage-common/src/main/java/org/apache/tajo/tuple/offheap/UnSafeTuple.java
@@ -21,7 +21,6 @@ package org.apache.tajo.tuple.offheap;
import com.google.common.base.Preconditions;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
-
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.datum.*;
import org.apache.tajo.exception.UnsupportedException;
@@ -30,7 +29,6 @@ import org.apache.tajo.storage.VTuple;
import org.apache.tajo.util.SizeOf;
import org.apache.tajo.util.StringUtils;
import org.apache.tajo.util.UnsafeUtil;
-
import org.apache.tajo.util.datetime.TimeMeta;
import sun.misc.Unsafe;
import sun.nio.ch.DirectBuffer;
[2/4] tajo git commit: TAJO-1699: Tajo Java Client version 2.
Posted by hy...@apache.org.
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 89e0a66..19eba3e 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
@@ -33,6 +33,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto;
import org.apache.tajo.catalog.proto.CatalogProtos.PartitionKeyProto;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.exception.TajoInternalError;
import org.apache.tajo.master.TajoMaster;
import org.apache.tajo.plan.LogicalPlan;
@@ -69,8 +70,10 @@ public class DDLExecutor {
public CreateTableExecutor getCreateTableExecutor() {
return createTableExecutor;
}
+
+ public boolean execute(QueryContext queryContext, LogicalPlan plan)
+ throws IOException, TajoException {
- public boolean execute(QueryContext queryContext, LogicalPlan plan) throws IOException {
LogicalNode root = ((LogicalRootNode) plan.getRootBlock().getRoot()).getChild();
switch (root.getType()) {
@@ -124,7 +127,9 @@ public class DDLExecutor {
}
}
- public void createIndex(final QueryContext queryContext, final CreateIndexNode createIndexNode) {
+ public void createIndex(final QueryContext queryContext, final CreateIndexNode createIndexNode)
+ throws DuplicateIndexException {
+
String databaseName, simpleIndexName, qualifiedIndexName;
if (CatalogUtil.isFQTableName(createIndexNode.getIndexName())) {
String[] splits = CatalogUtil.splitFQTableName(createIndexNode.getIndexName());
@@ -159,7 +164,9 @@ public class DDLExecutor {
}
}
- public void dropIndex(final QueryContext queryContext, final DropIndexNode dropIndexNode) {
+ public void dropIndex(final QueryContext queryContext, final DropIndexNode dropIndexNode)
+ throws UndefinedIndexException {
+
String databaseName, simpleIndexName;
if (CatalogUtil.isFQTableName(dropIndexNode.getIndexName())) {
String[] splits = CatalogUtil.splitFQTableName(dropIndexNode.getIndexName());
@@ -223,7 +230,7 @@ public class DDLExecutor {
//--------------------------------------------------------------------------
public boolean createDatabase(@Nullable QueryContext queryContext, String databaseName,
@Nullable String tablespace,
- boolean ifNotExists) throws IOException {
+ boolean ifNotExists) throws IOException, DuplicateDatabaseException {
String tablespaceName;
if (tablespace == null) {
@@ -253,7 +260,9 @@ public class DDLExecutor {
return true;
}
- public boolean dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) {
+ public boolean dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists)
+ throws UndefinedDatabaseException {
+
boolean exists = catalog.existDatabase(databaseName);
if (!exists) {
if (ifExists) { // DROP DATABASE IF EXISTS
@@ -284,7 +293,8 @@ public class DDLExecutor {
* @param tableName to be dropped
* @param purge Remove all data if purge is true.
*/
- public boolean dropTable(QueryContext queryContext, String tableName, boolean ifExists, boolean purge) {
+ public boolean dropTable(QueryContext queryContext, String tableName, boolean ifExists, boolean purge)
+ throws UndefinedTableException {
String databaseName;
String simpleTableName;
@@ -327,7 +337,8 @@ public class DDLExecutor {
* Truncate table a given table
*/
public void truncateTable(final QueryContext queryContext, final TruncateTableNode truncateTableNode)
- throws IOException {
+ throws IOException, UndefinedTableException {
+
List<String> tableNames = truncateTableNode.getTableNames();
final CatalogService catalog = context.getCatalog();
@@ -385,7 +396,10 @@ public class DDLExecutor {
* @throws IOException
*/
public void alterTable(TajoMaster.MasterContext context, final QueryContext queryContext,
- final AlterTableNode alterTable) throws IOException {
+ final AlterTableNode alterTable)
+ throws IOException, UndefinedTableException, DuplicateTableException, DuplicateColumnException,
+ DuplicatePartitionException, UndefinedPartitionException, UndefinedPartitionKeyException, AmbiguousPartitionDirectoryExistException {
+
final CatalogService catalog = context.getCatalog();
final String tableName = alterTable.getTableName();
@@ -548,8 +562,10 @@ public class DDLExecutor {
}
}
- private boolean ensureColumnPartitionKeys(String tableName, String[] columnNames) {
- for (String columnName : columnNames) {
+ private boolean ensureColumnPartitionKeys(String tableName, String[] columnNames)
+ throws UndefinedPartitionKeyException {
+
+ for(String columnName : columnNames) {
if (!ensureColumnPartitionKeys(tableName, columnName)) {
throw new UndefinedPartitionKeyException(columnName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 e7fc4d2..3f65831 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
@@ -529,7 +529,8 @@ public class QueryExecutor {
}
private void checkIndexExistence(final QueryContext queryContext, final CreateIndexNode createIndexNode)
- throws IOException {
+ throws DuplicateIndexException {
+
String databaseName, simpleIndexName, qualifiedIndexName;
if (CatalogUtil.isFQTableName(createIndexNode.getIndexName())) {
String[] splits = CatalogUtil.splitFQTableName(createIndexNode.getIndexName());
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java b/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java
index 54c65bf..5aedffb 100644
--- a/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java
+++ b/tajo-core/src/main/java/org/apache/tajo/session/InvalidSessionException.java
@@ -18,8 +18,11 @@
package org.apache.tajo.session;
-public class InvalidSessionException extends Exception {
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoRuntimeException;
+
+public class InvalidSessionException extends TajoRuntimeException {
public InvalidSessionException(String sessionId) {
- super("Invalid session id \"" + sessionId + "\"");
+ super(Errors.ResultCode.INVALID_SESSION, sessionId);
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
index 24534b0..630b1e9 100644
--- a/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
+++ b/tajo-core/src/main/java/org/apache/tajo/webapp/QueryExecutorServlet.java
@@ -360,7 +360,7 @@ public class QueryExecutorServlet extends HttpServlet {
if (queryId != null) {
try {
tajoClient.closeQuery(queryId);
- } catch (SQLException e) {
+ } catch (Throwable e) {
LOG.warn(e);
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java b/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
index eae9e8c..f084138 100644
--- a/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
+++ b/tajo-core/src/test/java/org/apache/tajo/LocalTajoTestingUtility.java
@@ -19,7 +19,6 @@
package org.apache.tajo;
import com.google.common.base.Preconditions;
-import com.google.protobuf.ServiceException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -31,12 +30,12 @@ import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.catalog.TableMeta;
-import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.catalog.statistics.TableStats;
import org.apache.tajo.client.TajoClient;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.engine.planner.global.MasterPlan;
import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.session.Session;
import org.apache.tajo.util.CommonTestingUtil;
import org.apache.tajo.util.FileUtil;
@@ -47,7 +46,6 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.UUID;
public class LocalTajoTestingUtility {
@@ -140,7 +138,7 @@ public class LocalTajoTestingUtility {
return util;
}
- public ResultSet execute(String query) throws IOException, SQLException {
+ public ResultSet execute(String query) throws TajoException {
return client.executeQueryAndGetResult(query);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 b5e464b..ec4796f 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -29,6 +29,8 @@ import org.apache.tajo.annotation.Nullable;
import org.apache.tajo.catalog.CatalogService;
import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
import org.apache.tajo.cli.tsql.ParsedResult;
import org.apache.tajo.cli.tsql.SimpleParser;
import org.apache.tajo.client.TajoClient;
@@ -199,7 +201,7 @@ public class QueryTestCaseBase {
}
@AfterClass
- public static void tearDownClass() throws SQLException {
+ public static void tearDownClass() throws Exception {
for (String tableName : createdTableGlobalSet) {
client.updateQuery("DROP TABLE IF EXISTS " + CatalogUtil.denormalizeIdentifier(tableName));
}
@@ -704,17 +706,17 @@ public class QueryTestCaseBase {
assertTrue(!client.existTable(tableName));
}
- public void assertColumnExists(String tableName,String columnName) throws ServiceException, SQLException {
+ public void assertColumnExists(String tableName,String columnName) throws UndefinedTableException {
TableDesc tableDesc = getTableDesc(tableName);
assertTrue(tableDesc.getSchema().containsByName(columnName));
}
- private TableDesc getTableDesc(String tableName) throws ServiceException, SQLException {
+ private TableDesc getTableDesc(String tableName) throws UndefinedTableException {
return client.getTableDesc(tableName);
}
public void assertTablePropertyEquals(String tableName, String key, String expectedValue)
- throws ServiceException, SQLException {
+ throws UndefinedTableException {
TableDesc tableDesc = getTableDesc(tableName);
assertEquals(expectedValue, tableDesc.getMeta().getOption(key));
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
index d89bca1..0ba0d76 100644
--- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
+++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClient.java
@@ -35,6 +35,9 @@ import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.TajoRuntimeException;
+import org.apache.tajo.exception.UnsupportedException;
import org.apache.tajo.ipc.ClientProtos;
import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto;
import org.apache.tajo.ipc.ClientProtos.QueryInfoProto;
@@ -83,7 +86,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndDropDatabases() throws SQLException {
+ public final void testCreateAndDropDatabases() throws TajoException {
int currentNum = client.getAllDatabaseNames().size();
String prefix = CatalogUtil.normalizeIdentifier("testCreateDatabase_");
@@ -114,7 +117,7 @@ public class TestTajoClient {
}
@Test
- public final void testCurrentDatabase() throws IOException, SQLException, InterruptedException {
+ public final void testCurrentDatabase() throws IOException, TajoException, InterruptedException {
int currentNum = client.getAllDatabaseNames().size();
assertEquals(TajoConstants.DEFAULT_DATABASE_NAME, client.getCurrentDatabase());
@@ -131,7 +134,7 @@ public class TestTajoClient {
}
@Test
- public final void testSelectDatabaseToInvalidOne() throws IOException, SQLException, InterruptedException {
+ public final void testSelectDatabaseToInvalidOne() throws IOException, TajoException, InterruptedException {
int currentNum = client.getAllDatabaseNames().size();
assertFalse(client.existDatabase("invaliddatabase"));
@@ -146,7 +149,7 @@ public class TestTajoClient {
}
@Test
- public final void testDropCurrentDatabase() throws IOException, SQLException, InterruptedException {
+ public final void testDropCurrentDatabase() throws IOException, TajoException, InterruptedException {
int currentNum = client.getAllDatabaseNames().size();
String databaseName = CatalogUtil.normalizeIdentifier("testdropcurrentdatabase");
assertTrue(client.createDatabase(databaseName));
@@ -166,7 +169,7 @@ public class TestTajoClient {
}
@Test
- public final void testSessionVariables() throws IOException, SQLException, InterruptedException {
+ public final void testSessionVariables() throws IOException, TajoException, InterruptedException {
String prefixName = "key_";
String prefixValue = "val_";
@@ -212,7 +215,7 @@ public class TestTajoClient {
}
@Test
- public final void testKillQuery() throws IOException, SQLException, InterruptedException {
+ public final void testKillQuery() throws IOException, TajoException, InterruptedException {
ClientProtos.SubmitQueryResponse res = client.executeQuery("select sleep(1) from lineitem");
Thread.sleep(1000);
QueryId queryId = new QueryId(res.getQueryId());
@@ -221,7 +224,7 @@ public class TestTajoClient {
}
@Test
- public final void testUpdateQuery() throws IOException, SQLException {
+ public final void testUpdateQuery() throws IOException, TajoException {
final String tableName = CatalogUtil.normalizeIdentifier("testUpdateQuery");
Path tablePath = writeTmpTable(tableName);
@@ -236,7 +239,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndDropExternalTable() throws IOException, SQLException {
+ public final void testCreateAndDropExternalTable() throws IOException, TajoException {
final String tableName = "testCreateAndDropExternalTable";
Path tablePath = writeTmpTable(tableName);
LOG.error("Full path:" + tablePath.toUri().getRawPath());
@@ -254,7 +257,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndPurgeExternalTable() throws IOException, SQLException {
+ public final void testCreateAndPurgeExternalTable() throws IOException, TajoException {
final String tableName = "testCreateAndPurgeExternalTable";
Path tablePath = writeTmpTable(tableName);
LOG.error("Full path:" + tablePath.toUri().getRawPath());
@@ -272,7 +275,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndDropExternalTableByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropExternalTableByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndDropExternalTableByExecuteQuery");
@@ -292,7 +295,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndPurgeExternalTableByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndPurgeExternalTableByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndPurgeExternalTableByExecuteQuery");
@@ -312,7 +315,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndDropTableByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropTableByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndDropTableByExecuteQuery");
@@ -333,7 +336,7 @@ public class TestTajoClient {
}
@Test
- public final void testCreateAndPurgeTableByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndPurgeTableByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndPurgeTableByExecuteQuery");
@@ -354,7 +357,7 @@ public class TestTajoClient {
}
@Test
- public final void testDDLByExecuteQuery() throws IOException, SQLException {
+ public final void testDDLByExecuteQuery() throws IOException, TajoException {
final String tableName = CatalogUtil.normalizeIdentifier("testDDLByExecuteQuery");
Path tablePath = writeTmpTable(tableName);
@@ -367,7 +370,7 @@ public class TestTajoClient {
}
@Test
- public final void testGetTableList() throws IOException, SQLException {
+ public final void testGetTableList() throws IOException, TajoException {
String tableName1 = "GetTableList1".toLowerCase();
String tableName2 = "GetTableList2".toLowerCase();
@@ -387,7 +390,7 @@ public class TestTajoClient {
Log LOG = LogFactory.getLog(TestTajoClient.class);
@Test
- public final void testGetTableDesc() throws IOException, SQLException {
+ public final void testGetTableDesc() throws IOException, TajoException {
final String tableName1 = CatalogUtil.normalizeIdentifier("table3");
Path tablePath = writeTmpTable(tableName1);
LOG.error("Full path:" + tablePath.toUri().getRawPath());
@@ -407,7 +410,7 @@ public class TestTajoClient {
}
//@Test
- public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropTablePartitionedHash1ByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = "testCreateAndDropTablePartitionedHash1ByExecuteQuery";
@@ -430,7 +433,7 @@ public class TestTajoClient {
}
//@Test
- public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndPurgeTablePartitionedHash1ByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = "testCreateAndPurgeTablePartitionedHash1ByExecuteQuery";
@@ -453,7 +456,7 @@ public class TestTajoClient {
}
//@Test
- public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropTablePartitionedHash2ByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = "testCreateAndDropTablePartitionedHash2ByExecuteQuery";
@@ -476,7 +479,7 @@ public class TestTajoClient {
}
//@Test
- public final void testCreateAndDropTablePartitionedListByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropTablePartitionedListByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = "testCreateAndDropTablePartitionedListByExecuteQuery";
@@ -500,7 +503,7 @@ public class TestTajoClient {
}
//@Test
- public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropTablePartitionedRangeByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = "testCreateAndDropTablePartitionedRangeByExecuteQuery";
@@ -525,7 +528,7 @@ public class TestTajoClient {
}
@Test
- public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOException, SQLException {
+ public final void testFailCreateTablePartitionedOtherExceptColumn() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = "testFailCreateTablePartitionedOtherExceptColumn";
@@ -540,8 +543,7 @@ public class TestTajoClient {
try {
client.updateQuery(rangeSql);
fail();
- } catch (SQLException se) {
- assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode());
+ } catch (UnsupportedException se) {
}
String listSql = "create table " + tableName + " (deptname text, score int4)";
@@ -552,8 +554,7 @@ public class TestTajoClient {
try {
assertFalse(client.updateQuery(listSql));
fail();
- } catch (SQLException se) {
- assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode());
+ } catch (UnsupportedException se) {
}
String hashSql = "create table " + tableName + " (deptname text, score int4)";
@@ -563,13 +564,12 @@ public class TestTajoClient {
try {
assertFalse(client.updateQuery(hashSql));
fail();
- } catch (SQLException se) {
- assertEquals(Errors.ResultCode.FEATURE_NOT_SUPPORTED.getNumber(), se.getErrorCode());
+ } catch (UnsupportedException se) {
}
}
@Test
- public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() throws IOException, SQLException {
+ public final void testCreateAndDropTablePartitionedColumnByExecuteQuery() throws IOException, TajoException {
TajoConf conf = cluster.getConfiguration();
final String tableName = CatalogUtil.normalizeIdentifier("testCreateAndDropTablePartitionedColumnByExecuteQuery");
@@ -591,7 +591,7 @@ public class TestTajoClient {
}
@Test
- public final void testGetFunctions() throws IOException, SQLException {
+ public final void testGetFunctions() throws IOException, TajoException {
Collection<FunctionDesc> catalogFunctions = cluster.getMaster().getCatalog().getFunctions();
String functionName = "sum";
int numFunctions = 0;
@@ -612,7 +612,7 @@ public class TestTajoClient {
}
@Test
- public final void testGetFinishedQueryList() throws IOException, SQLException {
+ public final void testGetFinishedQueryList() throws SQLException, TajoException {
final String tableName = CatalogUtil.normalizeIdentifier("testGetFinishedQueryList");
String sql = "create table " + tableName + " (deptname text, score int4)";
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
index d43f61c..b745caa 100644
--- a/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
+++ b/tajo-core/src/test/java/org/apache/tajo/client/TestTajoClientFailures.java
@@ -21,7 +21,11 @@ package org.apache.tajo.client;
import net.jcip.annotations.NotThreadSafe;
import org.apache.tajo.TajoTestingCluster;
import org.apache.tajo.TpchTestBase;
+import org.apache.tajo.catalog.exception.DuplicateDatabaseException;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -48,18 +52,18 @@ public class TestTajoClientFailures {
client.close();
}
- @Test
- public final void testCreateDatabase() throws SQLException {
+ @Test(expected = DuplicateDatabaseException.class)
+ public final void testCreateDatabase() throws TajoException {
assertFalse(client.createDatabase("default")); // duplicate database
}
- @Test
- public final void testDropDatabase() throws SQLException {
+ @Test(expected = UndefinedDatabaseException.class)
+ public final void testDropDatabase() throws TajoException {
assertFalse(client.dropDatabase("unknown-database")); // unknown database
}
- @Test
- public final void testDropTable() throws SQLException {
+ @Test(expected = UndefinedTableException.class)
+ public final void testDropTable() throws UndefinedTableException {
assertFalse(client.dropTable("unknown-table")); // unknown table
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java
new file mode 100644
index 0000000..99b7c15
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/client/v2/TestTajoClientV2.java
@@ -0,0 +1,236 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import com.facebook.presto.hive.shaded.com.google.common.collect.Lists;
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.catalog.exception.DuplicateDatabaseException;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.service.ServiceTracker;
+import org.apache.tajo.service.ServiceTrackerFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.*;
+
+public class TestTajoClientV2 extends QueryTestCaseBase {
+ private static TajoClient clientv2;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ conf = testingCluster.getConfiguration();
+
+ clientv2 = new TajoClient(new ServiceDiscovery() {
+ ServiceTracker tracker = ServiceTrackerFactory.get(conf);
+ @Override
+ public InetSocketAddress clientAddress() {
+ return tracker.getClientServiceAddress();
+ }
+ });
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ clientv2.close();
+ }
+
+ @Test
+ public void testExecuteUpdate() throws TajoException {
+ clientv2.executeUpdate("create database tajoclientv2");
+ clientv2.selectDB("tajoclientv2");
+ clientv2.selectDB("default");
+ clientv2.executeUpdate("drop database tajoclientv2");
+
+ try {
+ clientv2.selectDB("tajoclientv2");
+ fail();
+ } catch (UndefinedDatabaseException e) {
+ }
+ }
+
+ @Test
+ public void testExecuteQueryType1() throws TajoException, IOException, SQLException {
+ ResultSet res = null;
+ try {
+ res = clientv2.executeQuery("select * from lineitem");
+ assertResultSet(res);
+ } finally {
+ if (res != null) {
+ res.close();
+ }
+ }
+ }
+
+ @Test
+ public void testExecuteQueryType2() throws TajoException, IOException, SQLException {
+ ResultSet res = null;
+ try {
+ res = clientv2.executeQuery("select * from lineitem where l_orderkey > 2");
+ assertResultSet(res);
+ } finally {
+ if (res != null) {
+ res.close();
+ }
+ }
+ }
+
+ @Test
+ public void testExecuteQueryType3() throws TajoException, IOException, SQLException {
+ ResultSet res = null;
+ try {
+ clientv2.executeUpdate("create database client_v2_type3");
+ clientv2.selectDB("client_v2_type3");
+ clientv2.executeUpdate("create table t1 (c1 int)");
+ clientv2.executeUpdate("create table t2 (c2 int)");
+
+ // why we shouldn't use join directly on virtual tables? Currently, join on virtual tables is not supported.
+ res = clientv2.executeQuery("select db_id from information_schema.databases where db_name = 'client_v2_type3'");
+ assertTrue(res.next());
+ int dbId = res.getInt(1);
+ res.close();
+
+ res = clientv2.executeQuery(
+ "select table_name from information_schema.tables where db_id = " + dbId + " order by table_name");
+ assertResultSet(res);
+ } finally {
+ if (res != null) {
+ res.close();
+ }
+
+ clientv2.executeUpdate("drop database IF EXISTS client_v2_types3");
+ }
+ }
+
+ @Test
+ public void testExecuteQueryAsync() throws TajoException, IOException, SQLException, ExecutionException,
+ InterruptedException {
+ QueryFuture future = clientv2.executeQueryAsync("select * from lineitem where l_orderkey > 0");
+
+ ResultSet result = future.get();
+ assertResultSet(result);
+
+ assertTrue(future.isDone());
+ assertEquals(QueryState.COMPLETED, future.state());
+ assertTrue(future.isSuccessful());
+ assertFalse(future.isFailed());
+ assertFalse(future.isKilled());
+ assertTrue(1.0f == future.progress());
+ assertEquals("default", future.queue());
+
+ assertTrue(future.submitTime() > 0);
+ assertTrue(future.startTime() > 0);
+ assertTrue(future.finishTime() > 0);
+
+ result.close();
+ }
+
+ @Test(timeout = 10 * 1000)
+ public void testExecuteQueryAsyncWithListener() throws TajoException, IOException, SQLException, ExecutionException,
+ InterruptedException {
+ QueryFuture future = clientv2.executeQueryAsync(
+ "select l_orderkey, sleep(1) from lineitem where l_orderkey > 3");
+
+ final AtomicBoolean success = new AtomicBoolean(false);
+ final List<ResultSet> resultContainer = Lists.newArrayList();
+
+ future.addListener(new FutureListener<QueryFuture>() {
+ @Override
+ public void processingCompleted(QueryFuture future) {
+ try {
+ ResultSet result = future.get();
+ resultContainer.add(result); // for better error handling, it should be verified outside this future.
+
+ assertTrue(future.isDone());
+ assertEquals(QueryState.COMPLETED, future.state());
+ assertTrue(future.isSuccessful());
+ assertFalse(future.isFailed());
+ assertFalse(future.isKilled());
+ assertTrue(1.0f == future.progress());
+ assertEquals("default", future.queue());
+
+ assertTrue(future.submitTime() > 0);
+ assertTrue(future.startTime() > 0);
+ assertTrue(future.finishTime() > 0);
+
+ success.set(true);
+
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+ });
+
+ while(!future.isDone()) {
+ Thread.sleep(100);
+ }
+
+ assertTrue(success.get());
+ assertResultSet(resultContainer.get(0));
+ resultContainer.get(0).close();
+ }
+
+ @Test(timeout = 10 * 1000)
+ public void testQueryFutureKill() throws TajoException, ExecutionException, InterruptedException, SQLException {
+ QueryFuture future = clientv2.executeQueryAsync("select sleep(1) from lineitem where l_orderkey > 4");
+
+ assertTrue(future.isOk());
+ assertFalse(future.isDone());
+ assertFalse(future.isSuccessful());
+ assertFalse(future.isFailed());
+ assertFalse(future.isKilled());
+
+ future.kill();
+ while(!future.isDone()) {
+ Thread.sleep(100);
+ }
+
+ assertTrue(future.isOk());
+ assertTrue(future.isDone());
+ assertFalse(future.isSuccessful());
+ assertFalse(future.isFailed());
+ assertTrue(future.isKilled());
+ }
+
+
+ @Test(expected = DuplicateDatabaseException.class)
+ public void testErrorOnExecuteUpdate() throws TajoException, IOException, SQLException {
+ clientv2.executeUpdate("create database default");
+ }
+
+ @Test(expected = UndefinedTableException.class)
+ public void testErrorOnExecuteQuery() throws TajoException, IOException, SQLException {
+ clientv2.executeQuery("select * from unknown_table");
+ }
+
+ @Test(expected = UndefinedTableException.class)
+ public void testErrorOnExecuteQueryAsync() throws TajoException {
+ clientv2.executeQueryAsync("select * from unknown_table");
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java b/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java
index d86081a..da59e8a 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/codegen/TestEvalCodeGenerator.java
@@ -23,10 +23,9 @@ import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
public class TestEvalCodeGenerator extends ExprTestBase {
private static Schema schema;
static {
@@ -44,7 +43,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testArithmetic() throws IOException {
+ public void testArithmetic() throws TajoException {
testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select 1+1;", new String [] {"2"});
testEval(schema, "table1", "0,1,2,3,4.5,5.5", "select col1 + col2 from table1;", new String [] {"3"});
testEval(schema, "table1", "0,1,2,3,4.5,5.5", "select col1 + col3 from table1;", new String [] {"4"});
@@ -53,7 +52,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testGetField() throws IOException {
+ public void testGetField() throws TajoException {
testEval(schema, "table1", "0,1,2,3,4.5,5.5,F6", "select col1 from table1;", new String [] {"1"});
testEval(schema, "table1", "0,1,2,3,4.5,5.5,F6", "select col2 from table1;", new String [] {"2"});
testEval(schema, "table1", "0,1,2,3,4.5,5.5,F6", "select col3 from table1;", new String [] {"3"});
@@ -64,7 +63,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testNullHandling() throws IOException {
+ public void testNullHandling() throws TajoException {
schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -104,7 +103,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testComparison() throws IOException {
+ public void testComparison() throws TajoException {
Schema inetSchema = new Schema();
inetSchema.addColumn("addr1", TajoDataTypes.Type.INET4);
inetSchema.addColumn("addr2", TajoDataTypes.Type.INET4);
@@ -160,7 +159,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testBetweenAsymmetric() throws IOException {
+ public void testBetweenAsymmetric() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TajoDataTypes.Type.INT4);
schema.addColumn("col2", TajoDataTypes.Type.INT4);
@@ -194,7 +193,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testBetweenSymmetric() throws IOException {
+ public void testBetweenSymmetric() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TajoDataTypes.Type.INT4);
schema.addColumn("col2", TajoDataTypes.Type.INT4);
@@ -229,7 +228,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testUnary() throws IOException {
+ public void testUnary() throws TajoException {
schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -266,7 +265,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testAndOr() throws IOException {
+ public void testAndOr() throws TajoException {
testSimpleEval("select true or (false or false) or false;", new String[] {"t"});
testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select true and true;", new String [] {"t"});
@@ -289,7 +288,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testFunction() throws IOException {
+ public void testFunction() throws TajoException {
testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select upper('abc');", new String [] {"ABC"});
testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select upper('bbc');", new String [] {"BBC"});
testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select upper('chs');", new String [] {"CHS"});
@@ -298,7 +297,7 @@ public class TestEvalCodeGenerator extends ExprTestBase {
}
@Test
- public void testStringConcat() throws IOException {
+ public void testStringConcat() throws TajoException {
testSimpleEval("select length('123456') as col1 ", new String[]{"6"});
testEval(schema, "table1", "0,1,2,3,4.5,6.5", "select 'abc' || 'bbc'", new String [] {"abcbbc"});
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
index abd0973..6fe1510 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
@@ -37,6 +37,7 @@ import org.apache.tajo.engine.json.CoreGsonHelper;
import org.apache.tajo.engine.parser.SQLAnalyzer;
import org.apache.tajo.engine.query.QueryContext;
import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.TajoInternalError;
import org.apache.tajo.function.FunctionSignature;
import org.apache.tajo.master.exec.QueryExecutor;
import org.apache.tajo.plan.*;
@@ -44,6 +45,7 @@ import org.apache.tajo.plan.expr.EvalContext;
import org.apache.tajo.plan.expr.EvalNode;
import org.apache.tajo.plan.serder.EvalNodeDeserializer;
import org.apache.tajo.plan.serder.EvalNodeSerializer;
+import org.apache.tajo.plan.serder.PlanProto;
import org.apache.tajo.plan.verifier.LogicalPlanVerifier;
import org.apache.tajo.plan.verifier.PreLogicalPlanVerifier;
import org.apache.tajo.plan.verifier.VerificationState;
@@ -57,7 +59,6 @@ import org.apache.tajo.util.KeyValueSet;
import org.apache.tajo.util.datetime.DateTimeUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.apache.tajo.plan.serder.PlanProto;
import java.io.IOException;
import java.util.List;
@@ -176,46 +177,46 @@ public class ExprTestBase {
return targets;
}
- public void testSimpleEval(String query, String [] expected) throws IOException {
+ public void testSimpleEval(String query, String [] expected) throws TajoException {
testEval(null, null, null, query, expected);
}
- public void testSimpleEval(OverridableConf context, String query, String [] expected) throws IOException {
+ public void testSimpleEval(OverridableConf context, String query, String [] expected) throws TajoException {
testEval(context, null, null, null, query, expected);
}
public void testSimpleEval(String query, String [] expected, boolean successOrFail)
- throws IOException {
+ throws TajoException, IOException {
testEval(null, null, null, null, query, expected, ',', successOrFail);
}
public void testSimpleEval(OverridableConf context, String query, String [] expected, boolean successOrFail)
- throws IOException {
+ throws TajoException, IOException {
testEval(context, null, null, null, query, expected, ',', successOrFail);
}
public void testEval(Schema schema, String tableName, String csvTuple, String query, String [] expected)
- throws IOException {
+ throws TajoException {
testEval(null, schema, tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null, csvTuple, query,
expected, ',', true);
}
public void testEval(OverridableConf context, Schema schema, String tableName, String csvTuple, String query,
String [] expected)
- throws IOException {
+ throws TajoException {
testEval(context, schema, tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null, csvTuple,
query, expected, ',', true);
}
public void testEval(Schema schema, String tableName, String csvTuple, String query,
- String [] expected, char delimiter, boolean condition) throws IOException {
+ String [] expected, char delimiter, boolean condition) throws TajoException {
testEval(null, schema, tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null, csvTuple,
query, expected, delimiter, condition);
}
public void testEval(OverridableConf context, Schema schema, String tableName, String csvTuple, String query,
- String [] expected, char delimiter, boolean condition) throws IOException {
+ String [] expected, char delimiter, boolean condition) throws TajoException {
QueryContext queryContext;
if (context == null) {
queryContext = LocalTajoTestingUtility.createDummyContext(conf);
@@ -262,8 +263,12 @@ public class ExprTestBase {
vtuple.put(i, lazyTuple.get(i));
}
}
- cat.createTable(new TableDesc(qualifiedTableName, inputSchema,"TEXT",
- new KeyValueSet(), CommonTestingUtil.getTestDir().toUri()));
+ try {
+ cat.createTable(new TableDesc(qualifiedTableName, inputSchema,"TEXT",
+ new KeyValueSet(), CommonTestingUtil.getTestDir().toUri()));
+ } catch (IOException e) {
+ throw new TajoInternalError(e);
+ }
}
Target [] targets;
@@ -309,6 +314,8 @@ public class ExprTestBase {
}
assertEquals(query, expected[i], outTupleAsChars);
}
+ } catch (IOException e) {
+ throw new TajoInternalError(e);
} catch (InvalidStatementException e) {
assertFalse(e.getMessage(), true);
} catch (TajoException e) {
@@ -317,7 +324,7 @@ public class ExprTestBase {
if (!condition) {
assertEquals(expected[0], e.getMessage());
} else {
- assertFalse(e.getMessage(), true);
+ throw e;
}
} finally {
if (schema != null) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
index cde370d..9f9d294 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
@@ -19,15 +19,14 @@
package org.apache.tajo.engine.eval;
import org.apache.tajo.exception.InvalidOperationException;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
import static org.junit.Assert.fail;
public class TestIntervalType extends ExprTestBase {
@Test
- public void testIntervalPostgresqlCase() throws IOException {
+ public void testIntervalPostgresqlCase() throws TajoException {
// http://www.postgresql.org/docs/8.2/static/functions-datetime.html
testSimpleEval("select date '2001-09-28' + 7", new String[]{"2001-10-05"});
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
index 94d5e71..6c42c3e 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
@@ -21,6 +21,7 @@ package org.apache.tajo.engine.eval;
import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
import java.io.IOException;
@@ -36,7 +37,7 @@ public class TestPredicates extends ExprTestBase {
//////////////////////////////////////////////////////////////////
@Test
- public void testAnd() throws IOException {
+ public void testAnd() throws TajoException {
testSimpleEval("select true;", new String[] {"t"});
testSimpleEval("select true and true;", new String[] {"t"});
@@ -46,7 +47,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testOr() throws IOException {
+ public void testOr() throws TajoException {
testSimpleEval("select true or true;", new String[] {"t"});
testSimpleEval("select true or false;", new String[] {"t"});
testSimpleEval("select false or true;", new String[] {"t"});
@@ -54,7 +55,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testLogicalOperatorPrecedence() throws IOException {
+ public void testLogicalOperatorPrecedence() throws TajoException {
testSimpleEval("select true or (false or false) or false;", new String[] {"t"});
testSimpleEval("select false or (true or false) or false;", new String[] {"t"});
testSimpleEval("select false or (false or true) or false;", new String[] {"t"});
@@ -77,7 +78,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testNot() throws IOException {
+ public void testNot() throws TajoException {
testSimpleEval("select true;", new String[] {"t"});
testSimpleEval("select not true;", new String[] {"f"});
@@ -99,7 +100,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testParenthesizedValues() throws IOException {
+ public void testParenthesizedValues() throws TajoException {
testSimpleEval("select ((true));", new String[] {"t"});
testSimpleEval("select ((((true))));", new String[] {"t"});
testSimpleEval("select not(not(not(false)));", new String[] {"t"});
@@ -110,7 +111,7 @@ public class TestPredicates extends ExprTestBase {
//////////////////////////////////////////////////////////////////
@Test
- public void testComparisonEqual() throws IOException {
+ public void testComparisonEqual() throws TajoException {
Schema schema = new Schema();
@@ -142,7 +143,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testComparisonNotEqual() throws IOException {
+ public void testComparisonNotEqual() throws TajoException {
Schema schema1 = new Schema();
schema1.addColumn("col1", INT4);
schema1.addColumn("col2", INT4);
@@ -159,7 +160,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testComparisonLessThan() throws IOException {
+ public void testComparisonLessThan() throws TajoException {
Schema schema1 = new Schema();
schema1.addColumn("col1", INT4);
schema1.addColumn("col2", INT4);
@@ -176,7 +177,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testComparisonLessThanEqual() throws IOException {
+ public void testComparisonLessThanEqual() throws TajoException {
Schema schema1 = new Schema();
schema1.addColumn("col1", INT4);
schema1.addColumn("col2", INT4);
@@ -193,7 +194,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testComparisonGreaterThan() throws IOException {
+ public void testComparisonGreaterThan() throws TajoException {
Schema schema1 = new Schema();
schema1.addColumn("col1", INT4);
schema1.addColumn("col2", INT4);
@@ -210,7 +211,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testComparisonGreaterThanEqual() throws IOException {
+ public void testComparisonGreaterThanEqual() throws TajoException {
Schema schema1 = new Schema();
schema1.addColumn("col1", INT4);
schema1.addColumn("col2", INT4);
@@ -231,7 +232,7 @@ public class TestPredicates extends ExprTestBase {
//////////////////////////////////////////////////////////////////
@Test
- public void testBetween() throws IOException {
+ public void testBetween() throws TajoException {
Schema schema2 = new Schema();
schema2.addColumn("col1", TEXT);
schema2.addColumn("col2", TEXT);
@@ -255,7 +256,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testBetween2() throws IOException { // for TAJO-249
+ public void testBetween2() throws TajoException { // for TAJO-249
Schema schema3 = new Schema();
schema3.addColumn("date_a", INT4);
schema3.addColumn("date_b", INT4);
@@ -294,7 +295,7 @@ public class TestPredicates extends ExprTestBase {
//////////////////////////////////////////////////////////////////
@Test
- public void testInPredicateWithConstant() throws IOException {
+ public void testInPredicateWithConstant() throws TajoException {
Schema schema2 = new Schema();
schema2.addColumn("col1", TEXT);
schema2.addColumn("col2", TEXT);
@@ -319,7 +320,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testInPredicateWithSimpleExprs() throws IOException {
+ public void testInPredicateWithSimpleExprs() throws TajoException {
Schema schema2 = new Schema();
schema2.addColumn("col1", TEXT);
schema2.addColumn("col2", INT4);
@@ -343,7 +344,7 @@ public class TestPredicates extends ExprTestBase {
//////////////////////////////////////////////////////////////////
@Test
- public void testIsNullPredicate() throws IOException {
+ public void testIsNullPredicate() throws TajoException {
Schema schema1 = new Schema();
schema1.addColumn("col1", INT4);
schema1.addColumn("col2", INT4);
@@ -354,7 +355,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testIsNullPredicateWithFunction() throws IOException {
+ public void testIsNullPredicateWithFunction() throws TajoException {
Schema schema2 = new Schema();
schema2.addColumn("col1", TEXT);
schema2.addColumn("col2", TEXT);
@@ -370,7 +371,7 @@ public class TestPredicates extends ExprTestBase {
//////////////////////////////////////////////////////////////////
@Test
- public void testBooleanTest() throws IOException {
+ public void testBooleanTest() throws TajoException {
testSimpleEval("select 1 < 3 is true", new String [] {"t"});
testSimpleEval("select 1 < 3 is not true", new String [] {"f"});
testSimpleEval("select 1 < 3 is false", new String [] {"f"});
@@ -393,7 +394,7 @@ public class TestPredicates extends ExprTestBase {
}
@Test
- public void testBooleanTestOnTable() throws IOException {
+ public void testBooleanTestOnTable() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", BOOLEAN);
schema.addColumn("col2", BOOLEAN);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
index fc74339..1b599a6 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
@@ -18,14 +18,13 @@
package org.apache.tajo.engine.eval;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
public class TestSQLDateTimeTypes extends ExprTestBase {
@Test
- public void testTimestamp() throws IOException {
+ public void testTimestamp() throws TajoException {
testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37';", new String[]{"1970-01-17 10:09:37"});
testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.5';", new String[]{"1970-01-17 10:09:37.5"});
testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.01';", new String[]{"1970-01-17 10:09:37.01"});
@@ -33,18 +32,18 @@ public class TestSQLDateTimeTypes extends ExprTestBase {
}
@Test
- public void testToTimestamp() throws IOException {
+ public void testToTimestamp() throws TajoException {
testSimpleEval("select to_char(TIMESTAMP '1970-01-17 10:09:37', 'YYYY-MM-DD HH24:MI:SS');",
new String[]{"1970-01-17 10:09:37"});
}
@Test
- public void testTimeLiteral() throws IOException {
+ public void testTimeLiteral() throws TajoException {
testSimpleEval("select TIME '10:09:37';", new String[]{"10:09:37"});
}
@Test
- public void testDateLiteral() throws IOException {
+ public void testDateLiteral() throws TajoException {
testSimpleEval("select DATE '1970-01-17';", new String[]{"1970-01-17"});
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
index 8d81ae8..684f0f2 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
@@ -26,10 +26,10 @@ import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.datum.DatumFactory;
import org.apache.tajo.datum.TimestampDatum;
import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.util.datetime.DateTimeUtil;
import org.junit.Test;
-import java.io.IOException;
import java.util.TimeZone;
import static org.apache.tajo.common.TajoDataTypes.Type.*;
@@ -38,7 +38,7 @@ import static org.junit.Assert.fail;
public class TestSQLExpression extends ExprTestBase {
@Test
- public void testQuotedIdentifiers() throws IOException {
+ public void testQuotedIdentifiers() throws TajoException {
Schema schema = new Schema();
schema.addColumn("컬럼1", TEXT);
schema.addColumn("컬럼2", TEXT);
@@ -50,7 +50,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testNoSuchFunction() throws IOException {
+ public void testNoSuchFunction() {
try {
testSimpleEval("select test123('abc') col1 ", new String[]{"abc"});
fail("This test should throw UndefinedFunctionException");
@@ -62,7 +62,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testSQLStandardCast() throws IOException {
+ public void testSQLStandardCast() throws TajoException {
testSimpleEval("select cast (1 as char)", new String[] {"1"});
testSimpleEval("select cast (119 as char)", new String[] {"1"});
@@ -92,7 +92,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testExplicitCast() throws IOException {
+ public void testExplicitCast() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", INT1);
schema.addColumn("col1", INT2);
@@ -172,7 +172,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testImplicitCastForInt1() throws IOException {
+ public void testImplicitCastForInt1() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -274,7 +274,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testImplicitCastForInt2() throws IOException {
+ public void testImplicitCastForInt2() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -376,7 +376,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testImplicitCastForInt4() throws IOException {
+ public void testImplicitCastForInt4() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -479,7 +479,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testImplicitCastForInt8() throws IOException {
+ public void testImplicitCastForInt8() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -586,7 +586,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testImplicitCastForFloat4() throws IOException {
+ public void testImplicitCastForFloat4() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -705,7 +705,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testImplicitCastForFloat8() throws IOException {
+ public void testImplicitCastForFloat8() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -825,7 +825,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testSigned() throws IOException {
+ public void testSigned() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col0", TajoDataTypes.Type.INT1);
schema.addColumn("col1", TajoDataTypes.Type.INT2);
@@ -853,7 +853,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testCastWithNestedFunction() throws IOException {
+ public void testCastWithNestedFunction() throws TajoException {
QueryContext context = new QueryContext(getConf());
context.put(SessionVars.TIMEZONE, "GMT-6");
TimeZone tz = TimeZone.getTimeZone("GMT-6");
@@ -865,7 +865,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testCastFromTable() throws IOException {
+ public void testCastFromTable() throws TajoException {
QueryContext queryContext = new QueryContext(getConf());
queryContext.put(SessionVars.TIMEZONE, "GMT-6");
TimeZone tz = TimeZone.getTimeZone("GMT-6");
@@ -898,7 +898,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testBooleanLiteral() throws IOException {
+ public void testBooleanLiteral() throws TajoException {
testSimpleEval("select true", new String[] {"t"});
testSimpleEval("select false", new String[]{"f"});
@@ -909,7 +909,7 @@ public class TestSQLExpression extends ExprTestBase {
}
@Test
- public void testNullComparisons() throws IOException {
+ public void testNullComparisons() throws TajoException {
testSimpleEval("select (1 > null) is null", new String[] {"t"});
testSimpleEval("select null is null", new String[] {"t"});
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
index 1d35139..7e63bc1 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
@@ -23,15 +23,14 @@ import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.exception.UndefinedFunctionException;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
import static org.junit.Assert.fail;
public class TestConditionalExpressions extends ExprTestBase {
@Test
- public void testCaseWhens1() throws IOException {
+ public void testCaseWhens1() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TajoDataTypes.Type.INT1);
schema.addColumn("col2", TajoDataTypes.Type.INT2);
@@ -58,7 +57,7 @@ public class TestConditionalExpressions extends ExprTestBase {
}
@Test
- public void testCaseWhensWithNullReturn() throws IOException {
+ public void testCaseWhensWithNullReturn() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TajoDataTypes.Type.TEXT);
schema.addColumn("col2", TajoDataTypes.Type.TEXT);
@@ -72,7 +71,7 @@ public class TestConditionalExpressions extends ExprTestBase {
}
@Test
- public void testCaseWhensWithCommonExpression() throws IOException {
+ public void testCaseWhensWithCommonExpression() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TajoDataTypes.Type.INT4);
schema.addColumn("col2", TajoDataTypes.Type.INT4);
@@ -110,7 +109,7 @@ public class TestConditionalExpressions extends ExprTestBase {
}
@Test
- public void testCaseWhensWithCommonExpressionAndNull() throws IOException {
+ public void testCaseWhensWithCommonExpressionAndNull() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TajoDataTypes.Type.INT4);
schema.addColumn("col2", TajoDataTypes.Type.INT4);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
index 25a10fd..9dd8653 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
@@ -25,21 +25,20 @@ import org.apache.tajo.datum.DatumFactory;
import org.apache.tajo.datum.TimestampDatum;
import org.apache.tajo.engine.eval.ExprTestBase;
import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.util.datetime.DateTimeUtil;
import org.apache.tajo.util.datetime.TimeMeta;
import org.junit.Test;
-import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import static org.apache.tajo.common.TajoDataTypes.Type.*;
-import static org.junit.Assert.assertEquals;
public class TestDateTimeFunctions extends ExprTestBase {
@Test
- public void testToTimestamp() throws IOException {
+ public void testToTimestamp() throws TajoException {
long expectedTimestamp = System.currentTimeMillis();
TimestampDatum expected = DatumFactory.createTimestmpDatumWithUnixTime((int)(expectedTimestamp/ 1000));
@@ -100,7 +99,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testToChar() throws IOException {
+ public void testToChar() throws TajoException {
long expectedTimestamp = System.currentTimeMillis();
TimeMeta tm = new TimeMeta();
DateTimeUtil.toJulianTimeMeta(DateTimeUtil.javaTimeToJulianTime(expectedTimestamp), tm);
@@ -116,7 +115,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testExtract() throws IOException {
+ public void testExtract() throws TajoException {
TimeZone GMT = TimeZone.getTimeZone("GMT");
TimeZone PST = TimeZone.getTimeZone("PST");
@@ -232,7 +231,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testDatePart() throws IOException {
+ public void testDatePart() throws TajoException {
TimeZone GMT = TimeZone.getTimeZone("GMT");
TimeZone PST = TimeZone.getTimeZone("PST");
@@ -345,7 +344,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testUtcUsecTo() throws IOException {
+ public void testUtcUsecTo() throws TajoException {
testSimpleEval("select utc_usec_to('day' ,1274259481071200);", new String[]{1274227200000000L+""});
testSimpleEval("select utc_usec_to('hour' ,1274259481071200);", new String[]{1274256000000000L+""});
testSimpleEval("select utc_usec_to('month' ,1274259481071200);", new String[]{1272672000000000L+""});
@@ -354,7 +353,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testToDate() throws IOException {
+ public void testToDate() throws TajoException {
testSimpleEval("select to_date('2014-01-04', 'YYYY-MM-DD')", new String[]{"2014-01-04"});
testSimpleEval("select to_date('2014-01-04', 'YYYY-MM-DD') + interval '1 day'",
new String[]{"2014-01-05 00:00:00"});
@@ -394,7 +393,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testAddDays() throws IOException {
+ public void testAddDays() throws TajoException {
testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT2);",
new String[]{"2014-01-04 00:00:00"});
testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT4);",
@@ -425,7 +424,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testDateTimeNow() throws IOException {
+ public void testDateTimeNow() throws TajoException {
TimeZone originalTimezone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT-6"));
@@ -454,7 +453,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
}
@Test
- public void testTimeValueKeyword() throws IOException {
+ public void testTimeValueKeyword() throws TajoException {
TimeZone originTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT-6"));
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java
index 89f0439..57248a8 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestJsonFunctions.java
@@ -20,15 +20,14 @@ package org.apache.tajo.engine.function;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
public class TestJsonFunctions extends ExprTestBase {
static final String JSON_DOCUMENT = "{\"map\" : {\"name\" : \"tajo\"}, \"array\" : [1,2,3]}";
@Test
- public void testJsonExtractPathText() throws IOException {
+ public void testJsonExtractPathText() throws TajoException {
testSimpleEval("select json_extract_path_text('" + JSON_DOCUMENT + "', '$.map.name') ", new String[]{"tajo"});
testSimpleEval("select json_extract_path_text('" + JSON_DOCUMENT + "', '$.array[1]') ", new String[]{"2"});
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
index 78509f7..4b0303f 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
@@ -20,15 +20,14 @@ package org.apache.tajo.engine.function;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
import static org.apache.tajo.common.TajoDataTypes.Type.*;
public class TestMathFunctions extends ExprTestBase {
@Test
- public void testRound() throws IOException {
+ public void testRound() throws TajoException {
testSimpleEval("select round(5.1) as col1 ", new String[]{"5"});
testSimpleEval("select round(5.5) as col1 ", new String[]{"6"});
testSimpleEval("select round(5.6) as col1 ", new String[]{"6"});
@@ -57,7 +56,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testFloor() throws IOException {
+ public void testFloor() throws TajoException {
testSimpleEval("select floor(5.1) as col1 ", new String[]{"5"});
testSimpleEval("select floor(5.5) as col1 ", new String[]{"5"});
testSimpleEval("select floor(5.6) as col1 ", new String[]{"5"});
@@ -75,7 +74,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testCeil() throws IOException {
+ public void testCeil() throws TajoException {
testSimpleEval("select ceil(5.0) as col1 ", new String[]{"5"});
testSimpleEval("select ceil(5.1) as col1 ", new String[]{"6"});
testSimpleEval("select ceil(5.5) as col1 ", new String[]{"6"});
@@ -94,7 +93,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testCeiling() throws IOException {
+ public void testCeiling() throws TajoException {
testSimpleEval("select ceiling(5.0) as col1 ", new String[]{"5"});
testSimpleEval("select ceiling(5.1) as col1 ", new String[]{"6"});
testSimpleEval("select ceiling(5.5) as col1 ", new String[]{"6"});
@@ -113,7 +112,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testSin() throws IOException {
+ public void testSin() throws TajoException {
testSimpleEval("select sin(0.0) as col1 ", new String[]{"0.0"});
testSimpleEval("select sin(0.7) as col1 ", new String[]{"0.644217687237691"});
testSimpleEval("select sin(1.2) as col1 ", new String[]{"0.9320390859672263"});
@@ -130,7 +129,7 @@ public class TestMathFunctions extends ExprTestBase {
@Test
- public void testCos() throws IOException {
+ public void testCos() throws TajoException {
testSimpleEval("select cos(0.0) as col1 ", new String[]{"1.0"});
testSimpleEval("select cos(0.7) as col1 ", new String[]{"0.7648421872844885"});
testSimpleEval("select cos(1.2) as col1 ", new String[]{"0.3623577544766736"});
@@ -146,7 +145,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testTan() throws IOException {
+ public void testTan() throws TajoException {
testSimpleEval("select tan(0.0) as col1 ", new String[]{"0.0"});
testSimpleEval("select tan(0.3) as col1 ", new String[]{"0.30933624960962325"});
testSimpleEval("select tan(0.8) as col1 ", new String[]{"1.0296385570503641"});
@@ -162,7 +161,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testAsin() throws IOException {
+ public void testAsin() throws TajoException {
testSimpleEval("select asin(0.0) as col1 ", new String[]{"0.0"});
testSimpleEval("select asin(0.3) as col1 ", new String[]{"0.3046926540153975"});
testSimpleEval("select asin(0.8) as col1 ", new String[]{"0.9272952180016123"});
@@ -178,7 +177,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testAcos() throws IOException {
+ public void testAcos() throws TajoException {
testSimpleEval("select acos(0.0) as col1 ", new String[]{"1.5707963267948966"});
testSimpleEval("select acos(0.3) as col1 ", new String[]{"1.2661036727794992"});
testSimpleEval("select acos(0.8) as col1 ", new String[]{"0.6435011087932843"});
@@ -194,7 +193,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testAtan() throws IOException {
+ public void testAtan() throws TajoException {
testSimpleEval("select atan(0.0) as col1 ", new String[]{"0.0"});
testSimpleEval("select atan(0.8) as col1 ", new String[]{"0.6747409422235527"});
testSimpleEval("select atan(1.2) as col1 ", new String[]{"0.8760580505981934"});
@@ -210,7 +209,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testAtan2() throws IOException {
+ public void testAtan2() throws TajoException {
testSimpleEval("select atan2(0.8, 0.0) as col1 ", new String[]{"1.5707963267948966"});
testSimpleEval("select atan2(0.8, 1.1) as col1 ", new String[]{"0.628796286415433"});
testSimpleEval("select atan2(2.7, 0.3) as col1 ", new String[]{"1.460139105621001"});
@@ -227,7 +226,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testMod() throws IOException {
+ public void testMod() throws TajoException {
testSimpleEval("select mod(9,4) as col1 ", new String[]{"1"});
testSimpleEval("select mod(200000000001,200000000000) as col1 ", new String[]{"1"});
testSimpleEval("select mod(200000000000,2) as col1 ", new String[]{"0"});
@@ -243,7 +242,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testDiv() throws IOException {
+ public void testDiv() throws TajoException {
testSimpleEval("select div(9,4) as col1 ", new String[]{"2"});
testSimpleEval("select div(200000000001,200000000000) as col1 ", new String[]{"1"});
testSimpleEval("select div(200000000000,2) as col1 ", new String[]{"100000000000"});
@@ -259,7 +258,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testSign() throws IOException {
+ public void testSign() throws TajoException {
testSimpleEval("select sign(2) as col1 ", new String[]{"1.0"});
testSimpleEval("select sign(2.345) as col1 ", new String[]{"1.0"});
testSimpleEval("select sign(0.3) as col1 ", new String[]{"1.0"});
@@ -284,7 +283,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testSqrt() throws IOException {
+ public void testSqrt() throws TajoException {
testSimpleEval("select sqrt(27.0) as col1 ", new String[]{"5.196152422706632"});
testSimpleEval("select sqrt(64.0) as col1 ", new String[]{"8.0"});
testSimpleEval("select sqrt(8.0) as col1 ", new String[]{"2.8284271247461903"});
@@ -309,7 +308,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testExp() throws IOException {
+ public void testExp() throws TajoException {
testSimpleEval("select exp(1.0) as col1 ", new String[]{String.valueOf(Math.exp(1.0d))});
testSimpleEval("select exp(1.1) as col1 ", new String[]{String.valueOf(Math.exp(1.1d))});
testSimpleEval("select exp(1.2) as col1 ", new String[]{String.valueOf(Math.exp(1.2d))});
@@ -330,7 +329,7 @@ public class TestMathFunctions extends ExprTestBase {
@Test
- public void testAbs() throws IOException {
+ public void testAbs() throws TajoException {
testSimpleEval("select abs(9) as col1 ", new String[]{"9"});
testSimpleEval("select abs(-9) as col1 ", new String[]{"9"});
testSimpleEval("select abs(200000000000) as col1 ", new String[]{"200000000000"});
@@ -351,7 +350,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testCbrt() throws IOException {
+ public void testCbrt() throws TajoException {
testSimpleEval("select cbrt(27.0) as col1 ", new String[]{"3.0"});
testSimpleEval("select cbrt(64.0) as col1 ", new String[]{"4.0"});
testSimpleEval("select cbrt(8.0) as col1 ", new String[]{"2.0"});
@@ -373,7 +372,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testDegrees() throws IOException {
+ public void testDegrees() throws TajoException {
testSimpleEval("select degrees(0.0) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.0))});
testSimpleEval("select degrees(0.8) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.8))});
testSimpleEval("select degrees(2.7) as col1 ", new String[]{String.valueOf(Math.toDegrees(2.7))});
@@ -393,7 +392,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testPow() throws IOException {
+ public void testPow() throws TajoException {
testSimpleEval("select pow(9,3) as col1 ", new String[]{String.valueOf(Math.pow(9, 3))});
testSimpleEval("select pow(1.0,3) as col1 ", new String[]{String.valueOf(Math.pow(1.0, 3))});
testSimpleEval("select pow(20.1,3.1) as col1 ", new String[]{String.valueOf(Math.pow(20.1, 3.1))});
@@ -414,7 +413,7 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testRadians() throws IOException {
+ public void testRadians() throws TajoException {
testSimpleEval("select radians(0.0) as col1 ", new String[]{String.valueOf(Math.toRadians(0.0))});
testSimpleEval("select radians(0.8) as col1 ", new String[]{String.valueOf(Math.toRadians(0.8))});
testSimpleEval("select radians(2.7) as col1 ", new String[]{String.valueOf(Math.toRadians(2.7))});
@@ -434,12 +433,12 @@ public class TestMathFunctions extends ExprTestBase {
}
@Test
- public void testPi() throws IOException {
+ public void testPi() throws TajoException {
testSimpleEval("select pi() as col1 ", new String[]{String.valueOf(Math.PI)});
}
@Test
- public void testRoundWithSpecifiedPrecision() throws IOException {
+ public void testRoundWithSpecifiedPrecision() throws TajoException {
// TODO - in order to make this test possible, testSimpleEval should take session variables. Now, we disable it.
// divide zero
// try {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
index 8aae26d..50a8f35 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
@@ -20,16 +20,15 @@ package org.apache.tajo.engine.function;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
-import java.io.IOException;
-
import static org.apache.tajo.common.TajoDataTypes.Type.TEXT;
public class TestPatternMatchingPredicates extends ExprTestBase {
@Test
- public void testLike() throws IOException {
+ public void testLike() throws TajoException {
Schema schema = new Schema();
schema.addColumn("col1", TEXT);
@@ -58,7 +57,7 @@ public class TestPatternMatchingPredicates extends ExprTestBase {
}
@Test
- public void testILike() throws IOException {
+ public void testILike() throws TajoException {
testSimpleEval("select 'abc' ilike '%c'", new String[]{"t"});
testSimpleEval("select 'abc' ilike 'a%'", new String[]{"t"});
testSimpleEval("select 'abc' ilike '_bc'", new String[]{"t"});
@@ -80,7 +79,7 @@ public class TestPatternMatchingPredicates extends ExprTestBase {
}
@Test
- public void testSimilarToLike() throws IOException {
+ public void testSimilarToLike() throws TajoException {
testSimpleEval("select 'abc' similar to '%c'", new String[]{"t"});
testSimpleEval("select 'abc' similar to 'a%'", new String[]{"t"});
testSimpleEval("select 'abc' similar to '_bc'", new String[]{"t"});
@@ -104,7 +103,7 @@ public class TestPatternMatchingPredicates extends ExprTestBase {
}
@Test
- public void testRegexWithSimilarOperator() throws IOException {
+ public void testRegexWithSimilarOperator() throws TajoException {
testSimpleEval("select 'abc' ~ '.*c'", new String[]{"t"});
testSimpleEval("select 'abc' ~ '.*c$'", new String[]{"t"});
testSimpleEval("select 'aaabc' ~ '([a-z]){3}bc'", new String[]{"t"});
@@ -121,7 +120,7 @@ public class TestPatternMatchingPredicates extends ExprTestBase {
}
@Test
- public void testRegexp() throws IOException {
+ public void testRegexp() throws TajoException {
testSimpleEval("select 'abc' regexp '.*c'", new String[]{"t"});
testSimpleEval("select 'abc' regexp '.*c$'", new String[]{"t"});
@@ -130,7 +129,7 @@ public class TestPatternMatchingPredicates extends ExprTestBase {
}
@Test
- public void testRLike() throws IOException {
+ public void testRLike() throws TajoException {
testSimpleEval("select 'abc' rlike '.*c'", new String[]{"t"});
testSimpleEval("select 'abc' rlike '.*c$'", new String[]{"t"});
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java
index 6f73d01..e94f869 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPythonFunctions.java
@@ -19,6 +19,7 @@
package org.apache.tajo.engine.function;
import org.apache.tajo.engine.eval.ExprTestBase;
+import org.apache.tajo.exception.TajoException;
import org.junit.Test;
import java.io.IOException;
@@ -26,7 +27,7 @@ import java.io.IOException;
public class TestPythonFunctions extends ExprTestBase {
@Test
- public void testFunctions() throws IOException {
+ public void testFunctions() throws TajoException {
testSimpleEval("select return_one()", new String[]{"1"});
testSimpleEval("select helloworld()", new String[]{"Hello, World"});
testSimpleEval("select concat_py('1')", new String[]{"11"});
@@ -37,7 +38,7 @@ public class TestPythonFunctions extends ExprTestBase {
}
@Test
- public void testNestedFunctions() throws IOException {
+ public void testNestedFunctions() throws TajoException {
testSimpleEval("select add_py(3, return_one())", new String[]{"4"});
testSimpleEval("select concat_py(helloworld())", new String[]{"Hello, WorldHello, World"});
}
[4/4] tajo git commit: TAJO-1699: Tajo Java Client version 2.
Posted by hy...@apache.org.
TAJO-1699: Tajo Java Client version 2.
Closes #662
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/4253f1b6
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/4253f1b6
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/4253f1b6
Branch: refs/heads/master
Commit: 4253f1b60429adb9558f0b7b194754557eebcf15
Parents: d8ce562
Author: Hyunsik Choi <hy...@apache.org>
Authored: Tue Aug 4 10:29:21 2015 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Tue Aug 4 10:29:21 2015 +0900
----------------------------------------------------------------------
CHANGES | 2 +
.../tajo/catalog/AbstractCatalogClient.java | 4 +-
.../org/apache/tajo/catalog/CatalogService.java | 5 +-
.../java/org/apache/tajo/catalog/Schema.java | 4 +-
.../exception/AmbiguousFunctionException.java | 6 +
.../exception/AmbiguousTableException.java | 9 +-
.../catalog/exception/CatalogException.java | 9 +-
.../exception/DuplicateColumnException.java | 5 +
.../exception/DuplicateDatabaseException.java | 6 +
.../exception/DuplicateIndexException.java | 5 +
.../exception/DuplicatePartitionException.java | 5 +
.../exception/DuplicateTableException.java | 5 +
.../exception/UndefinedColumnException.java | 5 +
.../exception/UndefinedDatabaseException.java | 5 +
.../exception/UndefinedFunctionException.java | 8 +-
.../exception/UndefinedPartitionException.java | 5 +
.../exception/UndefinedTableException.java | 5 +
.../exception/UndefinedTablespaceException.java | 5 +
.../org/apache/tajo/catalog/TestSchema.java | 3 +-
.../tajo/catalog/store/HiveCatalogUtil.java | 2 +-
.../org/apache/tajo/catalog/CatalogServer.java | 62 +--
.../InfoSchemaMetadataDictionary.java | 12 +-
.../tajo/catalog/store/AbstractDBStore.java | 24 +-
.../org/apache/tajo/catalog/store/MemStore.java | 24 +-
.../catalog/store/XMLCatalogSchemaManager.java | 8 +-
.../org/apache/tajo/cli/tools/TajoAdmin.java | 4 +-
.../java/org/apache/tajo/cli/tsql/TajoCli.java | 7 +-
.../tsql/commands/ConnectDatabaseCommand.java | 3 +-
.../tajo/cli/tsql/commands/SetCommand.java | 5 +-
tajo-client/pom.xml | 4 +-
.../apache/tajo/client/CatalogAdminClient.java | 26 +-
.../tajo/client/CatalogAdminClientImpl.java | 91 ++--
.../apache/tajo/client/ClientExceptionUtil.java | 106 ++++
.../client/InvalidClientSessionException.java | 9 +-
.../org/apache/tajo/client/QueryClient.java | 41 +-
.../org/apache/tajo/client/QueryClientImpl.java | 83 ++--
.../apache/tajo/client/SessionConnection.java | 103 ++--
.../org/apache/tajo/client/TajoClientImpl.java | 46 +-
.../org/apache/tajo/client/TajoClientUtil.java | 2 +-
.../apache/tajo/client/v2/ClientDelegate.java | 41 ++
.../tajo/client/v2/ClientDelegateFactory.java | 42 ++
.../org/apache/tajo/client/v2/ClientUtil.java | 30 ++
.../apache/tajo/client/v2/FutureListener.java | 25 +
.../tajo/client/v2/LegacyClientDelegate.java | 485 +++++++++++++++++++
.../org/apache/tajo/client/v2/QueryFuture.java | 133 +++++
.../org/apache/tajo/client/v2/QueryState.java | 36 ++
.../apache/tajo/client/v2/ServiceDiscovery.java | 28 ++
.../org/apache/tajo/client/v2/TajoClient.java | 154 ++++++
.../v2/exception/ClientConnectionException.java | 28 ++
.../ClientUnableToConnectException.java | 28 ++
.../org/apache/tajo/jdbc/FetchResultSet.java | 2 +-
.../exception/AmbiguousColumnException.java | 9 +-
.../apache/tajo/exception/ErrorMessages.java | 6 +-
.../NoSuchSessionVariableException.java | 33 ++
.../apache/tajo/exception/ReturnStateUtil.java | 3 +-
.../apache/tajo/exception/SQLExceptionUtil.java | 22 +-
.../org/apache/tajo/exception/TajoError.java | 7 +
.../apache/tajo/exception/TajoException.java | 11 +
.../tajo/exception/TajoInternalError.java | 6 +
.../exception/UndefinedOperatorException.java | 5 +
.../tajo/exception/UnsupportedException.java | 5 +
tajo-core/pom.xml | 4 +-
.../org/apache/tajo/benchmark/BenchmarkSet.java | 3 +-
.../java/org/apache/tajo/benchmark/TPCH.java | 5 +-
.../engine/planner/global/GlobalPlanner.java | 107 ++--
.../java/org/apache/tajo/master/TajoMaster.java | 3 +-
.../tajo/master/exec/CreateTableExecutor.java | 15 +-
.../apache/tajo/master/exec/DDLExecutor.java | 36 +-
.../apache/tajo/master/exec/QueryExecutor.java | 3 +-
.../tajo/session/InvalidSessionException.java | 7 +-
.../tajo/webapp/QueryExecutorServlet.java | 2 +-
.../apache/tajo/LocalTajoTestingUtility.java | 6 +-
.../java/org/apache/tajo/QueryTestCaseBase.java | 10 +-
.../org/apache/tajo/client/TestTajoClient.java | 62 +--
.../tajo/client/TestTajoClientFailures.java | 16 +-
.../apache/tajo/client/v2/TestTajoClientV2.java | 236 +++++++++
.../engine/codegen/TestEvalCodeGenerator.java | 23 +-
.../apache/tajo/engine/eval/ExprTestBase.java | 31 +-
.../tajo/engine/eval/TestIntervalType.java | 5 +-
.../apache/tajo/engine/eval/TestPredicates.java | 39 +-
.../tajo/engine/eval/TestSQLDateTimeTypes.java | 11 +-
.../tajo/engine/eval/TestSQLExpression.java | 32 +-
.../function/TestConditionalExpressions.java | 11 +-
.../engine/function/TestDateTimeFunctions.java | 21 +-
.../tajo/engine/function/TestJsonFunctions.java | 5 +-
.../tajo/engine/function/TestMathFunctions.java | 49 +-
.../function/TestPatternMatchingPredicates.java | 15 +-
.../engine/function/TestPythonFunctions.java | 5 +-
.../TestStringOperatorsAndFunctions.java | 77 ++-
.../apache/tajo/engine/query/TestIndexScan.java | 3 +-
.../apache/tajo/engine/query/TestJoinQuery.java | 6 +-
.../java/org/apache/tajo/jdbc/TestTajoJdbc.java | 90 ----
.../testExecuteQueryAsync.result | 7 +
.../testExecuteQueryAsyncWithListener.result | 2 +
.../testExecuteQueryType1.result | 7 +
.../testExecuteQueryType2.result | 4 +
.../testExecuteQueryType3.result | 4 +
.../org/apache/tajo/jdbc/JdbcConnection.java | 28 +-
.../org/apache/tajo/jdbc/MetaDataTuple.java | 17 +-
.../org/apache/tajo/jdbc/TajoStatement.java | 55 ---
.../tajo/plan/expr/BasicEvalNodeVisitor.java | 1 +
.../tajo/plan/expr/SimpleEvalNodeVisitor.java | 3 +-
.../plan/function/stream/CSVLineSerializer.java | 1 -
.../tajo/plan/nameresolver/NameResolver.java | 6 +-
.../plan/nameresolver/ResolverByLegacy.java | 3 +-
.../tajo/plan/nameresolver/ResolverByRels.java | 4 +-
.../nameresolver/ResolverByRelsAndSubExprs.java | 4 +-
.../nameresolver/ResolverBySubExprsAndRels.java | 4 +-
.../rewrite/rules/ProjectionPushDownRule.java | 11 +-
.../tajo/plan/serder/EvalNodeDeserializer.java | 5 +-
.../tajo/plan/verifier/VerificationState.java | 6 +
.../org/apache/tajo/storage/NullScanner.java | 4 +-
.../org/apache/tajo/storage/RowStoreUtil.java | 2 +-
.../org/apache/tajo/storage/Tablespace.java | 3 +-
.../apache/tajo/tuple/offheap/HeapTuple.java | 2 -
.../apache/tajo/tuple/offheap/UnSafeTuple.java | 2 -
116 files changed, 2276 insertions(+), 749 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 3deac6d..129c7de 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,8 @@ Release 0.11.0 - unreleased
IMPROVEMENT
+ TAJO-1699: Tajo Java Client version 2. (hyunsik)
+
TAJO-1721: Separate routine for CREATE TABLE from DDLExecutor. (hyunsik)
TAJO-1736: Remove unnecessary getMountPath().
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
index 52f4b8e..e239b78 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
+++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
@@ -723,13 +723,13 @@ public abstract class AbstractCatalogClient implements CatalogService, Closeable
@Override
public final FunctionDesc getFunction(final String signature, DataType... paramTypes)
- throws UndefinedFunctionException {
+ throws AmbiguousFunctionException , UndefinedFunctionException {
return getFunction(signature, null, paramTypes);
}
@Override
public final FunctionDesc getFunction(final String signature, FunctionType funcType, DataType... paramTypes)
- throws UndefinedFunctionException {
+ throws AmbiguousFunctionException, UndefinedFunctionException {
final GetFunctionMetaRequest.Builder builder = GetFunctionMetaRequest.newBuilder();
builder.setSignature(signature);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
index 26fc564..a534805 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogService.java
@@ -18,6 +18,7 @@
package org.apache.tajo.catalog;
+import org.apache.tajo.catalog.exception.AmbiguousFunctionException;
import org.apache.tajo.catalog.exception.UndefinedFunctionException;
import org.apache.tajo.catalog.exception.UndefinedPartitionException;
import org.apache.tajo.catalog.partition.PartitionMethodDesc;
@@ -210,9 +211,9 @@ public interface CatalogService {
boolean dropFunction(String signature);
- FunctionDesc getFunction(String signature, DataType... paramTypes) throws UndefinedFunctionException;
+ FunctionDesc getFunction(String signature, DataType... paramTypes) throws AmbiguousFunctionException, UndefinedFunctionException;
- FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws UndefinedFunctionException;
+ FunctionDesc getFunction(String signature, FunctionType funcType, DataType... paramTypes) throws AmbiguousFunctionException, UndefinedFunctionException;
boolean containFunction(String signature, DataType... paramTypes);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
index 424861b..7bffe3a 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/Schema.java
@@ -31,6 +31,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto;
import org.apache.tajo.common.ProtoObject;
import org.apache.tajo.common.TajoDataTypes.DataType;
import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.exception.TajoRuntimeException;
import org.apache.tajo.json.GsonObject;
import org.apache.tajo.util.StringUtils;
import org.apache.tajo.util.TUtil;
@@ -419,8 +420,7 @@ public class Schema implements ProtoObject<SchemaProto>, Cloneable, GsonObject {
public synchronized Schema addColumn(String name, TypeDesc typeDesc) {
String normalized = name;
if(fieldsByQualifiedName.containsKey(normalized)) {
- LOG.error("Already exists column " + normalized);
- throw new DuplicateColumnException(normalized);
+ throw new TajoRuntimeException(new DuplicateColumnException(normalized));
}
Column newCol = new Column(normalized, typeDesc);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
index d1f17fd..56c11e1 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousFunctionException.java
@@ -20,10 +20,16 @@ package org.apache.tajo.catalog.exception;
import org.apache.tajo.common.TajoDataTypes.DataType;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature;
public class AmbiguousFunctionException extends CatalogException {
+
+ public AmbiguousFunctionException(PrimitiveProtos.ReturnState state) {
+ super(state);
+ }
+
public AmbiguousFunctionException(String funcName, DataType[] parameters) {
super(Errors.ResultCode.AMBIGUOUS_FUNCTION, buildSimpleFunctionSignature(funcName, parameters));
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
index 65ff746..27f5534 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/AmbiguousTableException.java
@@ -18,12 +18,15 @@
package org.apache.tajo.catalog.exception;
-import org.apache.tajo.common.TajoDataTypes.DataType;
import org.apache.tajo.error.Errors;
-
-import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class AmbiguousTableException extends CatalogException {
+
+ public AmbiguousTableException(ReturnState state) {
+ super(state);
+ }
+
public AmbiguousTableException(String tableName) {
super(Errors.ResultCode.AMBIGUOUS_TABLE, tableName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
index 7098800..e19199c 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/CatalogException.java
@@ -19,11 +19,16 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors.ResultCode;
-import org.apache.tajo.exception.TajoRuntimeException;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
-public class CatalogException extends TajoRuntimeException {
+public class CatalogException extends TajoException {
private static final long serialVersionUID = -26362412527118618L;
+ public CatalogException(ReturnState state) {
+ super(state);
+ }
+
public CatalogException(ResultCode code, String...args) {
super(code, args);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
index 121a289..88b067a 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateColumnException.java
@@ -19,10 +19,15 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class DuplicateColumnException extends CatalogException {
private static final long serialVersionUID = 6766228091940775275L;
+ public DuplicateColumnException(ReturnState state) {
+ super(state);
+ }
+
public DuplicateColumnException(String columnName) {
super(Errors.ResultCode.DUPLICATE_COLUMN, columnName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
index 69e37d3..8725d49 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateDatabaseException.java
@@ -20,8 +20,14 @@ package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class DuplicateDatabaseException extends CatalogException {
+
+ public DuplicateDatabaseException(ReturnState state) {
+ super(state);
+ }
public DuplicateDatabaseException(String dbName) {
super(Errors.ResultCode.DUPLICATE_DATABASE, dbName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
index c510b16..b9e71c2 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateIndexException.java
@@ -19,10 +19,15 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class DuplicateIndexException extends CatalogException {
private static final long serialVersionUID = 3705839985189534673L;
+ public DuplicateIndexException(ReturnState state) {
+ super(state);
+ }
+
public DuplicateIndexException(String indexName) {
super(Errors.ResultCode.DUPLICATE_INDEX, indexName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
index bdec4fc..bbb50b9 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicatePartitionException.java
@@ -19,10 +19,15 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class DuplicatePartitionException extends CatalogException {
private static final long serialVersionUID = 277182608283894930L;
+ public DuplicatePartitionException(ReturnState state) {
+ super(state);
+ }
+
public DuplicatePartitionException(String partitionName) {
super(Errors.ResultCode.DUPLICATE_PARTITION, partitionName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
index 74fa39f..2111186 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/DuplicateTableException.java
@@ -20,10 +20,15 @@ package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class DuplicateTableException extends CatalogException {
private static final long serialVersionUID = -641623770742392865L;
+ public DuplicateTableException(ReturnState state) {
+ super(state);
+ }
+
public DuplicateTableException(String relName) {
super(Errors.ResultCode.DUPLICATE_TABLE, relName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
index 43b7410..39d6130 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedColumnException.java
@@ -20,10 +20,15 @@ package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UndefinedColumnException extends CatalogException {
private static final long serialVersionUID = 277182608283894937L;
+ public UndefinedColumnException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedColumnException(String columnName) {
super(ResultCode.UNDEFINED_COLUMN, columnName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
index 8294add..75dcd49 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedDatabaseException.java
@@ -20,10 +20,15 @@ package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UndefinedDatabaseException extends CatalogException {
private static final long serialVersionUID = 277182608283894937L;
+ public UndefinedDatabaseException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedDatabaseException(String dbName) {
super(Errors.ResultCode.UNDEFINED_DATABASE, dbName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
index 175b597..0ac2a93 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedFunctionException.java
@@ -19,17 +19,19 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.common.TajoDataTypes;
-import org.apache.tajo.error.Errors;
import org.apache.tajo.error.Errors.ResultCode;
-import org.apache.tajo.exception.TajoException;
-import org.apache.tajo.exception.TajoRuntimeException;
import org.apache.tajo.function.FunctionUtil;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
import java.util.Collection;
public class UndefinedFunctionException extends CatalogException {
private static final long serialVersionUID = 5062193018697228028L;
+ public UndefinedFunctionException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedFunctionException(String signature) {
super(ResultCode.UNDEFINED_FUNCTION, signature);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
index 282f0a2..1033c44 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedPartitionException.java
@@ -19,11 +19,16 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UndefinedPartitionException extends CatalogException {
private static final long serialVersionUID = 277182608283894938L;
+ public UndefinedPartitionException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedPartitionException(String partitionName) {
super(ResultCode.UNDEFINED_PARTITION, partitionName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
index 2513783..bbdb69d 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTableException.java
@@ -21,10 +21,15 @@ package org.apache.tajo.catalog.exception;
import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UndefinedTableException extends CatalogException {
private static final long serialVersionUID = 277182608283894937L;
+ public UndefinedTableException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedTableException(String dbName, String tbName) {
super(ResultCode.UNDEFINED_TABLE, CatalogUtil.buildFQName(dbName, tbName));
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
index ffe5789..f3faf6e 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/UndefinedTablespaceException.java
@@ -19,10 +19,15 @@
package org.apache.tajo.catalog.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UndefinedTablespaceException extends CatalogException {
private static final long serialVersionUID = 277182608283894937L;
+ public UndefinedTablespaceException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedTablespaceException(String spaceName) {
super(Errors.ResultCode.UNDEFINED_TABLESPACE, spaceName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
index cf1a24a..4c251af 100644
--- a/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
+++ b/tajo-catalog/tajo-catalog-common/src/test/java/org/apache/tajo/catalog/TestSchema.java
@@ -22,6 +22,7 @@ import org.apache.tajo.catalog.exception.DuplicateColumnException;
import org.apache.tajo.catalog.json.CatalogGsonHelper;
import org.apache.tajo.catalog.proto.CatalogProtos.SchemaProto;
import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.exception.TajoRuntimeException;
import org.junit.Before;
import org.junit.Test;
@@ -191,7 +192,7 @@ public class TestSchema {
assertEquals(schema.size(), schema3.size());
}
- @Test(expected = DuplicateColumnException.class)
+ @Test(expected = TajoRuntimeException.class)
public final void testAddExistColumn() {
Schema schema = new Schema();
schema.addColumn("abc", Type.FLOAT8);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java b/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
index 5ae5969..39b3cb9 100644
--- a/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogUtil.java
@@ -47,7 +47,7 @@ public class HiveCatalogUtil {
}
}
- public static TajoDataTypes.Type getTajoFieldType(String dataType) {
+ public static TajoDataTypes.Type getTajoFieldType(String dataType) throws CatalogException {
Preconditions.checkNotNull(dataType);
if(dataType.equalsIgnoreCase(serdeConstants.INT_TYPE_NAME)) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
index 4ed1ae8..e2dcfcd 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
@@ -547,20 +547,22 @@ public class CatalogServer extends AbstractService {
@Override
public TableResponse getTableDesc(RpcController controller,
- TableIdentifierProto request) throws ServiceException {
+ TableIdentifierProto request) {
String dbName = request.getDatabaseName();
String tbName = request.getTableName();
- if (metaDictionary.isSystemDatabase(dbName)) {
- return TableResponse.newBuilder()
- .setState(OK)
- .setTable(metaDictionary.getTableDesc(tbName))
- .build();
- } else {
- rlock.lock();
- try {
- boolean contain;
+ rlock.lock();
+ try {
+
+ if (metaDictionary.isSystemDatabase(dbName)) {
+
+ return TableResponse.newBuilder()
+ .setState(OK)
+ .setTable(metaDictionary.getTableDesc(tbName))
+ .build();
+ } else {
+ boolean contain;
contain = store.existDatabase(dbName);
if (contain) {
@@ -580,17 +582,17 @@ public class CatalogServer extends AbstractService {
.setState(errUndefinedDatabase(dbName))
.build();
}
+ }
- } catch (Throwable t) {
- printStackTraceIfError(LOG, t);
+ } catch (Throwable t) {
+ printStackTraceIfError(LOG, t);
- return TableResponse.newBuilder()
- .setState(returnError(t))
- .build();
+ return TableResponse.newBuilder()
+ .setState(returnError(t))
+ .build();
- } finally {
- rlock.unlock();
- }
+ } finally {
+ rlock.unlock();
}
}
@@ -718,15 +720,15 @@ public class CatalogServer extends AbstractService {
String dbName = request.getDatabaseName();
String tbName = request.getTableName();
- if (metaDictionary.isSystemDatabase(dbName)) {
- return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName);
+ rlock.lock();
+ try {
- } else {
- rlock.lock();
- try {
+ if (metaDictionary.isSystemDatabase(dbName)) {
+ return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName);
- boolean contain = store.existDatabase(dbName);
+ } else {
+ boolean contain = store.existDatabase(dbName);
if (contain) {
if (store.existTable(dbName, tbName)) {
return OK;
@@ -736,14 +738,14 @@ public class CatalogServer extends AbstractService {
} else {
return errUndefinedDatabase(dbName);
}
+ }
- } catch (Throwable t) {
- printStackTraceIfError(LOG, t);
- return returnError(t);
+ } catch (Throwable t) {
+ printStackTraceIfError(LOG, t);
+ return returnError(t);
- } finally {
- rlock.unlock();
- }
+ } finally {
+ rlock.unlock();
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
index f798c1d..b59d61c 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
@@ -91,7 +91,7 @@ public class InfoSchemaMetadataDictionary {
return systemTableNames;
}
- private TableDescriptor getTableDescriptor(String tableName) {
+ private TableDescriptor getTableDescriptor(String tableName) throws UndefinedTableException {
TableDescriptor tableDescriptor = null;
if (tableName == null || tableName.isEmpty()) {
@@ -106,11 +106,15 @@ public class InfoSchemaMetadataDictionary {
break;
}
}
-
+
+ if (tableDescriptor == null) {
+ throw new UndefinedTableException(tableName);
+ }
+
return tableDescriptor;
}
- public CatalogProtos.TableDescProto getTableDesc(String tableName) {
+ public CatalogProtos.TableDescProto getTableDesc(String tableName) throws UndefinedTableException {
TableDescriptor tableDescriptor;
tableDescriptor = getTableDescriptor(tableName);
@@ -121,7 +125,7 @@ public class InfoSchemaMetadataDictionary {
return tableDescriptor.getTableDescription();
}
- public boolean existTable(String tableName) {
+ public boolean existTable(String tableName) throws UndefinedTableException {
return getTableDescriptor(tableName) != null;
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 b62624a..a3eb0c3 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
@@ -170,16 +170,12 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
createBaseTable();
LOG.info("The base tables of CatalogServer are created.");
} catch (CatalogException ce) {
- try {
- dropBaseTable();
- } catch (Throwable t) {
- LOG.error(t, t);
- }
+ dropBaseTable();
throw ce;
}
}
}
- } catch (Exception se) {
+ } catch (Throwable se) {
throw new TajoInternalError(se);
}
}
@@ -200,7 +196,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
return catalogUri;
}
- protected boolean isConnValid(int timeout) throws CatalogException {
+ protected boolean isConnValid(int timeout) {
boolean isValid = false;
try {
@@ -703,7 +699,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
}
- private TableSpaceInternal getTableSpaceInfo(String spaceName) {
+ private TableSpaceInternal getTableSpaceInfo(String spaceName) throws UndefinedTablespaceException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet res = null;
@@ -742,7 +738,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
return res.getInt(1);
} catch (SQLException se) {
- throw new UndefinedTableException(databaseName, tableName);
+ throw new TajoInternalError(se);
} finally {
CatalogUtil.closeQuietly(pstmt, res);
}
@@ -1034,7 +1030,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
- private Map<String, String> getTableOptions(final int tableId) throws CatalogException {
+ private Map<String, String> getTableOptions(final int tableId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet res = null;
@@ -1335,7 +1331,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
}
- private int getDatabaseId(String databaseName) throws SQLException {
+ private int getDatabaseId(String databaseName) throws SQLException, UndefinedDatabaseException {
String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES);
if (LOG.isDebugEnabled()) {
@@ -1394,7 +1390,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
public void dropTableInternal(Connection conn, String databaseName, final String tableName)
- throws SQLException {
+ throws SQLException, UndefinedDatabaseException {
PreparedStatement pstmt = null;
@@ -1507,7 +1503,9 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
}
}
- public Pair<Integer, String> getDatabaseIdAndUri(String databaseName) throws SQLException {
+ public Pair<Integer, String> getDatabaseIdAndUri(String databaseName)
+ throws SQLException, UndefinedDatabaseException {
+
String sql =
"SELECT DB_ID, SPACE_URI from " + TB_DATABASES + " natural join " + TB_SPACES + " WHERE db_name = ?";
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 bcd9ce9..c822482 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
@@ -22,26 +22,13 @@
package org.apache.tajo.catalog.store;
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.*;
import org.apache.tajo.catalog.exception.*;
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.SortSpecProto;
-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;
-import org.apache.tajo.catalog.proto.CatalogProtos.TableStatsProto;
+import org.apache.tajo.catalog.proto.CatalogProtos.*;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto;
import org.apache.tajo.util.KeyValueSet;
import org.apache.tajo.util.TUtil;
@@ -50,7 +37,7 @@ import java.io.IOException;
import java.util.*;
import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceType;
-import static org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
+import static org.apache.tajo.catalog.proto.CatalogProtos.*;
/**
* CatalogServer guarantees that all operations are thread-safe.
@@ -198,7 +185,7 @@ public class MemStore implements CatalogStore {
* Get a database namespace from a Map instance.
*/
private <T> Map<String, T> checkAndGetDatabaseNS(final Map<String, Map<String, T>> databaseMap,
- String databaseName) {
+ String databaseName) throws UndefinedDatabaseException {
if (databaseMap.containsKey(databaseName)) {
return databaseMap.get(databaseName);
} else {
@@ -372,7 +359,8 @@ public class MemStore implements CatalogStore {
partitions.put(tableName, protoMap);
}
- private void dropPartition(String databaseName, String tableName, String partitionName) {
+ private void dropPartition(String databaseName, String tableName, String partitionName)
+ throws UndefinedPartitionException {
if(!partitions.containsKey(tableName)) {
throw new UndefinedPartitionException(partitionName);
} else {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
index dd8e2a2..9d767a0 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
@@ -64,15 +64,15 @@ public class XMLCatalogSchemaManager {
private final Unmarshaller unmarshaller;
private StoreObject catalogStore;
- public XMLCatalogSchemaManager(String schemaPath) throws CatalogException {
+ public XMLCatalogSchemaManager(String schemaPath) {
this.schemaPath = schemaPath;
try {
JAXBContext context = JAXBContext.newInstance(StoreObject.class);
unmarshaller = context.createUnmarshaller();
loadFromXmlFiles();
- } catch (Exception e) {
- throw new TajoInternalError(e);
+ } catch (Throwable t) {
+ throw new TajoInternalError(t);
}
}
@@ -489,7 +489,7 @@ public class XMLCatalogSchemaManager {
return files;
}
- protected void mergeXmlSchemas(final List<StoreObject> storeObjects) throws CatalogException {
+ protected void mergeXmlSchemas(final List<StoreObject> storeObjects) {
if (storeObjects.size() <= 0) {
throw new TajoInternalError("Unable to find a schema file.");
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
index 77a7000..72f7f7a 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tools/TajoAdmin.java
@@ -416,8 +416,8 @@ public class TajoAdmin {
} else {
writer.write("ERROR:" + status.getErrorMessage());
}
- } catch (SQLException e) {
- writer.write("ERROR:" + e.getMessage());
+ } catch (Throwable t) {
+ writer.write("ERROR:" + t.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
index c6409f1..eadd4df 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
@@ -34,6 +34,7 @@ import org.apache.tajo.client.*;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.conf.TajoConf.ConfVars;
import org.apache.tajo.exception.ReturnStateUtil;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.ipc.ClientProtos;
import org.apache.tajo.service.ServiceTrackerFactory;
import org.apache.tajo.util.FileUtil;
@@ -296,7 +297,7 @@ public class TajoCli {
}
}
- private void processSessionVarCommand(String[] confCommands) throws SQLException {
+ private void processSessionVarCommand(String[] confCommands) throws TajoException {
for (String eachParam: confCommands) {
String[] tokens = eachParam.split("=");
if (tokens.length != 2) {
@@ -488,7 +489,7 @@ public class TajoCli {
return 0;
}
- private void executeJsonQuery(String json) throws SQLException {
+ private void executeJsonQuery(String json) throws TajoException {
long startTime = System.currentTimeMillis();
ClientProtos.SubmitQueryResponse response = client.executeQueryWithJson(json);
@@ -581,7 +582,7 @@ public class TajoCli {
}
}
- private void waitForQueryCompleted(QueryId queryId) throws SQLException {
+ private void waitForQueryCompleted(QueryId queryId) {
// if query is empty string
if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
return;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
index e75171d..3682a74 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java
@@ -20,6 +20,7 @@ package org.apache.tajo.cli.tsql.commands;
import com.google.protobuf.ServiceException;
import org.apache.tajo.cli.tsql.TajoCli;
+import org.apache.tajo.exception.TajoException;
import java.sql.SQLException;
@@ -51,7 +52,7 @@ public class ConnectDatabaseCommand extends TajoShellCommand {
context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n",
context.getCurrentDatabase(), client.getUserInfo().getUserName()));
}
- } catch (SQLException se) {
+ } catch (TajoException se) {
if (se.getMessage() != null) {
context.getOutput().write(se.getMessage());
} else {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
index c1c286d..0ae07d5 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java
@@ -21,6 +21,7 @@ package org.apache.tajo.cli.tsql.commands;
import com.google.protobuf.ServiceException;
import org.apache.tajo.SessionVars;
import org.apache.tajo.cli.tsql.TajoCli;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
import org.apache.tajo.util.StringUtils;
import java.sql.SQLException;
@@ -46,13 +47,13 @@ public class SetCommand extends TajoShellCommand {
}
}
- private void updateSessionVariable(String key, String val) throws SQLException {
+ private void updateSessionVariable(String key, String val) throws NoSuchSessionVariableException {
Map<String, String> variables = new HashMap<String, String>();
variables.put(key, val);
client.updateSessionVariables(variables);
}
- public void set(String key, String val) throws SQLException {
+ public void set(String key, String val) throws NoSuchSessionVariableException {
SessionVars sessionVar;
if (SessionVars.exists(key)) { // if the variable is one of the session variables
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-client/pom.xml b/tajo-client/pom.xml
index e6be476..1044d28 100644
--- a/tajo-client/pom.xml
+++ b/tajo-client/pom.xml
@@ -51,8 +51,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.7</source>
+ <target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
index 5e923e0..bc63f84 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClient.java
@@ -22,9 +22,11 @@ import org.apache.tajo.annotation.Nullable;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.exception.*;
import org.apache.tajo.catalog.partition.PartitionMethodDesc;
import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
+import org.apache.tajo.exception.TajoException;
import java.io.Closeable;
import java.net.URI;
@@ -39,7 +41,7 @@ public interface CatalogAdminClient extends Closeable {
* @return True if created successfully.
* @throws java.sql.SQLException
*/
- boolean createDatabase(final String databaseName) throws SQLException;
+ boolean createDatabase(final String databaseName) throws DuplicateDatabaseException;
/**
* Does the database exist?
*
@@ -47,7 +49,7 @@ public interface CatalogAdminClient extends Closeable {
* @return True if so.
* @throws java.sql.SQLException
*/
- boolean existDatabase(final String databaseName) throws SQLException;
+ boolean existDatabase(final String databaseName);
/**
* Drop the database
*
@@ -55,9 +57,9 @@ public interface CatalogAdminClient extends Closeable {
* @return True if the database is dropped successfully.
* @throws java.sql.SQLException
*/
- boolean dropDatabase(final String databaseName) throws SQLException;
+ boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException;
- List<String> getAllDatabaseNames() throws SQLException;
+ List<String> getAllDatabaseNames();
/**
* Does the table exist?
@@ -65,7 +67,7 @@ public interface CatalogAdminClient extends Closeable {
* @param tableName The table name to be checked. This name is case sensitive.
* @return True if so.
*/
- boolean existTable(final String tableName) throws SQLException;
+ boolean existTable(final String tableName);
/**
* Create an external table.
@@ -79,7 +81,7 @@ public interface CatalogAdminClient extends Closeable {
* @throws java.sql.SQLException
*/
TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
- final TableMeta meta) throws SQLException;
+ final TableMeta meta) throws DuplicateTableException;
/**
* Create an external table.
@@ -95,7 +97,7 @@ public interface CatalogAdminClient extends Closeable {
*/
TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
final TableMeta meta, final PartitionMethodDesc partitionMethodDesc)
- throws SQLException;
+ throws DuplicateTableException;
/**
* Drop a table
@@ -104,7 +106,7 @@ public interface CatalogAdminClient extends Closeable {
* @return True if the table is dropped successfully.
* @throws java.sql.SQLException
*/
- boolean dropTable(final String tableName) throws SQLException;
+ boolean dropTable(final String tableName) throws UndefinedTableException;
/**
* Drop a table.
@@ -114,7 +116,7 @@ public interface CatalogAdminClient extends Closeable {
* @return True if the table is dropped successfully.
* @throws java.sql.SQLException
*/
- boolean dropTable(final String tableName, final boolean purge) throws SQLException;
+ boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException;
/**
* Get a list of table names.
@@ -124,7 +126,7 @@ public interface CatalogAdminClient extends Closeable {
* in the current database of this session.
* @throws java.sql.SQLException
*/
- List<String> getTableList(@Nullable final String databaseName) throws SQLException;
+ List<String> getTableList(@Nullable final String databaseName);
/**
* Get a table description
@@ -133,9 +135,9 @@ public interface CatalogAdminClient extends Closeable {
* @return Table description
* @throws java.sql.SQLException
*/
- TableDesc getTableDesc(final String tableName) throws SQLException;
+ TableDesc getTableDesc(final String tableName) throws UndefinedTableException;
- List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName) throws SQLException;
+ List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName);
IndexDescProto getIndex(final String indexName) throws SQLException;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
index 8745d19..d4d8a86 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/CatalogAdminClientImpl.java
@@ -24,16 +24,16 @@ import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.exception.*;
import org.apache.tajo.catalog.partition.PartitionMethodDesc;
import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.catalog.proto.CatalogProtos.*;
-import org.apache.tajo.error.Errors.ResultCode;
-import org.apache.tajo.ipc.ClientProtos;
-import org.apache.tajo.ipc.ClientProtos.*;
-import org.apache.tajo.exception.SQLExceptionUtil;
+import org.apache.tajo.error.Errors;
import org.apache.tajo.ipc.ClientProtos;
import org.apache.tajo.ipc.ClientProtos.DropTableRequest;
+import org.apache.tajo.ipc.ClientProtos.GetIndexWithColumnsRequest;
import org.apache.tajo.rpc.NettyClientBase;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListResponse;
import java.io.IOException;
@@ -41,7 +41,7 @@ import java.net.URI;
import java.sql.SQLException;
import java.util.List;
-import static org.apache.tajo.exception.ReturnStateUtil.isSuccess;
+import static org.apache.tajo.exception.ReturnStateUtil.*;
import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError;
import static org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface;
@@ -53,19 +53,27 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
}
@Override
- public boolean createDatabase(final String databaseName) throws SQLException {
+ public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException {
final BlockingInterface stub = conn.getTMStub();
try {
- return isSuccess(stub.createDatabase(null, conn.getSessionedString(databaseName)));
+ PrimitiveProtos.ReturnState state = stub.createDatabase(null, conn.getSessionedString(databaseName));
+
+ if (isThisError(state, Errors.ResultCode.DUPLICATE_DATABASE)) {
+ throw new DuplicateDatabaseException(state);
+ }
+
+ ensureOk(state);
+ return true;
+
} catch (ServiceException e) {
throw new RuntimeException(e);
}
}
@Override
- public boolean existDatabase(final String databaseName) throws SQLException {
+ public boolean existDatabase(final String databaseName) {
final BlockingInterface stub = conn.getTMStub();
@@ -77,19 +85,24 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
}
@Override
- public boolean dropDatabase(final String databaseName) throws SQLException {
+ public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException {
final BlockingInterface stub = conn.getTMStub();
try {
- return isSuccess(stub.dropDatabase(null, conn.getSessionedString(databaseName)));
+ PrimitiveProtos.ReturnState state = stub.dropDatabase(null, conn.getSessionedString(databaseName));
+ if (isThisError(state, Errors.ResultCode.UNDEFINED_DATABASE)) {
+ throw new UndefinedDatabaseException(state);
+ }
+ ensureOk(state);
+ return true;
} catch (ServiceException e) {
throw new RuntimeException(e);
}
}
@Override
- public List<String> getAllDatabaseNames() throws SQLException {
+ public List<String> getAllDatabaseNames() {
final BlockingInterface stub = conn.getTMStub();
@@ -100,26 +113,34 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
}
}
- public boolean existTable(final String tableName) throws SQLException {
+ public boolean existTable(final String tableName) {
final BlockingInterface stub = conn.getTMStub();
+ PrimitiveProtos.ReturnState state;
try {
- return isSuccess(stub.existTable(null, conn.getSessionedString(tableName)));
+ state = stub.existTable(null, conn.getSessionedString(tableName));
} catch (ServiceException e) {
throw new RuntimeException(e);
}
+
+ if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) {
+ return false;
+ }
+
+ ensureOk(state);
+ return true;
}
@Override
public TableDesc createExternalTable(String tableName, Schema schema, URI path, TableMeta meta)
- throws SQLException {
+ throws DuplicateTableException {
return createExternalTable(tableName, schema, path, meta, null);
}
public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
final TableMeta meta, final PartitionMethodDesc partitionMethodDesc)
- throws SQLException {
+ throws DuplicateTableException {
NettyClientBase client = conn.getTajoMasterConnection();
conn.checkSessionAndGet(client);
@@ -143,20 +164,21 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
throw new RuntimeException(e);
}
- if (isSuccess(res.getState())) {
- return CatalogUtil.newTableDesc(res.getTable());
- } else {
- throw SQLExceptionUtil.toSQLException(res.getState());
+ if (isThisError(res.getState(), Errors.ResultCode.DUPLICATE_TABLE)) {
+ throw new DuplicateTableException(res.getState());
}
+
+ ensureOk(res.getState());
+ return CatalogUtil.newTableDesc(res.getTable());
}
@Override
- public boolean dropTable(String tableName) throws SQLException {
+ public boolean dropTable(String tableName) throws UndefinedTableException {
return dropTable(tableName, false);
}
@Override
- public boolean dropTable(final String tableName, final boolean purge) throws SQLException {
+ public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException {
final BlockingInterface stub = conn.getTMStub();
final DropTableRequest request = DropTableRequest.newBuilder()
@@ -165,15 +187,24 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
.setPurge(purge)
.build();
+
+ PrimitiveProtos.ReturnState state;
try {
- return isSuccess(stub.dropTable(null, request));
+ state = stub.dropTable(null, request);
} catch (ServiceException e) {
throw new RuntimeException(e);
}
+
+ if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) {
+ throw new UndefinedTableException(state);
+ }
+
+ ensureOk(state);
+ return true;
}
@Override
- public List<String> getTableList(@Nullable final String databaseName) throws SQLException {
+ public List<String> getTableList(@Nullable final String databaseName) {
final BlockingInterface stub = conn.getTMStub();
@@ -184,12 +215,12 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
throw new RuntimeException(e);
}
- throwIfError(response.getState());
+ ensureOk(response.getState());
return response.getValuesList();
}
@Override
- public TableDesc getTableDesc(final String tableName) throws SQLException {
+ public TableDesc getTableDesc(final String tableName) throws UndefinedTableException {
final BlockingInterface stub = conn.getTMStub();
@@ -200,12 +231,16 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
throw new RuntimeException(e);
}
- throwIfError(res.getState());
+ if (isThisError(res.getState(), Errors.ResultCode.UNDEFINED_TABLE)) {
+ throw new UndefinedTableException(res.getState());
+ }
+
+ ensureOk(res.getState());
return CatalogUtil.newTableDesc(res.getTable());
}
@Override
- public List<FunctionDescProto> getFunctions(final String functionName) throws SQLException {
+ public List<FunctionDescProto> getFunctions(final String functionName) {
final BlockingInterface stub = conn.getTMStub();
@@ -217,7 +252,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient {
throw new RuntimeException(e);
}
- throwIfError(res.getState());
+ ensureOk(res.getState());
return res.getFunctionList();
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java
new file mode 100644
index 0000000..2ecc078
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client;
+
+import com.google.common.collect.Maps;
+import org.apache.tajo.catalog.exception.*;
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.exception.*;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+import static org.apache.tajo.error.Errors.ResultCode.*;
+import static org.apache.tajo.exception.ReturnStateUtil.isError;
+
+/**
+ * Exception related utilities. Especially, it provides a way to recover @{link ReturnState} into TajoException.
+ */
+public class ClientExceptionUtil {
+
+ static Map<ResultCode, Class<? extends TajoExceptionInterface>> EXCEPTIONS = Maps.newHashMap();
+
+ static {
+
+ // General Errors
+ ADD_EXCEPTION(INTERNAL_ERROR, TajoInternalError.class);
+ ADD_EXCEPTION(FEATURE_NOT_SUPPORTED, UnsupportedException.class);
+
+ ADD_EXCEPTION(UNDEFINED_TABLESPACE, UndefinedTablespaceException.class);
+ ADD_EXCEPTION(UNDEFINED_DATABASE, UndefinedDatabaseException.class);
+ // ADD_EXCEPTION(UNDEFINED_SCHEMA, );
+ ADD_EXCEPTION(UNDEFINED_TABLE, UndefinedTableException.class);
+ ADD_EXCEPTION(UNDEFINED_COLUMN, UndefinedColumnException.class);
+ ADD_EXCEPTION(UNDEFINED_FUNCTION, UndefinedFunctionException.class);
+ ADD_EXCEPTION(UNDEFINED_PARTITION, UndefinedPartitionException.class);
+ ADD_EXCEPTION(UNDEFINED_OPERATOR, UndefinedOperatorException.class);
+
+ ADD_EXCEPTION(DUPLICATE_TABLESPACE, DuplicateTableException.class);
+ ADD_EXCEPTION(DUPLICATE_DATABASE, DuplicateDatabaseException.class);
+ // ADD_EXCEPTION(DUPLICATE_SCHEMA, );
+ ADD_EXCEPTION(DUPLICATE_TABLE, DuplicateTableException.class);
+ ADD_EXCEPTION(DUPLICATE_COLUMN, DuplicateColumnException.class);
+ // ADD_EXCEPTION(DUPLICATE_ALIAS, );
+ ADD_EXCEPTION(DUPLICATE_INDEX, DuplicateIndexException.class);
+ ADD_EXCEPTION(DUPLICATE_PARTITION, DuplicatePartitionException.class);
+
+ ADD_EXCEPTION(AMBIGUOUS_TABLE, AmbiguousTableException.class);
+ ADD_EXCEPTION(AMBIGUOUS_COLUMN, AmbiguousColumnException.class);
+ }
+
+ private static void ADD_EXCEPTION(ResultCode code, Class<? extends TajoExceptionInterface> cls) {
+ EXCEPTIONS.put(code, cls);
+ }
+
+ public static void throwIfError(ReturnState state) throws TajoException {
+ if (isError(state)) {
+ throw toTajoException(state);
+ }
+ }
+
+ public static TajoException toTajoException(ReturnState state) {
+
+ if (state.getReturnCode() == ResultCode.INTERNAL_ERROR) {
+ throw new TajoInternalError(state);
+
+ } else if (EXCEPTIONS.containsKey(state.getReturnCode())) {
+ Object exception = null;
+ try {
+ Class clazz = EXCEPTIONS.get(state.getReturnCode());
+ Constructor c = clazz.getConstructor(ReturnState.class);
+ exception = c.newInstance(new Object[]{state});
+ } catch (Throwable t) {
+ throw new TajoInternalError(t);
+ }
+
+ if (exception instanceof TajoException) {
+ return (TajoException) exception;
+ } else if (exception instanceof TajoRuntimeException) {
+ throw ((TajoRuntimeException) exception);
+ } else {
+ throw ((TajoError) exception);
+ }
+
+ } else {
+ throw new TajoInternalError("Unregistred Exception (" + state.getReturnCode().name() +"): "
+ + state.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java b/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
index acbc33f..48ba5f6 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/InvalidClientSessionException.java
@@ -18,10 +18,11 @@
package org.apache.tajo.client;
-import com.google.protobuf.ServiceException;
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoRuntimeException;
-public class InvalidClientSessionException extends ServiceException {
- public InvalidClientSessionException(String message) {
- super(message);
+public class InvalidClientSessionException extends TajoRuntimeException {
+ public InvalidClientSessionException(String sessionId) {
+ super(Errors.ResultCode.INVALID_SESSION, sessionId);
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 ffe3d96..966bddf 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
@@ -18,9 +18,11 @@
package org.apache.tajo.client;
-import com.google.protobuf.ServiceException;
import org.apache.tajo.QueryId;
import org.apache.tajo.auth.UserRoleInfo;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.ipc.ClientProtos;
import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto;
import org.apache.tajo.ipc.ClientProtos.QueryInfoProto;
@@ -28,14 +30,11 @@ import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse;
import org.apache.tajo.jdbc.TajoMemoryResultSet;
import java.io.Closeable;
-import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
-import static org.apache.tajo.TajoIdProtos.SessionIdProto;
-
public interface QueryClient extends Closeable {
boolean isConnected();
@@ -59,32 +58,32 @@ public interface QueryClient extends Closeable {
* Call to QueryMaster closing query resources
* @param queryId
*/
- void closeQuery(final QueryId queryId) throws SQLException;
+ void closeQuery(final QueryId queryId);
void closeNonForwardQuery(final QueryId queryId) throws SQLException;
- String getCurrentDatabase() throws SQLException;
+ String getCurrentDatabase();
- Boolean selectDatabase(final String databaseName) throws SQLException;
+ Boolean selectDatabase(final String databaseName) throws UndefinedDatabaseException;
- Map<String, String> updateSessionVariables(final Map<String, String> variables) throws SQLException;
+ Map<String, String> updateSessionVariables(final Map<String, String> variables) throws NoSuchSessionVariableException;
- Map<String, String> unsetSessionVariables(final List<String> variables) throws SQLException;
+ Map<String, String> unsetSessionVariables(final List<String> variables) throws NoSuchSessionVariableException;
- String getSessionVariable(final String varname) throws SQLException;
+ String getSessionVariable(final String varname) throws NoSuchSessionVariableException;
- Boolean existSessionVariable(final String varname) throws SQLException;
+ Boolean existSessionVariable(final String varname);
- Map<String, String> getAllSessionVariables() throws SQLException;
+ Map<String, String> getAllSessionVariables();
/**
* It submits a query statement and get a response immediately.
* The response only contains a query id, and submission status.
* In order to get the result, you should use {@link #getQueryResult(org.apache.tajo.QueryId)}.
*/
- SubmitQueryResponse executeQuery(final String sql) throws SQLException;
+ SubmitQueryResponse executeQuery(final String sql);
- SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException;
+ SubmitQueryResponse executeQueryWithJson(final String json);
/**
* It submits a query statement and get a response.
@@ -94,11 +93,11 @@ public interface QueryClient extends Closeable {
*
* @return If failed, return null.
*/
- ResultSet executeQueryAndGetResult(final String sql) throws SQLException;
+ ResultSet executeQueryAndGetResult(final String sql) throws TajoException;
- ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException;
+ ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException;
- QueryStatus getQueryStatus(QueryId queryId) throws SQLException;
+ QueryStatus getQueryStatus(QueryId queryId);
ResultSet getQueryResult(QueryId queryId) throws SQLException;
@@ -108,17 +107,17 @@ public interface QueryClient extends Closeable {
TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException;
- boolean updateQuery(final String sql) throws SQLException;
+ boolean updateQuery(final String sql) throws TajoException;
- boolean updateQueryWithJson(final String json) throws SQLException;
+ boolean updateQueryWithJson(final String json) throws TajoException;
List<ClientProtos.BriefQueryInfo> getRunningQueryList() throws SQLException;
- List<ClientProtos.BriefQueryInfo> getFinishedQueryList() throws SQLException;
+ List<ClientProtos.BriefQueryInfo> getFinishedQueryList();
List<ClientProtos.WorkerResourceInfo> getClusterInfo() throws SQLException;
- QueryStatus killQuery(final QueryId queryId) throws SQLException;
+ QueryStatus killQuery(final QueryId queryId);
QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 e7317e5..02110c0 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
@@ -27,7 +27,10 @@ import org.apache.tajo.auth.UserRoleInfo;
import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
import org.apache.tajo.exception.SQLExceptionUtil;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.ipc.ClientProtos;
import org.apache.tajo.ipc.QueryMasterClientProtocol;
import org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface;
@@ -45,6 +48,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import static org.apache.tajo.exception.ReturnStateUtil.ensureOk;
import static org.apache.tajo.exception.ReturnStateUtil.isSuccess;
import static org.apache.tajo.exception.ReturnStateUtil.returnError;
import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError;
@@ -95,56 +99,56 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public void closeQuery(QueryId queryId) throws SQLException {
+ public void closeQuery(QueryId queryId) {
closeNonForwardQuery(queryId);
}
@Override
- public void closeNonForwardQuery(QueryId queryId) throws SQLException {
+ public void closeNonForwardQuery(QueryId queryId) {
try {
- throwIfError(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId)));
+ ensureOk(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId)));
} catch (ServiceException e) {
throw new RuntimeException(e);
}
}
@Override
- public String getCurrentDatabase() throws SQLException {
+ public String getCurrentDatabase() {
return conn.getCurrentDatabase();
}
@Override
- public Boolean selectDatabase(String databaseName) throws SQLException {
+ public Boolean selectDatabase(String databaseName) throws UndefinedDatabaseException {
return conn.selectDatabase(databaseName);
}
@Override
- public Map<String, String> updateSessionVariables(Map<String, String> variables) throws SQLException {
+ public Map<String, String> updateSessionVariables(Map<String, String> variables) throws NoSuchSessionVariableException {
return conn.updateSessionVariables(variables);
}
@Override
- public Map<String, String> unsetSessionVariables(List<String> variables) throws SQLException {
+ public Map<String, String> unsetSessionVariables(List<String> variables) throws NoSuchSessionVariableException {
return conn.unsetSessionVariables(variables);
}
@Override
- public String getSessionVariable(String varname) throws SQLException {
+ public String getSessionVariable(String varname) throws NoSuchSessionVariableException {
return conn.getSessionVariable(varname);
}
@Override
- public Boolean existSessionVariable(String varname) throws SQLException {
+ public Boolean existSessionVariable(String varname) {
return conn.existSessionVariable(varname);
}
@Override
- public Map<String, String> getAllSessionVariables() throws SQLException {
+ public Map<String, String> getAllSessionVariables() {
return conn.getAllSessionVariables();
}
@Override
- public ClientProtos.SubmitQueryResponse executeQuery(final String sql) throws SQLException {
+ public ClientProtos.SubmitQueryResponse executeQuery(final String sql) {
final BlockingInterface stub = conn.getTMStub();
final QueryRequest request = buildQueryRequest(sql, false);
@@ -165,7 +169,7 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException {
+ public ClientProtos.SubmitQueryResponse executeQueryWithJson(final String json) {
final BlockingInterface stub = conn.getTMStub();
final QueryRequest request = buildQueryRequest(json, true);
@@ -177,10 +181,10 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public ResultSet executeQueryAndGetResult(String sql) throws SQLException {
+ public ResultSet executeQueryAndGetResult(String sql) throws TajoException {
ClientProtos.SubmitQueryResponse response = executeQuery(sql);
- throwIfError(response.getState());
+ ensureOk(response.getState());
QueryId queryId = new QueryId(response.getQueryId());
@@ -195,10 +199,10 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException {
+ public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException {
ClientProtos.SubmitQueryResponse response = executeQueryWithJson(json);
- throwIfError(response.getState());
+ ensureOk(response.getState());
QueryId queryId = new QueryId(response.getQueryId());
@@ -212,7 +216,7 @@ public class QueryClientImpl implements QueryClient {
}
}
- private ResultSet getQueryResultAndWait(QueryId queryId) throws SQLException {
+ public ResultSet getQueryResultAndWait(QueryId queryId) {
if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
return createNullResultSet(queryId);
@@ -235,8 +239,27 @@ public class QueryClientImpl implements QueryClient {
}
}
+ public GetQueryStatusResponse getRawQueryStatus(QueryId queryId) {
+
+ final BlockingInterface stub = conn.getTMStub();
+ final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder()
+ .setSessionId(conn.sessionId)
+ .setQueryId(queryId.getProto())
+ .build();
+
+ GetQueryStatusResponse res;
+ try {
+ res = stub.getQueryStatus(null, request);
+ } catch (ServiceException t) {
+ throw new RuntimeException(t);
+ }
+
+ ensureOk(res.getState());
+ return res;
+ }
+
@Override
- public QueryStatus getQueryStatus(QueryId queryId) throws SQLException {
+ public QueryStatus getQueryStatus(QueryId queryId) {
final BlockingInterface stub = conn.getTMStub();
final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder()
@@ -251,19 +274,19 @@ public class QueryClientImpl implements QueryClient {
throw new RuntimeException(t);
}
- throwIfError(res.getState());
+ ensureOk(res.getState());
return new QueryStatus(res);
}
@Override
- public ResultSet getQueryResult(QueryId queryId) throws SQLException {
+ public ResultSet getQueryResult(QueryId queryId) {
if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
return createNullResultSet(queryId);
}
GetQueryResultResponse response = getResultResponse(queryId);
- throwIfError(response.getState());
+ ensureOk(response.getState());
TableDesc tableDesc = CatalogUtil.newTableDesc(response.getTableDesc());
return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows);
}
@@ -274,7 +297,7 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException {
+ public GetQueryResultResponse getResultResponse(QueryId queryId) {
if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
return null;
}
@@ -292,7 +315,7 @@ public class QueryClientImpl implements QueryClient {
throw new RuntimeException(t);
}
- throwIfError(response.getState());
+ ensureOk(response.getState());
return response;
}
@@ -324,7 +347,7 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public boolean updateQuery(final String sql) throws SQLException {
+ public boolean updateQuery(final String sql) throws TajoException {
final BlockingInterface stub = conn.getTMStub();
final QueryRequest request = buildQueryRequest(sql, false);
@@ -336,14 +359,14 @@ public class QueryClientImpl implements QueryClient {
throw new RuntimeException(e);
}
- throwIfError(response.getState());
+ ClientExceptionUtil.throwIfError(response.getState());
conn.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
return true;
}
@Override
- public boolean updateQueryWithJson(final String json) throws SQLException {
+ public boolean updateQueryWithJson(final String json) throws TajoException {
final BlockingInterface stub = conn.getTMStub();
final QueryRequest request = buildQueryRequest(json, true);
@@ -355,7 +378,7 @@ public class QueryClientImpl implements QueryClient {
throw new RuntimeException(e);
}
- throwIfError(response.getState());
+ ClientExceptionUtil.throwIfError(response.getState());
return true;
}
@@ -376,7 +399,7 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public List<ClientProtos.BriefQueryInfo> getFinishedQueryList() throws SQLException {
+ public List<ClientProtos.BriefQueryInfo> getFinishedQueryList() {
final BlockingInterface stub = conn.getTMStub();
@@ -387,7 +410,7 @@ public class QueryClientImpl implements QueryClient {
throw new RuntimeException(e);
}
- throwIfError(res.getState());
+ ensureOk(res.getState());
return res.getQueryListList();
}
@@ -411,7 +434,7 @@ public class QueryClientImpl implements QueryClient {
}
@Override
- public QueryStatus killQuery(final QueryId queryId) throws SQLException {
+ public QueryStatus killQuery(final QueryId queryId) {
final BlockingInterface stub = conn.getTMStub();
QueryStatus status = getQueryStatus(queryId);
[3/4] tajo git commit: TAJO-1699: Tajo Java Client version 2.
Posted by hy...@apache.org.
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
index 4900188..a97cb33 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
@@ -26,6 +26,9 @@ import org.apache.tajo.TajoIdProtos;
import org.apache.tajo.annotation.NotNull;
import org.apache.tajo.annotation.Nullable;
import org.apache.tajo.auth.UserRoleInfo;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.client.v2.exception.ClientConnectionException;
+import org.apache.tajo.exception.NoSuchSessionVariableException;
import org.apache.tajo.exception.SQLExceptionUtil;
import org.apache.tajo.ipc.ClientProtos;
import org.apache.tajo.ipc.ClientProtos.SessionUpdateResponse;
@@ -36,7 +39,6 @@ import org.apache.tajo.rpc.NettyClientBase;
import org.apache.tajo.rpc.RpcChannelFactory;
import org.apache.tajo.rpc.RpcClientManager;
import org.apache.tajo.rpc.RpcConstants;
-import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueSetResponse;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringResponse;
@@ -57,14 +59,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.tajo.error.Errors.ResultCode.NO_SUCH_SESSION_VARIABLE;
-import static org.apache.tajo.exception.ReturnStateUtil.isError;
-import static org.apache.tajo.exception.ReturnStateUtil.isSuccess;
-import static org.apache.tajo.exception.ReturnStateUtil.isThisError;
-import static org.apache.tajo.exception.SQLExceptionUtil.toSQLException;
+import static org.apache.tajo.error.Errors.ResultCode.UNDEFINED_DATABASE;
+import static org.apache.tajo.exception.ReturnStateUtil.*;
import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError;
+import static org.apache.tajo.exception.SQLExceptionUtil.toSQLException;
import static org.apache.tajo.ipc.ClientProtos.CreateSessionRequest;
import static org.apache.tajo.ipc.ClientProtos.CreateSessionResponse;
-import static org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService;
public class SessionConnection implements Closeable {
@@ -101,7 +101,7 @@ public class SessionConnection implements Closeable {
* @throws SQLException
*/
public SessionConnection(@NotNull ServiceTracker tracker, @Nullable String baseDatabase,
- @NotNull KeyValueSet properties) throws SQLException {
+ @NotNull KeyValueSet properties) {
this.serviceTracker = tracker;
this.baseDatabase = baseDatabase;
this.properties = properties;
@@ -117,7 +117,7 @@ public class SessionConnection implements Closeable {
return Collections.unmodifiableMap(sessionVarsCache);
}
- public synchronized NettyClientBase getTajoMasterConnection() throws SQLException {
+ public synchronized NettyClientBase getTajoMasterConnection() {
if (client != null && client.isConnected()) {
return client;
@@ -138,14 +138,14 @@ public class SessionConnection implements Closeable {
connections.incrementAndGet();
} catch (Throwable t) {
- throw SQLExceptionUtil.makeUnableToEstablishConnection(t);
+ throw new ClientConnectionException(t);
}
return client;
}
}
- protected BlockingInterface getTMStub() throws SQLException {
+ protected BlockingInterface getTMStub() {
NettyClientBase tmClient;
tmClient = getTajoMasterConnection();
BlockingInterface stub = tmClient.getStub();
@@ -185,7 +185,7 @@ public class SessionConnection implements Closeable {
return userInfo;
}
- public String getCurrentDatabase() throws SQLException {
+ public String getCurrentDatabase() {
NettyClientBase client = getTajoMasterConnection();
checkSessionAndGet(client);
@@ -198,11 +198,11 @@ public class SessionConnection implements Closeable {
throw new RuntimeException(e);
}
- throwIfError(response.getState());
+ ensureOk(response.getState());
return response.getValue();
}
- public Map<String, String> updateSessionVariables(final Map<String, String> variables) throws SQLException {
+ public Map<String, String> updateSessionVariables(final Map<String, String> variables) {
NettyClientBase client = getTajoMasterConnection();
checkSessionAndGet(client);
@@ -221,15 +221,12 @@ public class SessionConnection implements Closeable {
throw new RuntimeException(e);
}
- if (isSuccess(response.getState())) {
- updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
- return Collections.unmodifiableMap(sessionVarsCache);
- } else {
- throw toSQLException(response.getState());
- }
+ ensureOk(response.getState());
+ updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
+ return Collections.unmodifiableMap(sessionVarsCache);
}
- public Map<String, String> unsetSessionVariables(final List<String> variables) throws SQLException {
+ public Map<String, String> unsetSessionVariables(final List<String> variables) throws NoSuchSessionVariableException {
final BlockingInterface stub = getTMStub();
final UpdateSessionVariableRequest request = UpdateSessionVariableRequest.newBuilder()
@@ -244,12 +241,13 @@ public class SessionConnection implements Closeable {
throw new RuntimeException(e);
}
- if (isSuccess(response.getState())) {
- updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
- return Collections.unmodifiableMap(sessionVarsCache);
- } else {
- throw toSQLException(response.getState());
+ if (isThisError(response.getState(), NO_SUCH_SESSION_VARIABLE)) {
+ throw new NoSuchSessionVariableException(response.getState());
}
+
+ ensureOk(response.getState());
+ updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
+ return Collections.unmodifiableMap(sessionVarsCache);
}
void updateSessionVarsCache(Map<String, String> variables) {
@@ -259,7 +257,7 @@ public class SessionConnection implements Closeable {
}
}
- public String getSessionVariable(final String varname) throws SQLException {
+ public String getSessionVariable(final String varname) throws NoSuchSessionVariableException {
synchronized (sessionVarsCache) {
// If a desired variable is client side one and exists in the cache, immediately return the variable.
if (sessionVarsCache.containsKey(varname)) {
@@ -271,35 +269,41 @@ public class SessionConnection implements Closeable {
checkSessionAndGet(client);
BlockingInterface stub = client.getStub();
-
+ StringResponse response;
try {
- return stub.getSessionVariable(null, getSessionedString(varname)).getValue();
+ response = stub.getSessionVariable(null, getSessionedString(varname));
} catch (ServiceException e) {
throw new RuntimeException(e);
}
+
+ if (isThisError(response.getState(), NO_SUCH_SESSION_VARIABLE)) {
+ throw new NoSuchSessionVariableException(response.getState());
+ }
+
+ ensureOk(response.getState());
+ return response.getValue();
}
- public Boolean existSessionVariable(final String varname) throws SQLException {
+ public Boolean existSessionVariable(final String varname) {
+ ReturnState state;
try {
final BlockingInterface stub = getTMStub();
- ReturnState state = stub.existSessionVariable(null, getSessionedString(varname));
-
- if (isThisError(state, NO_SUCH_SESSION_VARIABLE)) {
- return false;
- } else if (isError(state)){
- throw SQLExceptionUtil.toSQLException(state);
- }
-
- return isSuccess(state);
-
+ state = stub.existSessionVariable(null, getSessionedString(varname));
} catch (ServiceException e) {
throw new RuntimeException(e);
}
+
+ if (isThisError(state, NO_SUCH_SESSION_VARIABLE)) {
+ return false;
+ }
+
+ ensureOk(state);
+ return true;
}
- public Map<String, String> getAllSessionVariables() throws SQLException {
+ public Map<String, String> getAllSessionVariables() {
NettyClientBase client = getTajoMasterConnection();
checkSessionAndGet(client);
@@ -311,22 +315,29 @@ public class SessionConnection implements Closeable {
throw new RuntimeException(e);
}
- throwIfError(response.getState());
+ ensureOk(response.getState());
return ProtoUtil.convertToMap(response.getValue());
}
- public Boolean selectDatabase(final String databaseName) throws SQLException {
+ public Boolean selectDatabase(final String dbName) throws UndefinedDatabaseException {
BlockingInterface stub = getTMStub();
boolean selected;
try {
- selected = isSuccess(stub.selectDatabase(null, getSessionedString(databaseName)));
+ ReturnState state = stub.selectDatabase(null, getSessionedString(dbName));
+
+ if (isThisError(state, UNDEFINED_DATABASE)) {
+ throw new UndefinedDatabaseException(dbName);
+ }
+
+ selected = ensureOk(state);
+
} catch (ServiceException e) {
throw new RuntimeException(e);
}
if (selected) {
- this.baseDatabase = databaseName;
+ this.baseDatabase = dbName;
}
return selected;
}
@@ -362,7 +373,7 @@ public class SessionConnection implements Closeable {
return serviceTracker.getClientServiceAddress();
}
- protected void checkSessionAndGet(NettyClientBase client) throws SQLException {
+ protected void checkSessionAndGet(NettyClientBase client) {
if (sessionId == null) {
@@ -390,7 +401,7 @@ public class SessionConnection implements Closeable {
LOG.debug(String.format("Got session %s as a user '%s'.", sessionId.getId(), userInfo.getUserName()));
}
} else {
- throw SQLExceptionUtil.toSQLException(response.getState());
+ throw new InvalidClientSessionException(sessionId.getId());
}
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 b66d451..8c167a4 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
@@ -26,8 +26,10 @@ import org.apache.tajo.annotation.ThreadSafe;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.catalog.TableMeta;
+import org.apache.tajo.catalog.exception.*;
import org.apache.tajo.catalog.partition.PartitionMethodDesc;
import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
import org.apache.tajo.ipc.ClientProtos.*;
import org.apache.tajo.jdbc.TajoMemoryResultSet;
@@ -90,7 +92,7 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que
// QueryClient wrappers
/*------------------------------------------------------------------------*/
- public void closeQuery(final QueryId queryId) throws SQLException {
+ public void closeQuery(final QueryId queryId) {
queryClient.closeQuery(queryId);
}
@@ -98,23 +100,23 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que
queryClient.closeNonForwardQuery(queryId);
}
- public SubmitQueryResponse executeQuery(final String sql) throws SQLException {
+ public SubmitQueryResponse executeQuery(final String sql) {
return queryClient.executeQuery(sql);
}
- public SubmitQueryResponse executeQueryWithJson(final String json) throws SQLException {
+ public SubmitQueryResponse executeQueryWithJson(final String json) {
return queryClient.executeQueryWithJson(json);
}
- public ResultSet executeQueryAndGetResult(final String sql) throws SQLException {
+ public ResultSet executeQueryAndGetResult(final String sql) throws TajoException {
return queryClient.executeQueryAndGetResult(sql);
}
- public ResultSet executeJsonQueryAndGetResult(final String json) throws SQLException {
+ public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException {
return queryClient.executeJsonQueryAndGetResult(json);
}
- public QueryStatus getQueryStatus(QueryId queryId) throws SQLException {
+ public QueryStatus getQueryStatus(QueryId queryId) {
return queryClient.getQueryStatus(queryId);
}
@@ -134,15 +136,15 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que
return queryClient.fetchNextQueryResult(queryId, fetchRowNum);
}
- public boolean updateQuery(final String sql) throws SQLException {
+ public boolean updateQuery(final String sql) throws TajoException {
return queryClient.updateQuery(sql);
}
- public boolean updateQueryWithJson(final String json) throws SQLException {
+ public boolean updateQueryWithJson(final String json) throws TajoException {
return queryClient.updateQueryWithJson(json);
}
- public QueryStatus killQuery(final QueryId queryId) throws SQLException {
+ public QueryStatus killQuery(final QueryId queryId) {
return queryClient.killQuery(queryId);
}
@@ -150,7 +152,7 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que
return queryClient.getRunningQueryList();
}
- public List<BriefQueryInfo> getFinishedQueryList() throws SQLException {
+ public List<BriefQueryInfo> getFinishedQueryList() {
return queryClient.getFinishedQueryList();
}
@@ -178,54 +180,54 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que
// CatalogClient wrappers
/*------------------------------------------------------------------------*/
- public boolean createDatabase(final String databaseName) throws SQLException {
+ public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException {
return catalogClient.createDatabase(databaseName);
}
- public boolean existDatabase(final String databaseName) throws SQLException {
+ public boolean existDatabase(final String databaseName) {
return catalogClient.existDatabase(databaseName);
}
- public boolean dropDatabase(final String databaseName) throws SQLException {
+ public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException {
return catalogClient.dropDatabase(databaseName);
}
- public List<String> getAllDatabaseNames() throws SQLException {
+ public List<String> getAllDatabaseNames() {
return catalogClient.getAllDatabaseNames();
}
- public boolean existTable(final String tableName) throws SQLException {
+ public boolean existTable(final String tableName) {
return catalogClient.existTable(tableName);
}
public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
- final TableMeta meta) throws SQLException {
+ final TableMeta meta) throws DuplicateTableException {
return catalogClient.createExternalTable(tableName, schema, path, meta);
}
public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path,
final TableMeta meta, final PartitionMethodDesc partitionMethodDesc)
- throws SQLException {
+ throws DuplicateTableException {
return catalogClient.createExternalTable(tableName, schema, path, meta, partitionMethodDesc);
}
- public boolean dropTable(final String tableName) throws SQLException {
+ public boolean dropTable(final String tableName) throws UndefinedTableException {
return dropTable(tableName, false);
}
- public boolean dropTable(final String tableName, final boolean purge) throws SQLException {
+ public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException {
return catalogClient.dropTable(tableName, purge);
}
- public List<String> getTableList(@Nullable final String databaseName) throws SQLException {
+ public List<String> getTableList(@Nullable final String databaseName) {
return catalogClient.getTableList(databaseName);
}
- public TableDesc getTableDesc(final String tableName) throws SQLException {
+ public TableDesc getTableDesc(final String tableName) throws UndefinedTableException {
return catalogClient.getTableDesc(tableName);
}
- public List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName) throws SQLException {
+ public List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName) {
return catalogClient.getFunctions(functionName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
index 358f1a0..c79b756 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
@@ -58,7 +58,7 @@ public class TajoClientUtil {
return !isQueryWaitingForSchedule(state) && !isQueryRunning(state);
}
- public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) throws SQLException {
+ public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) {
QueryStatus status = client.getQueryStatus(queryId);
while(!isQueryComplete(status.getState())) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java
new file mode 100644
index 0000000..8dce7c4
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegate.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.exception.TajoException;
+
+import java.io.Closeable;
+import java.sql.ResultSet;
+
+/**
+ * ClientDelegate is a delegate for various wired protocols like protocol buffer, rest API, and proxy.
+ */
+public interface ClientDelegate extends Closeable {
+
+ int executeUpdate(String sql) throws TajoException;
+
+ ResultSet executeSQL(String sql) throws TajoException;
+
+ QueryFuture executeSQLAsync(String sql) throws TajoException;
+
+ String currentDB();
+
+ void selectDB(String db) throws UndefinedDatabaseException;
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java
new file mode 100644
index 0000000..44721b3
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientDelegateFactory.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import org.apache.tajo.annotation.Nullable;
+import org.apache.tajo.client.v2.exception.ClientUnableToConnectException;
+
+import java.util.Map;
+
+public class ClientDelegateFactory {
+
+ public static ClientDelegate newDefaultDelegate(String host,
+ int port,
+ @Nullable Map<String, String> props)
+ throws ClientUnableToConnectException {
+
+ return new LegacyClientDelegate(host, port, props);
+ }
+
+ public static ClientDelegate newDefaultDelegate(ServiceDiscovery discovery,
+ @Nullable Map<String, String> props)
+ throws ClientUnableToConnectException {
+
+ return new LegacyClientDelegate(discovery, props);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java
new file mode 100644
index 0000000..b6a00e2
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ClientUtil.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+public class ClientUtil {
+
+ public static boolean isOk(QueryState state) {
+ return !(state == QueryState.ERROR || state == QueryState.FAILED);
+ }
+
+ public static boolean isFailed(QueryState state) {
+ return state == QueryState.ERROR || state == QueryState.FAILED;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java
new file mode 100644
index 0000000..ac6283e
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/FutureListener.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import java.util.EventListener;
+
+public interface FutureListener<V> extends EventListener {
+ void processingCompleted(V future);
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java
new file mode 100644
index 0000000..a17311b
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/LegacyClientDelegate.java
@@ -0,0 +1,485 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.AbstractFuture;
+import org.apache.tajo.QueryId;
+import org.apache.tajo.TajoProtos;
+import org.apache.tajo.annotation.ThreadSafe;
+import org.apache.tajo.auth.UserRoleInfo;
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.client.*;
+import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.exception.TajoException;
+import org.apache.tajo.exception.UnimplementedException;
+import org.apache.tajo.ipc.ClientProtos;
+import org.apache.tajo.ipc.ClientProtos.GetQueryStatusResponse;
+import org.apache.tajo.service.ServiceTracker;
+import org.apache.tajo.service.ServiceTrackerException;
+import org.apache.tajo.service.TajoMasterInfo;
+import org.apache.tajo.util.KeyValueSet;
+import org.apache.tajo.util.NetUtils;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.sql.ResultSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.tajo.exception.ReturnStateUtil.ensureOk;
+
+@ThreadSafe
+public class LegacyClientDelegate extends SessionConnection implements ClientDelegate {
+
+ private QueryClientImpl queryClient;
+ private final ExecutorService executor = Executors.newFixedThreadPool(8);
+
+ public LegacyClientDelegate(String host, int port, Map<String, String> props) {
+ super(new DummyServiceTracker(NetUtils.createSocketAddr(host, port)), null, new KeyValueSet(props));
+ queryClient = new QueryClientImpl(this);
+ }
+
+ public LegacyClientDelegate(ServiceDiscovery discovery, Map<String, String> props) {
+ super(new DelegateServiceTracker(discovery), null, new KeyValueSet(props));
+ queryClient = new QueryClientImpl(this);
+ }
+
+ @Override
+ public int executeUpdate(String sql) throws TajoException {
+ queryClient.updateQuery(sql);
+ return 0;
+ }
+
+ @Override
+ public ResultSet executeSQL(String sql) throws TajoException {
+ try {
+ return executeSQLAsync(sql).get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public QueryFuture executeSQLAsync(String sql) throws TajoException {
+ ClientProtos.SubmitQueryResponse response = queryClient.executeQuery(sql);
+ ClientExceptionUtil.throwIfError(response.getState());
+
+ QueryId queryId = new QueryId(response.getQueryId());
+
+ switch (response.getResultType()) {
+ case ENCLOSED:
+ return new QueryFutureForEnclosed(queryId, TajoClientUtil.createResultSet(this.queryClient, response, 200));
+ case FETCH:
+ AsyncQueryFuture future = new AsyncQueryFuture(queryId);
+ executor.execute(future);
+ return future;
+ default:
+ return new QueryFutureForNoFetch(queryId);
+ }
+ }
+
+ @Override
+ public String currentDB() {
+ return getCurrentDatabase();
+ }
+
+ @Override
+ public void selectDB(String db) throws UndefinedDatabaseException {
+ selectDatabase(db);
+ }
+
+ private class QueryFutureForNoFetch implements QueryFuture {
+ protected final QueryId id;
+ private final long now = System.currentTimeMillis();
+
+ QueryFutureForNoFetch(QueryId id) {
+ this.id = id;
+ }
+
+ @Override
+ public String id() {
+ return id.toString();
+ }
+
+ @Override
+ public String queue() {
+ return "default";
+ }
+
+ @Override
+ public QueryState state() {
+ return QueryState.COMPLETED;
+ }
+
+ @Override
+ public float progress() {
+ return 1.0f;
+ }
+
+ @Override
+ public boolean isOk() {
+ return true;
+ }
+
+ @Override
+ public boolean isSuccessful() {
+ return true;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return false;
+ }
+
+ @Override
+ public boolean isKilled() {
+ return false;
+ }
+
+ @Override
+ public UserRoleInfo user() {
+ return UserRoleInfo.getCurrentUser();
+ }
+
+ @Override
+ public void kill() {
+ }
+
+ @Override
+ public long submitTime() {
+ return 0;
+ }
+
+ @Override
+ public long startTime() {
+ return now;
+ }
+
+ @Override
+ public long finishTime() {
+ return now;
+ }
+
+ @Override
+ public void release() {
+ queryClient.closeQuery(id);
+ }
+
+ @Override
+ public void addListener(FutureListener<QueryFuture> future) {
+ future.processingCompleted(this);
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public ResultSet get() {
+ return TajoClientUtil.NULL_RESULT_SET;
+ }
+
+ @Override
+ public ResultSet get(long timeout, TimeUnit unit) {
+ return TajoClientUtil.NULL_RESULT_SET;
+ }
+ }
+
+ private class QueryFutureForEnclosed extends QueryFutureForNoFetch {
+ private final ResultSet resultSet;
+ QueryFutureForEnclosed(QueryId id, ResultSet resultSet) {
+ super(id);
+ this.resultSet = resultSet;
+ }
+
+ @Override
+ public ResultSet get() {
+ return resultSet;
+ }
+
+ @Override
+ public ResultSet get(long timeout, TimeUnit unit) {
+ return resultSet;
+ }
+ }
+
+ private class AsyncQueryFuture extends AbstractFuture<ResultSet> implements QueryFuture, Runnable {
+ private final QueryId queryId;
+ private volatile QueryState lastState;
+ private volatile float progress;
+ private final long submitTime = System.currentTimeMillis();
+ private volatile long startTime = 0;
+ private volatile long finishTime = 0;
+
+ public AsyncQueryFuture(QueryId queryId) {
+ this.queryId = queryId;
+ this.lastState = QueryState.SCHEDULED;
+ }
+
+ @Override
+ public String id() {
+ return queryId.toString();
+ }
+
+ @Override
+ public boolean isOk() {
+ return ClientUtil.isOk(lastState);
+ }
+
+ @Override
+ public boolean isSuccessful() {
+ return lastState == QueryState.COMPLETED;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return ClientUtil.isFailed(lastState);
+ }
+
+ @Override
+ public boolean isKilled() {
+ return queryClient.getQueryStatus(queryId).getState() == TajoProtos.QueryState.QUERY_KILLED;
+ }
+
+ @Override
+ public QueryState state() {
+ return lastState;
+ }
+
+ @Override
+ public String queue() {
+ return "default";
+ }
+
+ @Override
+ public UserRoleInfo user() {
+ return UserRoleInfo.getCurrentUser();
+ }
+
+ @Override
+ public float progress() {
+ return progress;
+ }
+
+ @Override
+ public void kill() {
+ queryClient.killQuery(queryId).getState();
+ }
+
+ @Override
+ public long submitTime() {
+ return submitTime;
+ }
+
+ @Override
+ public long startTime() {
+ return startTime;
+ }
+
+ @Override
+ public long finishTime() {
+ return finishTime;
+ }
+
+ @Override
+ public void release() {
+ queryClient.closeQuery(queryId);
+ }
+
+ @Override
+ public void addListener(final FutureListener<QueryFuture> listener) {
+ final QueryFuture f = this;
+ addListener(new Runnable() {
+ @Override
+ public void run() {
+ listener.processingCompleted(f);
+ }},
+ executor);
+ }
+
+ private void updateState(GetQueryStatusResponse lastState) {
+ this.startTime = lastState.getSubmitTime();
+ this.finishTime = lastState.getFinishTime();
+ this.progress = lastState.getProgress();
+ this.lastState = convert(lastState.getQueryState());
+ }
+
+ GetQueryStatusResponse waitCompletion() {
+ GetQueryStatusResponse response = queryClient.getRawQueryStatus(queryId);
+ ensureOk(response.getState());
+ updateState(response);
+
+ while(!TajoClientUtil.isQueryComplete(response.getQueryState())) {
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ response = queryClient.getRawQueryStatus(queryId);
+ updateState(response);
+ ensureOk(response.getState());
+ }
+ return response;
+ }
+
+ @Override
+ public void run() {
+ GetQueryStatusResponse finalResponse;
+ try {
+ finalResponse = waitCompletion();
+ } catch (Throwable t) {
+ setException(t);
+ return;
+ }
+
+ if (finalResponse.getQueryState() == TajoProtos.QueryState.QUERY_SUCCEEDED) {
+ if (finalResponse.hasHasResult()) {
+ set(queryClient.getQueryResult(queryId));
+ } else { // when update
+ set(TajoClientUtil.NULL_RESULT_SET);
+ }
+ } else {
+ cancel(false); // failed
+ set(TajoClientUtil.NULL_RESULT_SET);
+ }
+ }
+ }
+
+ public static class DelegateServiceTracker implements ServiceTracker {
+
+ private final ServiceDiscovery discovery;
+ DelegateServiceTracker(ServiceDiscovery discovery) {
+ this.discovery = discovery;
+ }
+
+ @Override
+ public boolean isHighAvailable() {
+ return false;
+ }
+
+ @Override
+ public InetSocketAddress getUmbilicalAddress() throws ServiceTrackerException {
+ return null;
+ }
+
+ @Override
+ public InetSocketAddress getClientServiceAddress() throws ServiceTrackerException {
+ return discovery.clientAddress();
+ }
+
+ @Override
+ public InetSocketAddress getResourceTrackerAddress() throws ServiceTrackerException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public InetSocketAddress getCatalogAddress() throws ServiceTrackerException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public InetSocketAddress getMasterHttpInfo() throws ServiceTrackerException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public int getState(String masterName, TajoConf conf) throws ServiceTrackerException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public int formatHA(TajoConf conf) throws ServiceTrackerException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public List<String> getMasters(TajoConf conf) throws ServiceTrackerException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public void register() throws IOException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public void delete() throws IOException {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public boolean isActiveMaster() {
+ throw new UnimplementedException();
+ }
+
+ @Override
+ public List<TajoMasterInfo> getMasters() throws IOException {
+ throw new UnimplementedException();
+ }
+ }
+
+ public static QueryState convert(TajoProtos.QueryState state) {
+ switch (state) {
+ case QUERY_NEW:
+ case QUERY_INIT:
+ case QUERY_NOT_ASSIGNED:
+ return QueryState.SCHEDULED;
+
+ case QUERY_MASTER_INIT:
+ case QUERY_MASTER_LAUNCHED:
+ case QUERY_RUNNING:
+ return QueryState.RUNNING;
+
+ case QUERY_KILL_WAIT:
+ return QueryState.KILLING;
+
+ case QUERY_KILLED:
+ return QueryState.KILLED;
+
+ case QUERY_FAILED:
+ return QueryState.FAILED;
+
+ case QUERY_ERROR:
+ return QueryState.ERROR;
+
+ case QUERY_SUCCEEDED:
+ return QueryState.COMPLETED;
+
+ default:
+ throw new RuntimeException("Unknown state:" + state.name());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java
new file mode 100644
index 0000000..f1604cd
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryFuture.java
@@ -0,0 +1,133 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import org.apache.tajo.auth.UserRoleInfo;
+
+import java.sql.ResultSet;
+import java.util.concurrent.Future;
+
+/**
+ *
+ */
+public interface QueryFuture extends Future<ResultSet> {
+ /**
+ * Get a query id
+ *
+ * @return query id
+ */
+ String id();
+
+ /**
+ * Get the queue name that the query is running
+ *
+ * @return queue name
+ */
+ String queue();
+
+ /**
+ * Get a query state
+ *
+ * @return query state
+ */
+ QueryState state();
+
+ /**
+ * Get a normalized progress (0 ~ 1.0f) of a query running
+ *
+ * @return progress
+ */
+ float progress();
+
+ /**
+ * A submitted or running query state is normal
+ *
+ * @return True if a query state is normal
+ */
+ boolean isOk();
+
+ /**
+ * Get whether the query is successfully completed or not.
+ *
+ * @return True if the query is successfully completed.
+ */
+ boolean isSuccessful();
+
+ /**
+ * Get whether the query is abort due to error.
+ *
+ * @return True if the query is abort due to error.
+ */
+ boolean isFailed();
+
+ /**
+ * Get whether the query is killed. This is equivalent to
+ * @{link Future#cancel}.
+ *
+ * @return True if the query is already killed.
+ */
+ boolean isKilled();
+
+ /**
+ * Get an user information
+ *
+ * @return UserRoleInfo
+ */
+ UserRoleInfo user();
+
+ /**
+ * Kill this query
+ */
+ void kill();
+
+ /**
+ * Get the time when a query is submitted.
+ * This time can be different from @{link QueryFuture#startTime}
+ * due to scheduling delay.
+ *
+ * @return Millisecond since epoch
+ */
+ long submitTime();
+
+ /**
+ * Get the time when a query is actually launched.
+ *
+ * @return Millisecond since epoch
+ */
+ long startTime();
+
+ /**
+ * Get the time when a query is finished.
+ *
+ * @return Millisecond since epoch
+ */
+ long finishTime();
+
+ /**
+ * Release a query future. It will be automatically released after the session invalidation.
+ */
+ void release();
+
+ /**
+ * Add a listener which will be executed after this query is completed, error, failed or killed.
+ *
+ * @param future
+ */
+ void addListener(FutureListener<QueryFuture> future);
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java
new file mode 100644
index 0000000..24ea386
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/QueryState.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+public enum QueryState {
+ /** successfully submitted */
+ SCHEDULED,
+ /** Running */
+ RUNNING,
+ /** Error before a query execution */
+ ERROR,
+ /** Failure after a query launches */
+ FAILED,
+ /** Killed */
+ KILLED,
+ /** Wait for completely kill */
+ KILLING,
+ /** Successfully completed */
+ COMPLETED
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java
new file mode 100644
index 0000000..e69ca8a
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/ServiceDiscovery.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Client service discovery interface
+ */
+public interface ServiceDiscovery {
+ InetSocketAddress clientAddress();
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java
new file mode 100644
index 0000000..08a921d
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/TajoClient.java
@@ -0,0 +1,154 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2;
+
+import org.apache.tajo.catalog.exception.UndefinedDatabaseException;
+import org.apache.tajo.client.v2.exception.ClientUnableToConnectException;
+import org.apache.tajo.exception.TajoException;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.util.Map;
+
+public class TajoClient implements Closeable {
+ /**
+ * default client port number
+ */
+ public static final int DEFAULT_PORT = 26002;
+
+ private final ClientDelegate delegate;
+
+ /**
+ * Initialize TajoClient with a hostname and default port 26002.
+ *
+ * @param host hostname to connect
+ */
+ public TajoClient(String host) throws ClientUnableToConnectException {
+ delegate = ClientDelegateFactory.newDefaultDelegate(host, DEFAULT_PORT, null);
+ }
+
+ /**
+ * Initialize TajoClient with a hostname and default port 26002.
+ *
+ * @param host Hostname to connect
+ * @param properties Connection properties
+ */
+ public TajoClient(String host, Map<String, String> properties) throws ClientUnableToConnectException {
+ delegate = ClientDelegateFactory.newDefaultDelegate(host, DEFAULT_PORT, properties);
+ }
+
+ /**
+ * Initialize TajoClient with a hostname and port
+ *
+ * @param host Hostname to connect
+ * @param port Port number to connect
+ */
+ public TajoClient(String host, int port) throws ClientUnableToConnectException {
+ delegate = ClientDelegateFactory.newDefaultDelegate(host, port, null);
+ }
+
+ /**
+ * Initialize TajoClient with a hostname and port
+ *
+ * @param host Hostname to connect
+ * @param port Port number to connect
+ * @param properties Connection properties
+ */
+ public TajoClient(String host, int port, Map<String, String> properties) throws ClientUnableToConnectException {
+ delegate = ClientDelegateFactory.newDefaultDelegate(host, port, properties);
+ }
+
+ /**
+ * Initialize TajoClient via service discovery protocol
+ *
+ * @param discovery Service discovery
+ */
+ public TajoClient(ServiceDiscovery discovery) throws ClientUnableToConnectException {
+ delegate = ClientDelegateFactory.newDefaultDelegate(discovery, null);
+ }
+
+ /**
+ * Initialize TajoClient via service discovery protocol
+ *
+ * @param discovery Service discovery
+ * @param properties Connection properties
+ */
+ public TajoClient(ServiceDiscovery discovery, Map<String, String> properties) throws ClientUnableToConnectException {
+ delegate = ClientDelegateFactory.newDefaultDelegate(discovery, properties);
+ }
+
+ /**
+ * Submit and executes the given SQL statement, which may be an <code>INSERT (INTO)</code>,
+ * or <code>CREATE TABLE AS SELECT</code> statement or anSQL statement that returns nothing,
+ * such as an SQL DDL statement.
+ *
+ * @param sql a SQL statement
+ * @return inserted row number
+ * @throws TajoException
+ */
+ public int executeUpdate(String sql) throws TajoException {
+ return delegate.executeUpdate(sql);
+ }
+
+ /**
+ * Submit a SQL query statement
+ *
+ * @param sql a SQL statement
+ * @return QueryHandler
+ * @throws TajoException
+ */
+ public ResultSet executeQuery(String sql) throws TajoException {
+ return delegate.executeSQL(sql);
+ }
+
+ /**
+ * Execute a SQL statement through asynchronous API
+ *
+ * @param sql
+ * @return
+ * @throws TajoException
+ */
+ public QueryFuture executeQueryAsync(String sql) throws TajoException {
+ return delegate.executeSQLAsync(sql);
+ }
+
+ public void close() throws IOException {
+ delegate.close();
+ }
+
+ /**
+ * Select working database
+ *
+ * @param database Database name
+ * @throws UndefinedDatabaseException
+ */
+ public void selectDB(String database) throws UndefinedDatabaseException {
+ delegate.selectDB(database);
+ }
+
+ /**
+ * Get the current working database
+ *
+ * @return Current working database
+ */
+ public String currentDB() {
+ return delegate.currentDB();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java
new file mode 100644
index 0000000..a7fb08a
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientConnectionException.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2.exception;
+
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoRuntimeException;
+
+public class ClientConnectionException extends TajoRuntimeException {
+ public ClientConnectionException(Throwable t) {
+ super(Errors.ResultCode.CLIENT_CONNECTION_EXCEPTION, t.getMessage());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java
new file mode 100644
index 0000000..e567d7d
--- /dev/null
+++ b/tajo-client/src/main/java/org/apache/tajo/client/v2/exception/ClientUnableToConnectException.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.client.v2.exception;
+
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.exception.TajoException;
+
+public class ClientUnableToConnectException extends TajoException {
+ public ClientUnableToConnectException() {
+ super(Errors.ResultCode.CLIENT_UNABLE_TO_ESTABLISH_CONNECTION);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 869d7c4..8f15710 100644
--- a/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
+++ b/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
@@ -87,6 +87,6 @@ public class FetchResultSet extends TajoResultSetBase {
currentResultSet.close();
currentResultSet = null;
}
- tajoClient.closeNonForwardQuery(queryId);
+ tajoClient.closeQuery(queryId);
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java b/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java
index 7cf6e1e..574dc3b 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/AmbiguousColumnException.java
@@ -18,14 +18,17 @@
package org.apache.tajo.exception;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
import static org.apache.tajo.error.Errors.ResultCode.AMBIGUOUS_COLUMN;
public class AmbiguousColumnException extends TajoException {
private static final long serialVersionUID = 3102675985226352347L;
- /**
- * @param fieldName
- */
+ public AmbiguousColumnException(ReturnState state) {
+ super(state);
+ }
+
public AmbiguousColumnException(String fieldName) {
super(AMBIGUOUS_COLUMN, fieldName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
index d50164d..3b646e1 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
@@ -21,6 +21,7 @@ package org.apache.tajo.exception;
import com.google.common.collect.Maps;
import org.apache.tajo.error.Errors.ResultCode;
import org.apache.tajo.util.Pair;
+import org.apache.tajo.util.StringUtils;
import java.util.Map;
@@ -99,6 +100,9 @@ public class ErrorMessages {
ADD_MESSAGE(AMBIGUOUS_PARTITION_DIRECTORY, "There is a directory which is assumed to be a partitioned directory" +
" : '%s'", 1);
+
+ ADD_MESSAGE(CLIENT_CONNECTION_EXCEPTION, "Client connection to '%s' has error: %s", 2);
+ ADD_MESSAGE(CLIENT_UNABLE_TO_ESTABLISH_CONNECTION, "Client is unable to establish connection to '%s'", 1);
}
private static void ADD_MESSAGE(ResultCode code, String msgFormat) {
@@ -138,7 +142,7 @@ public class ErrorMessages {
}
} else {
- throw new TajoRuntimeException(code, args);
+ throw new TajoInternalError("Argument mismatch: code=" + code.name() + ", args=" + StringUtils.join(args));
}
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java b/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java
new file mode 100644
index 0000000..c9ed78d
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/NoSuchSessionVariableException.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.exception;
+
+import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
+
+public class NoSuchSessionVariableException extends TajoException {
+
+ public NoSuchSessionVariableException(PrimitiveProtos.ReturnState state) {
+ super(state);
+ }
+
+ public NoSuchSessionVariableException(String variableName) {
+ super(Errors.ResultCode.NO_SUCH_SESSION_VARIABLE, variableName);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java b/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java
index fb6b9a5..81554c4 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/ReturnStateUtil.java
@@ -45,10 +45,11 @@ public class ReturnStateUtil {
OK = builder.build();
}
- public static void ensureOk(ReturnState state) {
+ public static boolean ensureOk(ReturnState state) {
if (isError(state)) {
throw new TajoRuntimeException(state);
}
+ return true;
}
public static StringListResponse returnStringList(Collection<String> values) {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java b/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java
index 10b5aff..deeb7f9 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/SQLExceptionUtil.java
@@ -19,6 +19,7 @@
package org.apache.tajo.exception;
import com.google.common.collect.Maps;
+import org.apache.log4j.spi.ErrorCode;
import org.apache.tajo.error.Errors.ResultCode;
import org.apache.tajo.exception.ErrorMessages;
import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
@@ -54,27 +55,34 @@ public class SQLExceptionUtil {
}
}
- public static SQLException toSQLException(ReturnState state) throws SQLException {
-
- if (SQLSTATES.containsKey(state.getReturnCode())) {
+ private static SQLException toSQLException(ResultCode code, String message) throws SQLException {
+ if (SQLSTATES.containsKey(code)) {
return new SQLException(
- state.getMessage(),
- SQLSTATES.get(state.getReturnCode()),
- state.getReturnCode().getNumber()
+ message,
+ SQLSTATES.get(code),
+ code.getNumber()
);
} else {
// If there is no SQLState corresponding to error code,
// It will make SQLState '42000' (Syntax Error Or Access Rule Violation).
return new SQLException(
- state.getMessage(),
+ message,
"42000",
ResultCode.SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION_VALUE
);
}
}
+ public static SQLException toSQLException(TajoException e) throws SQLException {
+ return toSQLException(e.getErrorCode(), e.getMessage());
+ }
+
+ public static SQLException toSQLException(ReturnState state) throws SQLException {
+ return toSQLException(state.getReturnCode(), state.getMessage());
+ }
+
public static SQLException makeSQLException(ResultCode code, String ...args) {
if (SQLSTATES.containsKey(code)) {
return new SQLException(
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java
index dbb2748..765ead3 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoError.java
@@ -19,6 +19,8 @@
package org.apache.tajo.exception;
import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
/**
* Unrecoverable errors
@@ -26,6 +28,11 @@ import org.apache.tajo.error.Errors.ResultCode;
public class TajoError extends Error implements TajoExceptionInterface {
private ResultCode code;
+ public TajoError(ReturnState state) {
+ super(state.getMessage());
+ code = state.getReturnCode();
+ }
+
public TajoError(ResultCode code) {
super(ErrorMessages.getMessage(code));
this.code = code;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java
index 781d1a0..e0e2ccb 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoException.java
@@ -19,6 +19,7 @@
package org.apache.tajo.exception;
import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
/**
* TajoException contains all exceptions with any exact reason.
@@ -27,6 +28,16 @@ import org.apache.tajo.error.Errors.ResultCode;
public class TajoException extends Exception implements TajoExceptionInterface {
private ResultCode code;
+ public TajoException(ReturnState e) {
+ super(e.getMessage());
+ this.code = e.getReturnCode();
+ }
+
+ public TajoException(TajoRuntimeException e) {
+ super(e.getMessage());
+ this.code = e.getErrorCode();
+ }
+
public TajoException(ResultCode code) {
super(ErrorMessages.getMessage(code));
this.code = code;
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java b/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java
index 767c13c..072636b 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/TajoInternalError.java
@@ -19,12 +19,18 @@
package org.apache.tajo.exception;
import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
/**
* Exception for Internal Bugs and Unexpected exception
*/
public class TajoInternalError extends TajoError {
+ public TajoInternalError(ReturnState state) {
+ super(state);
+ }
+
public TajoInternalError(String message) {
super(ResultCode.INTERNAL_ERROR, message);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java
index 9d91946..70586c9 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UndefinedOperatorException.java
@@ -19,9 +19,14 @@
package org.apache.tajo.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UndefinedOperatorException extends TajoException {
+ public UndefinedOperatorException(ReturnState state) {
+ super(state);
+ }
+
public UndefinedOperatorException(String operation) {
super(Errors.ResultCode.UNDEFINED_OPERATOR, operation);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
index 9ca5539..a7a3915 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
@@ -19,10 +19,15 @@
package org.apache.tajo.exception;
import org.apache.tajo.error.Errors;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
public class UnsupportedException extends TajoRuntimeException {
private static final long serialVersionUID = 6702291354858193578L;
+ public UnsupportedException(ReturnState state) {
+ super(state);
+ }
+
public UnsupportedException(String featureName) {
super(Errors.ResultCode.FEATURE_NOT_SUPPORTED, featureName);
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/pom.xml
----------------------------------------------------------------------
diff --git a/tajo-core/pom.xml b/tajo-core/pom.xml
index 7489503..60e02a6 100644
--- a/tajo-core/pom.xml
+++ b/tajo-core/pom.xml
@@ -54,8 +54,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.7</source>
+ <target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java b/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java
index b4a28db..90c95a1 100644
--- a/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java
+++ b/tajo-core/src/main/java/org/apache/tajo/benchmark/BenchmarkSet.java
@@ -28,6 +28,7 @@ import org.apache.tajo.client.TajoClient;
import org.apache.tajo.client.TajoClientImpl;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.service.ServiceTracker;
import org.apache.tajo.service.ServiceTrackerFactory;
import org.apache.tajo.util.FileUtil;
@@ -91,7 +92,7 @@ public abstract class BenchmarkSet {
public abstract void loadQueries() throws IOException;
- public abstract void loadTables() throws SQLException;
+ public abstract void loadTables() throws TajoException;
public String [] getTableNames() {
return schemas.keySet().toArray(new String[schemas.size()]);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java b/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java
index 91a3b66..9739767 100644
--- a/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java
+++ b/tajo-core/src/main/java/org/apache/tajo/benchmark/TPCH.java
@@ -32,6 +32,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.storage.StorageConstants;
import java.io.File;
@@ -192,7 +193,7 @@ public class TPCH extends BenchmarkSet {
loadQueries(BENCHMARK_DIR);
}
- public void loadTables() throws SQLException {
+ public void loadTables() throws TajoException {
loadTable(LINEITEM);
loadTable(CUSTOMER);
loadTable(CUSTOMER_PARTS);
@@ -206,7 +207,7 @@ public class TPCH extends BenchmarkSet {
}
- public void loadTable(String tableName) throws SQLException {
+ public void loadTable(String tableName) throws TajoException {
TableMeta meta = CatalogUtil.newTableMeta("TEXT");
meta.putOption(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
index 67f782a..07445a4 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
@@ -29,6 +29,9 @@ import org.apache.tajo.ExecutionBlockId;
import org.apache.tajo.SessionVars;
import org.apache.tajo.algebra.JoinType;
import org.apache.tajo.catalog.*;
+import org.apache.tajo.catalog.exception.AmbiguousFunctionException;
+import org.apache.tajo.catalog.exception.CatalogException;
+import org.apache.tajo.catalog.exception.UndefinedFunctionException;
import org.apache.tajo.catalog.partition.PartitionMethodDesc;
import org.apache.tajo.catalog.proto.CatalogProtos;
import org.apache.tajo.common.TajoDataTypes;
@@ -37,10 +40,7 @@ import org.apache.tajo.engine.planner.global.builder.DistinctGroupbyBuilder;
import org.apache.tajo.engine.planner.global.rewriter.GlobalPlanRewriteEngine;
import org.apache.tajo.engine.planner.global.rewriter.GlobalPlanRewriteRuleProvider;
import org.apache.tajo.engine.query.QueryContext;
-import org.apache.tajo.exception.InternalException;
-import org.apache.tajo.exception.TajoException;
-import org.apache.tajo.exception.TajoInternalError;
-import org.apache.tajo.exception.UnimplementedException;
+import org.apache.tajo.exception.*;
import org.apache.tajo.plan.LogicalPlan;
import org.apache.tajo.plan.PlanningException;
import org.apache.tajo.plan.Target;
@@ -346,31 +346,32 @@ public class GlobalPlanner {
}
}
- private AggregationFunctionCallEval createSumFunction(EvalNode[] args) throws InternalException {
- FunctionDesc functionDesc = getCatalog().getFunction("sum", CatalogProtos.FunctionType.AGGREGATION,
+ private AggregationFunctionCallEval createSumFunction(EvalNode[] args) throws CatalogException {
+ FunctionDesc functionDesc = null;
+ functionDesc = getCatalog().getFunction("sum", CatalogProtos.FunctionType.AGGREGATION,
args[0].getValueType());
return new AggregationFunctionCallEval(functionDesc, args);
}
- private AggregationFunctionCallEval createCountFunction(EvalNode [] args) throws InternalException {
+ private AggregationFunctionCallEval createCountFunction(EvalNode [] args) throws CatalogException {
FunctionDesc functionDesc = getCatalog().getFunction("count", CatalogProtos.FunctionType.AGGREGATION,
args[0].getValueType());
return new AggregationFunctionCallEval(functionDesc, args);
}
- private AggregationFunctionCallEval createCountRowFunction(EvalNode[] args) throws InternalException {
+ private AggregationFunctionCallEval createCountRowFunction(EvalNode[] args) throws CatalogException {
FunctionDesc functionDesc = getCatalog().getFunction("count", CatalogProtos.FunctionType.AGGREGATION,
new TajoDataTypes.DataType[]{});
return new AggregationFunctionCallEval(functionDesc, args);
}
- private AggregationFunctionCallEval createMaxFunction(EvalNode [] args) throws InternalException {
+ private AggregationFunctionCallEval createMaxFunction(EvalNode [] args) throws CatalogException {
FunctionDesc functionDesc = getCatalog().getFunction("max", CatalogProtos.FunctionType.AGGREGATION,
args[0].getValueType());
return new AggregationFunctionCallEval(functionDesc, args);
}
- private AggregationFunctionCallEval createMinFunction(EvalNode [] args) throws InternalException {
+ private AggregationFunctionCallEval createMinFunction(EvalNode [] args) throws CatalogException {
FunctionDesc functionDesc = getCatalog().getFunction("min", CatalogProtos.FunctionType.AGGREGATION,
args[0].getValueType());
return new AggregationFunctionCallEval(functionDesc, args);
@@ -428,57 +429,53 @@ public class GlobalPlanner {
*/
private RewrittenFunctions rewriteAggFunctionsForDistinctAggregation(GlobalPlanContext context,
AggregationFunctionCallEval function)
- throws PlanningException {
+ throws TajoException {
LogicalPlan plan = context.plan.getLogicalPlan();
RewrittenFunctions rewritten = null;
- try {
- if (function.getName().equalsIgnoreCase("count")) {
- rewritten = new RewrittenFunctions(1);
-
- if (function.getArgs().length == 0) {
- rewritten.firstStageEvals[0] = createCountRowFunction(function.getArgs());
- } else {
- rewritten.firstStageEvals[0] = createCountFunction(function.getArgs());
- }
- String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
- FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
- rewritten.firstStageTargets[0] = new Target(fieldEval);
- rewritten.secondStageEvals = createSumFunction(new EvalNode[] {fieldEval});
- } else if (function.getName().equalsIgnoreCase("sum")) {
- rewritten = new RewrittenFunctions(1);
-
- rewritten.firstStageEvals[0] = createSumFunction(function.getArgs());
- String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
- FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
- rewritten.firstStageTargets[0] = new Target(fieldEval);
- rewritten.secondStageEvals = createSumFunction(new EvalNode[] {fieldEval});
-
- } else if (function.getName().equals("max")) {
- rewritten = new RewrittenFunctions(1);
-
- rewritten.firstStageEvals[0] = createMaxFunction(function.getArgs());
- String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
- FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
- rewritten.firstStageTargets[0] = new Target(fieldEval);
- rewritten.secondStageEvals = createMaxFunction(new EvalNode[]{fieldEval});
-
- } else if (function.getName().equals("min")) {
-
- rewritten = new RewrittenFunctions(1);
-
- rewritten.firstStageEvals[0] = createMinFunction(function.getArgs());
- String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
- FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
- rewritten.firstStageTargets[0] = new Target(fieldEval);
- rewritten.secondStageEvals = createMinFunction(new EvalNode[]{fieldEval});
+ if (function.getName().equalsIgnoreCase("count")) {
+ rewritten = new RewrittenFunctions(1);
+ if (function.getArgs().length == 0) {
+ rewritten.firstStageEvals[0] = createCountRowFunction(function.getArgs());
} else {
- throw new PlanningException("Cannot support a mix of other functions");
+ rewritten.firstStageEvals[0] = createCountFunction(function.getArgs());
}
- } catch (InternalException e) {
- LOG.error(e, e);
+ String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
+ FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
+ rewritten.firstStageTargets[0] = new Target(fieldEval);
+ rewritten.secondStageEvals = createSumFunction(new EvalNode[]{fieldEval});
+ } else if (function.getName().equalsIgnoreCase("sum")) {
+ rewritten = new RewrittenFunctions(1);
+
+ rewritten.firstStageEvals[0] = createSumFunction(function.getArgs());
+ String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
+ FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
+ rewritten.firstStageTargets[0] = new Target(fieldEval);
+ rewritten.secondStageEvals = createSumFunction(new EvalNode[]{fieldEval});
+
+ } else if (function.getName().equals("max")) {
+ rewritten = new RewrittenFunctions(1);
+
+ rewritten.firstStageEvals[0] = createMaxFunction(function.getArgs());
+ String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
+ FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
+ rewritten.firstStageTargets[0] = new Target(fieldEval);
+ rewritten.secondStageEvals = createMaxFunction(new EvalNode[]{fieldEval});
+
+ } else if (function.getName().equals("min")) {
+
+ rewritten = new RewrittenFunctions(1);
+
+ rewritten.firstStageEvals[0] = createMinFunction(function.getArgs());
+ String referenceName = plan.generateUniqueColumnName(rewritten.firstStageEvals[0]);
+ FieldEval fieldEval = new FieldEval(referenceName, rewritten.firstStageEvals[0].getValueType());
+ rewritten.firstStageTargets[0] = new Target(fieldEval);
+ rewritten.secondStageEvals = createMinFunction(new EvalNode[]{fieldEval});
+
+ } else {
+ throw new UnsupportedException("Cannot support a mix of other functions");
}
return rewritten;
@@ -523,7 +520,7 @@ public class GlobalPlanner {
*/
private ExecutionBlock buildGroupByIncludingDistinctFunctionsMultiStage(GlobalPlanContext context,
ExecutionBlock latestExecBlock,
- GroupbyNode groupbyNode) throws PlanningException {
+ GroupbyNode groupbyNode) throws TajoException {
Column [] originalGroupingColumns = groupbyNode.getGroupingColumns();
LinkedHashSet<Column> firstStageGroupingColumns =
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/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 b70a79f..d16f7d1 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/TajoMaster.java
@@ -38,6 +38,7 @@ import org.apache.tajo.catalog.CatalogServer;
import org.apache.tajo.catalog.CatalogService;
import org.apache.tajo.catalog.FunctionDesc;
import org.apache.tajo.catalog.LocalCatalogWrapper;
+import org.apache.tajo.catalog.exception.DuplicateDatabaseException;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.conf.TajoConf.ConfVars;
import org.apache.tajo.engine.function.FunctionLoader;
@@ -369,7 +370,7 @@ public class TajoMaster extends CompositeService {
}
}
- private void checkBaseTBSpaceAndDatabase() throws IOException {
+ private void checkBaseTBSpaceAndDatabase() throws IOException, DuplicateDatabaseException {
if (!catalog.existTablespace(DEFAULT_TABLESPACE_NAME)) {
catalog.createTablespace(DEFAULT_TABLESPACE_NAME, context.getConf().getVar(ConfVars.WAREHOUSE_DIR));
} else {
http://git-wip-us.apache.org/repos/asf/tajo/blob/4253f1b6/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java b/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
index 40ebf4e..a43b95e 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/exec/CreateTableExecutor.java
@@ -28,6 +28,7 @@ import org.apache.tajo.catalog.exception.DuplicateTableException;
import org.apache.tajo.catalog.exception.UndefinedTablespaceException;
import org.apache.tajo.catalog.partition.PartitionMethodDesc;
import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.exception.TajoException;
import org.apache.tajo.exception.TajoInternalError;
import org.apache.tajo.master.TajoMaster;
import org.apache.tajo.plan.logical.CreateTableNode;
@@ -52,7 +53,7 @@ public class CreateTableExecutor {
}
public TableDesc create(QueryContext queryContext, CreateTableNode createTable, boolean ifNotExists)
- throws IOException {
+ throws IOException, TajoException {
TableMeta meta;
if (createTable.hasOptions()) {
@@ -85,7 +86,7 @@ public class CreateTableExecutor {
@Nullable URI uri,
boolean isExternal,
@Nullable PartitionMethodDesc partitionDesc,
- boolean ifNotExists) throws IOException {
+ boolean ifNotExists) throws IOException, TajoException {
Pair<String, String> separatedNames = getQualifiedName(queryContext.getCurrentDatabase(), tableName);
String databaseName = separatedNames.getFirst();
@@ -119,7 +120,7 @@ public class CreateTableExecutor {
}
}
- private TableDesc handlExistence(boolean ifNotExists, String qualifiedName) {
+ private TableDesc handlExistence(boolean ifNotExists, String qualifiedName) throws DuplicateTableException {
if (ifNotExists) {
LOG.info("relation \"" + qualifiedName + "\" is already exists.");
return catalog.getTableDesc(qualifiedName);
@@ -131,13 +132,15 @@ public class CreateTableExecutor {
private Pair<String, String> getQualifiedName(String currentDatabase, String tableName) {
if (CatalogUtil.isFQTableName(tableName)) {
String [] splitted = CatalogUtil.splitFQTableName(tableName);
- return new Pair<String, String>(splitted[0], splitted[1]);
+ return new Pair<>(splitted[0], splitted[1]);
} else {
- return new Pair<String, String>(currentDatabase, tableName);
+ return new Pair<>(currentDatabase, tableName);
}
}
- private Tablespace getTablespaceHandler(@Nullable String tableSpaceName, @Nullable URI tableUri) {
+ private Tablespace getTablespaceHandler(@Nullable String tableSpaceName, @Nullable URI tableUri)
+ throws UndefinedTablespaceException {
+
if (tableSpaceName != null) {
Optional<Tablespace> ts = (Optional<Tablespace>) TablespaceManager.getByName(tableSpaceName);
if (ts.isPresent()) {