http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/OracleStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/OracleStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/OracleStore.java index 4b7e6a3..1911507 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/OracleStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/OracleStore.java @@ -18,19 +18,18 @@ package org.apache.tajo.catalog.store; +import org.apache.hadoop.conf.Configuration; +import org.apache.tajo.exception.TajoException; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; -import org.apache.hadoop.conf.Configuration; -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.exception.InternalException; - public class OracleStore extends AbstractDBStore { private static final String CATALOG_DRIVER = "oracle.jdbc.OracleDriver"; - public OracleStore(Configuration conf) throws InternalException { + public OracleStore(Configuration conf) { super(conf); } @@ -50,7 +49,7 @@ public class OracleStore extends AbstractDBStore { } @Override - protected void createDatabaseDependants() throws CatalogException { + protected void createDatabaseDependants() { }
http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/PostgreSQLStore.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/PostgreSQLStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/PostgreSQLStore.java index 6089fdd..df2ddde 100644 --- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/PostgreSQLStore.java +++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/PostgreSQLStore.java @@ -18,19 +18,17 @@ package org.apache.tajo.catalog.store; +import org.apache.hadoop.conf.Configuration; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; -import org.apache.hadoop.conf.Configuration; -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.exception.InternalException; - public class PostgreSQLStore extends AbstractDBStore { private static final String CATALOG_DRIVER = "org.postgresql.Driver"; - public PostgreSQLStore(Configuration conf) throws InternalException { + public PostgreSQLStore(Configuration conf) { super(conf); } @@ -50,7 +48,7 @@ public class PostgreSQLStore extends AbstractDBStore { } @Override - protected void createDatabaseDependants() throws CatalogException { + protected void createDatabaseDependants() { } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 9d767a0..c36426e 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 @@ -18,27 +18,14 @@ package org.apache.tajo.catalog.store; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tajo.catalog.CatalogConstants; +import org.apache.tajo.catalog.CatalogUtil; +import org.apache.tajo.catalog.store.object.*; +import org.apache.tajo.exception.TajoException; +import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.util.TUtil; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; @@ -48,15 +35,16 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tajo.catalog.CatalogConstants; -import org.apache.tajo.catalog.CatalogUtil; -import org.apache.tajo.catalog.exception.CatalogException; -import org.apache.tajo.catalog.store.object.*; -import org.apache.tajo.exception.TajoInternalError; -import org.apache.tajo.util.TUtil; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.sql.*; +import java.util.*; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; public class XMLCatalogSchemaManager { protected final Log LOG = LogFactory.getLog(getClass()); @@ -76,8 +64,7 @@ public class XMLCatalogSchemaManager { } } - protected String getDropSQL(DatabaseObjectType type, String name) - throws CatalogException { + protected String getDropSQL(DatabaseObjectType type, String name) { SQLObject foundDropQuery = null; String sqlStatement = "DROP " + type.toString() + " " + name; @@ -101,7 +88,7 @@ public class XMLCatalogSchemaManager { return sqlStatement; } - public void dropBaseSchema(Connection conn) throws CatalogException { + public void dropBaseSchema(Connection conn) { if (!isLoaded()) { throw new TajoInternalError("Schema files are not loaded yet."); } @@ -271,7 +258,7 @@ public class XMLCatalogSchemaManager { return result; } - public void createBaseSchema(Connection conn) throws CatalogException { + public void createBaseSchema(Connection conn) { Statement stmt; if (!isLoaded()) { @@ -347,7 +334,7 @@ public class XMLCatalogSchemaManager { CatalogUtil.closeQuietly(stmt); } - public boolean catalogAlreadyExists(Connection conn) throws CatalogException { + public boolean catalogAlreadyExists(Connection conn) { boolean result = false; try { List<String> constants = TUtil.newList(); @@ -375,7 +362,7 @@ public class XMLCatalogSchemaManager { return result; } - public boolean isInitialized(Connection conn) throws CatalogException { + public boolean isInitialized(Connection conn) { if (!isLoaded()) { throw new TajoInternalError("Database schema files are not loaded."); } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java index e2a096a..1d628f2 100644 --- a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java +++ b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java @@ -22,7 +22,6 @@ import com.google.common.collect.Sets; import org.apache.hadoop.fs.Path; import org.apache.tajo.TajoConstants; import org.apache.tajo.catalog.dictionary.InfoSchemaMetadataDictionary; -import org.apache.tajo.catalog.exception.UndefinedFunctionException; import org.apache.tajo.catalog.partition.PartitionDesc; import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos; @@ -33,7 +32,9 @@ import org.apache.tajo.catalog.store.*; import org.apache.tajo.common.TajoDataTypes; import org.apache.tajo.common.TajoDataTypes.Type; import org.apache.tajo.conf.TajoConf; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.exception.TajoInternalError; +import org.apache.tajo.exception.UndefinedFunctionException; import org.apache.tajo.function.Function; import org.apache.tajo.util.CommonTestingUtil; import org.apache.tajo.util.KeyValueSet; @@ -141,11 +142,11 @@ public class TestCatalog { ////////////////////////////////////////////////////////////////////////////// assertFalse(catalog.existTablespace("space1")); - assertTrue(catalog.createTablespace("space1", "hdfs://xxx.com/warehouse")); + catalog.createTablespace("space1", "hdfs://xxx.com/warehouse"); assertTrue(catalog.existTablespace("space1")); assertFalse(catalog.existTablespace("space2")); - assertTrue(catalog.createTablespace("space2", "hdfs://yyy.com/warehouse")); + catalog.createTablespace("space2", "hdfs://yyy.com/warehouse"); assertTrue(catalog.existTablespace("space2")); ////////////////////////////////////////////////////////////////////////////// @@ -199,32 +200,32 @@ public class TestCatalog { ////////////////////////////////////////////////////////////////////////////// // Clean up ////////////////////////////////////////////////////////////////////////////// - assertTrue(catalog.dropTablespace("space1")); + catalog.dropTablespace("space1"); assertFalse(catalog.existTablespace("space1")); - assertTrue(catalog.dropTablespace("space2")); + catalog.dropTablespace("space2"); assertFalse(catalog.existTablespace("space2")); } @Test public void testCreateAndDropDatabases() throws Exception { assertFalse(catalog.existDatabase("testCreateAndDropDatabases")); - assertTrue(catalog.createDatabase("testCreateAndDropDatabases", TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase("testCreateAndDropDatabases", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("testCreateAndDropDatabases")); - assertTrue(catalog.dropDatabase("testCreateAndDropDatabases")); + catalog.dropDatabase("testCreateAndDropDatabases"); } @Test public void testCreateAndDropDatabaseWithCharacterSensitivity() throws Exception { assertFalse(catalog.existDatabase("TestDatabase1")); assertFalse(catalog.existDatabase("testDatabase1")); - assertTrue(catalog.createDatabase("TestDatabase1", TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase("TestDatabase1", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("TestDatabase1")); assertFalse(catalog.existDatabase("testDatabase1")); - assertTrue(catalog.createDatabase("testDatabase1", TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase("testDatabase1", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("TestDatabase1")); assertTrue(catalog.existDatabase("testDatabase1")); - assertTrue(catalog.dropDatabase("TestDatabase1")); - assertTrue(catalog.dropDatabase("testDatabase1")); + catalog.dropDatabase("TestDatabase1"); + catalog.dropDatabase("testDatabase1"); } @Test @@ -236,7 +237,7 @@ public class TestCatalog { for (int i = 0; i < NUM; i++) { String databaseName = namePrefix + i; assertFalse(catalog.existDatabase(databaseName)); - assertTrue(catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase(databaseName)); createdDatabases.add(databaseName); } @@ -252,7 +253,7 @@ public class TestCatalog { Collections.shuffle(createdDatabases); for (String tobeDropped : createdDatabases) { assertTrue(catalog.existDatabase(tobeDropped)); - assertTrue(catalog.dropDatabase(tobeDropped)); + catalog.dropDatabase(tobeDropped); assertFalse(catalog.existDatabase(tobeDropped)); } } @@ -273,16 +274,16 @@ public class TestCatalog { @Test public void testCreateAndDropTable() throws Exception { - assertTrue(catalog.createDatabase("tmpdb1", TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase("tmpdb1", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("tmpdb1")); - assertTrue(catalog.createDatabase("tmpdb2", TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase("tmpdb2", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("tmpdb2")); TableDesc table1 = createMockupTable("tmpdb1", "table1"); - assertTrue(catalog.createTable(table1)); + catalog.createTable(table1); TableDesc table2 = createMockupTable("tmpdb2", "table2"); - assertTrue(catalog.createTable(table2)); + catalog.createTable(table2); Set<String> tmpdb1 = Sets.newHashSet(catalog.getAllTableNames("tmpdb1")); assertEquals(1, tmpdb1.size()); @@ -293,21 +294,21 @@ public class TestCatalog { assertEquals(1, tmpdb2.size()); assertTrue(tmpdb2.contains("table2")); - assertTrue(catalog.dropDatabase("tmpdb1")); + catalog.dropDatabase("tmpdb1"); assertFalse(catalog.existDatabase("tmpdb1")); tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2")); assertEquals(1, tmpdb2.size()); assertTrue(tmpdb2.contains("table2")); - assertTrue(catalog.dropDatabase("tmpdb2")); + catalog.dropDatabase("tmpdb2"); assertFalse(catalog.existDatabase("tmpdb2")); } @Test public void testCreateAndDropTableWithCharacterSensivity() throws Exception { String databaseName = "TestDatabase1"; - assertTrue(catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase(databaseName)); String tableName = "TestTable1"; @@ -322,7 +323,7 @@ public class TestCatalog { new TableMeta("TEXT", new KeyValueSet()), path.toUri(), true); - assertTrue(catalog.createTable(table)); + catalog.createTable(table); tableName = "testTable1"; schema = new Schema(); @@ -336,9 +337,9 @@ public class TestCatalog { new TableMeta("TEXT", new KeyValueSet()), path.toUri(), true); - assertTrue(catalog.createTable(table)); + catalog.createTable(table); - assertTrue(catalog.dropDatabase(databaseName)); + catalog.dropDatabase(databaseName); } static String dbPrefix = "db_"; @@ -347,7 +348,7 @@ public class TestCatalog { static final int TABLE_NUM_PER_DB = 3; static final int TOTAL_TABLE_NUM = DB_NUM * TABLE_NUM_PER_DB; - private Map<String, List<String>> createBaseDatabaseAndTables() throws IOException { + private Map<String, List<String>> createBaseDatabaseAndTables() throws IOException, TajoException { Map<String, List<String>> createdDatabaseAndTablesMap = new HashMap<String, List<String>>(); @@ -357,12 +358,12 @@ public class TestCatalog { String databaseName = dbPrefix + dbIdx; if (!catalog.existDatabase(databaseName)) { - assertTrue(catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME); } String tableName = tablePrefix + tableId; TableDesc table = createMockupTable(databaseName, tableName); - assertTrue(catalog.createTable(table)); + catalog.createTable(table); TUtil.putToNestedList(createdDatabaseAndTablesMap, databaseName, tableName); } @@ -438,7 +439,7 @@ public class TestCatalog { /** * It asserts the equality between an original table desc and a restored table desc. */ - private static void assertSchemaEquality(String tableName, Schema schema) throws IOException { + private static void assertSchemaEquality(String tableName, Schema schema) throws IOException, TajoException { Path path = new Path(CommonTestingUtil.getTestDir(), tableName); TableDesc tableDesc = new TableDesc( CatalogUtil.buildFQName(DEFAULT_DATABASE_NAME, tableName), @@ -577,30 +578,30 @@ public class TestCatalog { } @Test - public void testCreateSameTables() throws IOException { - assertTrue(catalog.createDatabase("tmpdb3", TajoConstants.DEFAULT_TABLESPACE_NAME)); + public void testCreateSameTables() throws IOException, TajoException { + catalog.createDatabase("tmpdb3", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("tmpdb3")); - assertTrue(catalog.createDatabase("tmpdb4", TajoConstants.DEFAULT_TABLESPACE_NAME)); + catalog.createDatabase("tmpdb4", TajoConstants.DEFAULT_TABLESPACE_NAME); assertTrue(catalog.existDatabase("tmpdb4")); TableDesc table1 = createMockupTable("tmpdb3", "table1"); - assertTrue(catalog.createTable(table1)); + catalog.createTable(table1); TableDesc table2 = createMockupTable("tmpdb3", "table2"); - assertTrue(catalog.createTable(table2)); + catalog.createTable(table2); assertTrue(catalog.existsTable("tmpdb3", "table1")); assertTrue(catalog.existsTable("tmpdb3", "table2")); TableDesc table3 = createMockupTable("tmpdb4", "table1"); - assertTrue(catalog.createTable(table3)); + catalog.createTable(table3); TableDesc table4 = createMockupTable("tmpdb4", "table2"); - assertTrue(catalog.createTable(table4)); + catalog.createTable(table4); assertTrue(catalog.existsTable("tmpdb4", "table1")); assertTrue(catalog.existsTable("tmpdb4", "table2")); - assertTrue(catalog.dropTable("tmpdb3.table1")); - assertTrue(catalog.dropTable("tmpdb3.table2")); - assertTrue(catalog.dropTable("tmpdb4.table1")); - assertTrue(catalog.dropTable("tmpdb4.table2")); + catalog.dropTable("tmpdb3.table1"); + catalog.dropTable("tmpdb3.table2"); + catalog.dropTable("tmpdb4.table1"); + catalog.dropTable("tmpdb4.table2"); assertFalse(catalog.existsTable("tmpdb3.table1")); assertFalse(catalog.existsTable("tmpdb3.table2")); @@ -612,7 +613,7 @@ public class TestCatalog { public void testAddAndDelIndex() throws Exception { TableDesc desc = prepareTable(); prepareIndexDescs(); - assertTrue(catalog.createTable(desc)); + catalog.createTable(desc); assertFalse(catalog.existIndexByName(DEFAULT_DATABASE_NAME, desc1.getName())); assertFalse(catalog.existIndexByColumnNames(DEFAULT_DATABASE_NAME, "indexed", new String[]{"id"})); @@ -1111,7 +1112,7 @@ public class TestCatalog { FunctionDesc meta = new FunctionDesc("testint", TestIntFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT4)); - assertTrue(catalog.createFunction(meta)); + catalog.createFunction(meta); // UPGRADE TO INT4 SUCCESS==> LOOK AT SECOND PARAM BELOW FunctionDesc retrieved = catalog.getFunction("testint", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT2)); @@ -1127,7 +1128,7 @@ public class TestCatalog { FunctionDesc meta = new FunctionDesc("testintinvalid", TestIntFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT4)); - assertTrue(catalog.createFunction(meta)); + catalog.createFunction(meta); //UPGRADE TO INT8 WILL FAIL ==> LOOK AT SECOND PARAM BELOW catalog.getFunction("testintinvalid", CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.INT8)); @@ -1139,7 +1140,7 @@ public class TestCatalog { FunctionDesc meta = new FunctionDesc("testfloat", TestFloatFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8, Type.INT4)); - assertTrue(catalog.createFunction(meta)); + catalog.createFunction(meta); //UPGRADE TO FLOAT 8 SUCCESS==> LOOK AT FIRST PARAM BELOW FunctionDesc retrieved = catalog.getFunction("testfloat", @@ -1156,7 +1157,7 @@ public class TestCatalog { FunctionDesc meta = new FunctionDesc("testfloatinvalid", TestFloatFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8, Type.INT4)); - assertTrue(catalog.createFunction(meta)); + catalog.createFunction(meta); // UPGRADE TO DECIMAL WILL FAIL ==> LOOK AT FIRST PARAM BELOW catalog.getFunction("testfloatinvalid", CatalogUtil.newSimpleDataTypeArray(Type.NUMERIC, Type.INT4)); @@ -1168,7 +1169,7 @@ public class TestCatalog { FunctionDesc meta = new FunctionDesc("testany", TestAnyParamFunc.class, FunctionType.GENERAL, CatalogUtil.newSimpleDataType(Type.INT4), CatalogUtil.newSimpleDataTypeArray(Type.ANY)); - assertTrue(catalog.createFunction(meta)); + catalog.createFunction(meta); FunctionDesc retrieved = catalog.getFunction("testany", CatalogUtil.newSimpleDataTypeArray(Type.INT1)); assertEquals(retrieved.getFunctionName(), "testany"); http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestLinkedMetadataManager.java ---------------------------------------------------------------------- diff --git a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestLinkedMetadataManager.java b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestLinkedMetadataManager.java index 4ddf7ab..d8f894e 100644 --- a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestLinkedMetadataManager.java +++ b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestLinkedMetadataManager.java @@ -24,12 +24,11 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.apache.hadoop.fs.Path; import org.apache.tajo.TajoConstants; -import org.apache.tajo.catalog.exception.UndefinedTablespaceException; +import org.apache.tajo.exception.*; import org.apache.tajo.catalog.proto.CatalogProtos; import org.apache.tajo.common.TajoDataTypes.Type; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.error.Errors; -import org.apache.tajo.exception.TajoInternalError; import org.apache.tajo.util.CommonTestingUtil; import org.apache.tajo.util.KeyValueSet; import org.junit.AfterClass; @@ -153,7 +152,7 @@ public class TestLinkedMetadataManager { static CatalogService catalog; @BeforeClass - public static void setUp() throws IOException { + public static void setUp() throws IOException, DuplicateTablespaceException, DuplicateDatabaseException { TajoConf conf = new TajoConf(); conf.setVar(TajoConf.ConfVars.CATALOG_ADDRESS, "127.0.0.1:0"); @@ -227,7 +226,7 @@ public class TestLinkedMetadataManager { assertEquals(Sets.newHashSet("table1", "table2"), Sets.newHashSet(catalog.getAllTableNames("space1"))); } - @Test + @Test(expected = InsufficientPrivilegeException.class) public void testCreateTable() throws Exception { TableDesc tb = new TableDesc( "space1.errortable", @@ -235,22 +234,12 @@ public class TestLinkedMetadataManager { new TableMeta("x", new KeyValueSet()), URI.create("file:///")); - try { - catalog.createTable(tb); - fail(); - } catch (TajoInternalError e) { - assertEquals(Errors.ResultCode.INTERNAL_ERROR, e.getErrorCode()); - } + catalog.createTable(tb); } - @Test + @Test(expected = InsufficientPrivilegeException.class) public void testDropTable() throws Exception { - try { - catalog.dropTable("space1.table1"); - fail(); - } catch (TajoInternalError e) { - assertEquals(Errors.ResultCode.INTERNAL_ERROR, e.getErrorCode()); - } + catalog.dropTable("space1.table1"); } @Test http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 eadd4df..affd128 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 @@ -33,8 +33,10 @@ import org.apache.tajo.cli.tsql.commands.*; import org.apache.tajo.client.*; import org.apache.tajo.conf.TajoConf; import org.apache.tajo.conf.TajoConf.ConfVars; +import org.apache.tajo.exception.ExceptionUtil; import org.apache.tajo.exception.ReturnStateUtil; import org.apache.tajo.exception.TajoException; +import org.apache.tajo.exception.DefaultTajoException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.service.ServiceTrackerFactory; import org.apache.tajo.util.FileUtil; @@ -444,7 +446,7 @@ public class TajoCli { } private int executeParsedResults(Collection<ParsedResult> parsedResults) throws Exception { - int exitCode; + int exitCode = 0; for (ParsedResult parsedResult : parsedResults) { if (parsedResult.getType() == StatementType.META) { exitCode = executeMetaCommand(parsedResult.getStatement()); @@ -457,10 +459,10 @@ public class TajoCli { } } - return 0; + return exitCode; } - public int executeMetaCommand(String line) throws Exception { + public int executeMetaCommand(String line) { String [] metaCommands = line.split(";"); for (String metaCommand : metaCommands) { String arguments [] = metaCommand.split(" "); @@ -474,8 +476,8 @@ public class TajoCli { try { invoked.invoke(arguments); - } catch (Exception e) { - onError(null, e); + } catch (Throwable t) { + onError(t); return -1; } finally { context.getOutput().flush(); @@ -493,11 +495,8 @@ public class TajoCli { long startTime = System.currentTimeMillis(); ClientProtos.SubmitQueryResponse response = client.executeQueryWithJson(json); - if (response == null) { - onError("response is null", null); - - } else if (ReturnStateUtil.isSuccess(response.getState())) { + if (ReturnStateUtil.isSuccess(response.getState())) { switch (response.getResultType()) { case FETCH: QueryId queryId = new QueryId(response.getQueryId()); @@ -511,9 +510,7 @@ public class TajoCli { } } else { - if (ReturnStateUtil.isError(response.getState())) { - onError(response.getState().getMessage(), null); - } + onError((Throwable) ExceptionUtil.toTajoExceptionCommon(response.getState())); } } @@ -523,33 +520,33 @@ public class TajoCli { ClientProtos.SubmitQueryResponse response = null; try{ response = client.executeQuery(statement); - } catch(Throwable te){ - onError(null, te); + } catch(Throwable t){ + onError(t); } - if (response != null) { - if (ReturnStateUtil.isSuccess(response.getState())) { + if (ReturnStateUtil.isSuccess(response.getState())) { - switch (response.getResultType()) { - case FETCH: - QueryId queryId = new QueryId(response.getQueryId()); - waitForQueryCompleted(queryId); - break; - case ENCLOSED: - localQueryCompleted(response, startTime); - break; - default: - displayFormatter.printMessage(sout, "OK"); - } + switch (response.getResultType()) { - } else { - if (ReturnStateUtil.isError(response.getState())) { - onError(response.getState().getMessage(), null); - } + case FETCH: + QueryId queryId = new QueryId(response.getQueryId()); + waitForQueryCompleted(queryId); + break; + + case ENCLOSED: + localQueryCompleted(response, startTime); + break; + + default: + displayFormatter.printMessage(sout, "OK"); } + + } else { + onError((Throwable) ExceptionUtil.toTajoExceptionCommon(response.getState())); } + return wasError ? -1 : 0; } @@ -570,7 +567,7 @@ public class TajoCli { displayFormatter.printResult(sout, sin, desc, responseTime, res); } } catch (Throwable t) { - onError(null, t); + onError(t); } finally { if (res != null) { try { @@ -637,7 +634,7 @@ public class TajoCli { } } } catch (Throwable t) { - onError(null, t); + onError(t); } finally { if (res != null) { try { @@ -667,19 +664,13 @@ public class TajoCli { sout.println("Invalid command " + command + ". Try \\? for help."); } - private void onError(String message, Throwable t) { + private void onError(Throwable t) { + Preconditions.checkNotNull(t); + wasError = true; - if (t == null) { - displayFormatter.printErrorMessage(sout, message); - } else { - if (t instanceof SQLException) { - displayFormatter.printErrorMessage(sout, t.getMessage()); - } else { - displayFormatter.printErrorMessage(sout, t); - } - } - if (reconnect && (t instanceof InvalidClientSessionException || - (message != null && message.startsWith("org.apache.tajo.session.InvalidSessionException")))) { + displayFormatter.printErrorMessage(sout, t.getMessage()); + + if (reconnect && (t instanceof InvalidClientSessionException)) { try { ((SessionConnection)client).reconnect(); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 3682a74..819f848 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 @@ -18,9 +18,11 @@ package org.apache.tajo.cli.tsql.commands; +import com.google.common.base.Preconditions; import com.google.protobuf.ServiceException; import org.apache.tajo.cli.tsql.TajoCli; import org.apache.tajo.exception.TajoException; +import org.apache.tajo.exception.UndefinedDatabaseException; import java.sql.SQLException; @@ -37,28 +39,28 @@ public class ConnectDatabaseCommand extends TajoShellCommand { @Override public void invoke(String[] cmd) throws Exception { - if (cmd.length == 1) { + + if (cmd.length == 1) { // no given database name + context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n", client.getCurrentDatabase(), client.getUserInfo().getUserName())); + } else if (cmd.length == 2) { - String databaseName = cmd[1]; - databaseName = databaseName.replace("\"", ""); - if (!client.existDatabase(databaseName)) { - context.getOutput().write("Database '" + databaseName + "' not found\n"); - } else { - try { - if (client.selectDatabase(databaseName)) { - context.setCurrentDatabase(client.getCurrentDatabase()); - context.getOutput().write(String.format("You are now connected to database \"%s\" as user \"%s\".%n", - context.getCurrentDatabase(), client.getUserInfo().getUserName())); - } - } catch (TajoException se) { - if (se.getMessage() != null) { - context.getOutput().write(se.getMessage()); - } else { - context.getOutput().write(String.format("cannot connect the database \"%s\"", databaseName)); - } - } + final String databaseName = cmd[1].replace("\"", ""); + + try { + client.selectDatabase(databaseName); + Preconditions.checkState(databaseName.equals(client.getCurrentDatabase())); + + context.setCurrentDatabase(client.getCurrentDatabase()); + context.getOutput().write(String.format( + "You are now connected to database \"%s\" as user \"%s\".%n", + context.getCurrentDatabase(), + client.getUserInfo().getUserName()) + ); + + } catch (TajoException se) { + context.getOutput().write("ERROR: " + se.getMessage()); } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java ---------------------------------------------------------------------- diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java index 4b7006d..b17a336 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java @@ -28,6 +28,7 @@ import org.apache.tajo.catalog.partition.PartitionMethodDesc; import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto; import org.apache.tajo.catalog.proto.CatalogProtos.SortSpecProto; import org.apache.tajo.cli.tsql.TajoCli; +import org.apache.tajo.exception.TajoException; import org.apache.tajo.util.FileUtil; import org.apache.tajo.util.StringUtils; @@ -45,7 +46,7 @@ public class DescTableCommand extends TajoShellCommand { } @Override - public void invoke(String[] cmd) throws Exception { + public void invoke(String[] cmd) throws TajoException { if (cmd.length == 2) { String tableName = cmd[1]; tableName = tableName.replace("\"", ""); http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java ---------------------------------------------------------------------- diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java index 2ac5854..22fa829 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoShellCommand.java @@ -28,8 +28,11 @@ public abstract class TajoShellCommand { return new String[] {}; } public abstract void invoke(String [] command) throws Exception; + public abstract String getUsage(); + public abstract String getDescription(); + public void printHelp() { context.getOutput().print(getCommand()); context.getOutput().print(" - "); @@ -78,10 +81,6 @@ public abstract class TajoShellCommand { } } - protected void printCenter(String message) { - printCenter(message, maxColumn, true); - } - protected void print(char c, int count) { for(int i = 0; i < count; i++) { context.getOutput().print(c); http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 bc63f84..7acc9b9 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,15 +22,13 @@ 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 org.apache.tajo.exception.*; import java.io.Closeable; import java.net.URI; -import java.sql.SQLException; import java.util.List; public interface CatalogAdminClient extends Closeable { @@ -39,15 +37,14 @@ public interface CatalogAdminClient extends Closeable { * * @param databaseName The database name to be created. This name is case sensitive. * @return True if created successfully. - * @throws java.sql.SQLException + * @throws DuplicateDatabaseException */ - boolean createDatabase(final String databaseName) throws DuplicateDatabaseException; + void createDatabase(final String databaseName) throws DuplicateDatabaseException; /** * Does the database exist? * * @param databaseName The database name to be checked. This name is case sensitive. * @return True if so. - * @throws java.sql.SQLException */ boolean existDatabase(final String databaseName); /** @@ -55,9 +52,9 @@ public interface CatalogAdminClient extends Closeable { * * @param databaseName The database name to be dropped. This name is case sensitive. * @return True if the database is dropped successfully. - * @throws java.sql.SQLException + * @throws UndefinedDatabaseException */ - boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException; + void dropDatabase(final String databaseName) throws UndefinedDatabaseException, InsufficientPrivilegeException; List<String> getAllDatabaseNames(); @@ -78,10 +75,11 @@ public interface CatalogAdminClient extends Closeable { * @param path The external table location * @param meta Table meta * @return the created table description. - * @throws java.sql.SQLException + * @throws DuplicateTableException */ TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, - final TableMeta meta) throws DuplicateTableException; + final TableMeta meta) + throws DuplicateTableException, UnavailableTableLocationException, InsufficientPrivilegeException; /** * Create an external table. @@ -93,20 +91,20 @@ public interface CatalogAdminClient extends Closeable { * @param meta Table meta * @param partitionMethodDesc Table partition description * @return the created table description. - * @throws java.sql.SQLException + * @throws DuplicateTableException */ TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, final TableMeta meta, final PartitionMethodDesc partitionMethodDesc) - throws DuplicateTableException; + throws DuplicateTableException, InsufficientPrivilegeException, UnavailableTableLocationException; /** * Drop a table * * @param tableName The table name to be dropped. This name is case sensitive. * @return True if the table is dropped successfully. - * @throws java.sql.SQLException + * @throws InsufficientPrivilegeException */ - boolean dropTable(final String tableName) throws UndefinedTableException; + void dropTable(final String tableName) throws UndefinedTableException, InsufficientPrivilegeException; /** * Drop a table. @@ -114,9 +112,11 @@ public interface CatalogAdminClient extends Closeable { * @param tableName The table name to be dropped. This name is case sensitive. * @param purge If purge is true, this call will remove the entry in catalog as well as the table contents. * @return True if the table is dropped successfully. - * @throws java.sql.SQLException + * @throws UndefinedTableException + * @throws InsufficientPrivilegeException */ - boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException; + void dropTable(final String tableName, final boolean purge) throws UndefinedTableException, + InsufficientPrivilegeException; /** * Get a list of table names. @@ -124,7 +124,6 @@ public interface CatalogAdminClient extends Closeable { * @param databaseName The database name to show all tables. This name is case sensitive. * If it is null, this method will show all tables * in the current database of this session. - * @throws java.sql.SQLException */ List<String> getTableList(@Nullable final String databaseName); @@ -133,23 +132,23 @@ public interface CatalogAdminClient extends Closeable { * * @param tableName The table name to get. This name is case sensitive. * @return Table description - * @throws java.sql.SQLException + * @throws UndefinedTableException */ TableDesc getTableDesc(final String tableName) throws UndefinedTableException; List<CatalogProtos.FunctionDescProto> getFunctions(final String functionName); - IndexDescProto getIndex(final String indexName) throws SQLException; + IndexDescProto getIndex(final String indexName); - boolean existIndex(final String indexName) throws SQLException; + boolean existIndex(final String indexName); - List<IndexDescProto> getIndexes(final String tableName) throws SQLException; + List<IndexDescProto> getIndexes(final String tableName); - boolean hasIndexes(final String tableName) throws SQLException; + boolean hasIndexes(final String tableName); - IndexDescProto getIndex(final String tableName, final String[] columnNames) throws SQLException; + IndexDescProto getIndex(final String tableName, final String[] columnNames); - boolean existIndex(final String tableName, final String[] columnName) throws SQLException; + boolean existIndex(final String tableName, final String[] columnName); - boolean dropIndex(final String indexName) throws SQLException; + boolean dropIndex(final String indexName); } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 d4d8a86..af1278d 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,25 +24,24 @@ 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; +import org.apache.tajo.error.Errors.ResultCode; +import org.apache.tajo.exception.*; 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.ReturnState; import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListResponse; import java.io.IOException; import java.net.URI; -import java.sql.SQLException; import java.util.List; +import static org.apache.tajo.exception.ExceptionUtil.throwsIfThisError; import static org.apache.tajo.exception.ReturnStateUtil.*; -import static org.apache.tajo.exception.SQLExceptionUtil.throwIfError; import static org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface; public class CatalogAdminClientImpl implements CatalogAdminClient { @@ -53,19 +52,16 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { } @Override - public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException { + public void createDatabase(final String databaseName) throws DuplicateDatabaseException { - final BlockingInterface stub = conn.getTMStub(); - try { - PrimitiveProtos.ReturnState state = stub.createDatabase(null, conn.getSessionedString(databaseName)); - if (isThisError(state, Errors.ResultCode.DUPLICATE_DATABASE)) { - throw new DuplicateDatabaseException(state); - } + try { + final BlockingInterface stub = conn.getTMStub(); + final ReturnState state = stub.createDatabase(null, conn.getSessionedString(databaseName)); + throwsIfThisError(state, DuplicateDatabaseException.class); ensureOk(state); - return true; } catch (ServiceException e) { throw new RuntimeException(e); @@ -75,27 +71,33 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { @Override public boolean existDatabase(final String databaseName) { - final BlockingInterface stub = conn.getTMStub(); - try { - return isSuccess(stub.existDatabase(null, conn.getSessionedString(databaseName))); + final BlockingInterface stub = conn.getTMStub(); + final ReturnState state = stub.existDatabase(null, conn.getSessionedString(databaseName)); + + if (isThisError(state, ResultCode.UNDEFINED_DATABASE)) { + return false; + } + ensureOk(state); + return true; + } catch (ServiceException e) { throw new RuntimeException(e); } } @Override - public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException { - - final BlockingInterface stub = conn.getTMStub(); + public void dropDatabase(final String databaseName) throws UndefinedDatabaseException { try { - PrimitiveProtos.ReturnState state = stub.dropDatabase(null, conn.getSessionedString(databaseName)); - if (isThisError(state, Errors.ResultCode.UNDEFINED_DATABASE)) { + final BlockingInterface stub = conn.getTMStub(); + final ReturnState state = stub.dropDatabase(null, conn.getSessionedString(databaseName)); + + if (isThisError(state, ResultCode.UNDEFINED_DATABASE)) { throw new UndefinedDatabaseException(state); } ensureOk(state); - return true; + } catch (ServiceException e) { throw new RuntimeException(e); } @@ -117,14 +119,14 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { final BlockingInterface stub = conn.getTMStub(); - PrimitiveProtos.ReturnState state; + ReturnState state; try { state = stub.existTable(null, conn.getSessionedString(tableName)); } catch (ServiceException e) { throw new RuntimeException(e); } - if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) { + if (isThisError(state, ResultCode.UNDEFINED_TABLE)) { return false; } @@ -134,19 +136,19 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { @Override public TableDesc createExternalTable(String tableName, Schema schema, URI path, TableMeta meta) - throws DuplicateTableException { + throws DuplicateTableException, UnavailableTableLocationException, InsufficientPrivilegeException { 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 DuplicateTableException { + throws DuplicateTableException, InsufficientPrivilegeException, UnavailableTableLocationException { - NettyClientBase client = conn.getTajoMasterConnection(); + final NettyClientBase client = conn.getTajoMasterConnection(); conn.checkSessionAndGet(client); - BlockingInterface tajoMasterService = client.getStub(); + final BlockingInterface tajoMasterService = client.getStub(); - ClientProtos.CreateTableRequest.Builder builder = ClientProtos.CreateTableRequest.newBuilder(); + final ClientProtos.CreateTableRequest.Builder builder = ClientProtos.CreateTableRequest.newBuilder(); builder.setSessionId(conn.sessionId); builder.setName(tableName); builder.setSchema(schema.getProto()); @@ -164,21 +166,22 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { throw new RuntimeException(e); } - if (isThisError(res.getState(), Errors.ResultCode.DUPLICATE_TABLE)) { - throw new DuplicateTableException(res.getState()); - } + throwsIfThisError(res.getState(), DuplicateTableException.class); + throwsIfThisError(res.getState(), InsufficientPrivilegeException.class); + throwsIfThisError(res.getState(), UnavailableTableLocationException.class); ensureOk(res.getState()); return CatalogUtil.newTableDesc(res.getTable()); } @Override - public boolean dropTable(String tableName) throws UndefinedTableException { - return dropTable(tableName, false); + public void dropTable(String tableName) throws UndefinedTableException, InsufficientPrivilegeException { + dropTable(tableName, false); } @Override - public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException { + public void dropTable(final String tableName, final boolean purge) + throws UndefinedTableException, InsufficientPrivilegeException { final BlockingInterface stub = conn.getTMStub(); final DropTableRequest request = DropTableRequest.newBuilder() @@ -188,19 +191,17 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { .build(); - PrimitiveProtos.ReturnState state; + ReturnState state; try { state = stub.dropTable(null, request); } catch (ServiceException e) { throw new RuntimeException(e); } - if (isThisError(state, Errors.ResultCode.UNDEFINED_TABLE)) { - throw new UndefinedTableException(state); - } + throwsIfThisError(state, UndefinedTableException.class); + throwsIfThisError(state, InsufficientPrivilegeException.class); ensureOk(state); - return true; } @Override @@ -231,7 +232,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { throw new RuntimeException(e); } - if (isThisError(res.getState(), Errors.ResultCode.UNDEFINED_TABLE)) { + if (isThisError(res.getState(), ResultCode.UNDEFINED_TABLE)) { throw new UndefinedTableException(res.getState()); } @@ -257,7 +258,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { } @Override - public IndexDescProto getIndex(final String indexName) throws SQLException { + public IndexDescProto getIndex(final String indexName) { final BlockingInterface stub = conn.getTMStub(); IndexResponse res; @@ -267,12 +268,12 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { throw new RuntimeException(e); } - throwIfError(res.getState()); + ensureOk(res.getState()); return res.getIndexDesc(); } @Override - public boolean existIndex(final String indexName) throws SQLException { + public boolean existIndex(final String indexName){ final BlockingInterface stub = conn.getTMStub(); try { @@ -283,7 +284,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { } @Override - public List<IndexDescProto> getIndexes(final String tableName) throws SQLException { + public List<IndexDescProto> getIndexes(final String tableName) { final BlockingInterface stub = conn.getTMStub(); IndexListResponse response; @@ -294,12 +295,12 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { throw new RuntimeException(e); } - throwIfError(response.getState()); + ensureOk(response.getState()); return response.getIndexDescList(); } @Override - public boolean hasIndexes(final String tableName) throws SQLException { + public boolean hasIndexes(final String tableName) { final BlockingInterface stub = conn.getTMStub(); try { @@ -310,7 +311,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { } @Override - public IndexDescProto getIndex(final String tableName, final String[] columnNames) throws SQLException { + public IndexDescProto getIndex(final String tableName, final String[] columnNames) { final BlockingInterface stub = conn.getTMStub(); GetIndexWithColumnsRequest.Builder builder = GetIndexWithColumnsRequest.newBuilder(); @@ -327,12 +328,12 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { throw new RuntimeException(e); } - throwIfError(response.getState()); + ensureOk(response.getState()); return response.getIndexDesc(); } @Override - public boolean existIndex(final String tableName, final String[] columnName) throws SQLException { + public boolean existIndex(final String tableName, final String[] columnName) { final BlockingInterface stub = conn.getTMStub(); GetIndexWithColumnsRequest.Builder builder = GetIndexWithColumnsRequest.newBuilder(); @@ -350,7 +351,7 @@ public class CatalogAdminClientImpl implements CatalogAdminClient { } @Override - public boolean dropIndex(final String indexName) throws SQLException { + public boolean dropIndex(final String indexName) { final BlockingInterface stub = conn.getTMStub(); try { http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 deleted file mode 100644 index 2ecc078..0000000 --- a/tajo-client/src/main/java/org/apache/tajo/client/ClientExceptionUtil.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tajo.client; - -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/903151ea/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 966bddf..ad9bfc5 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 @@ -20,10 +20,12 @@ package org.apache.tajo.client; import org.apache.tajo.QueryId; import org.apache.tajo.auth.UserRoleInfo; -import org.apache.tajo.catalog.exception.UndefinedDatabaseException; +import org.apache.tajo.exception.UndefinedDatabaseException; import org.apache.tajo.exception.NoSuchSessionVariableException; +import org.apache.tajo.exception.QueryNotFoundException; import org.apache.tajo.exception.TajoException; import org.apache.tajo.ipc.ClientProtos; +import org.apache.tajo.ipc.ClientProtos.GetQueryResultResponse; import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto; import org.apache.tajo.ipc.ClientProtos.QueryInfoProto; import org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse; @@ -31,7 +33,6 @@ import org.apache.tajo.jdbc.TajoMemoryResultSet; import java.io.Closeable; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.List; import java.util.Map; @@ -60,19 +61,19 @@ public interface QueryClient extends Closeable { */ void closeQuery(final QueryId queryId); - void closeNonForwardQuery(final QueryId queryId) throws SQLException; + void closeNonForwardQuery(final QueryId queryId); String getCurrentDatabase(); - Boolean selectDatabase(final String databaseName) throws UndefinedDatabaseException; + void selectDatabase(final String databaseName) throws UndefinedDatabaseException; - Map<String, String> updateSessionVariables(final Map<String, String> variables) throws NoSuchSessionVariableException; + Map<String, String> updateSessionVariables(final Map<String, String> variables); - Map<String, String> unsetSessionVariables(final List<String> variables) throws NoSuchSessionVariableException; + Map<String, String> unsetSessionVariables(final List<String> variables); String getSessionVariable(final String varname) throws NoSuchSessionVariableException; - Boolean existSessionVariable(final String varname); + boolean existSessionVariable(final String varname); Map<String, String> getAllSessionVariables(); @@ -97,29 +98,29 @@ public interface QueryClient extends Closeable { ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException; - QueryStatus getQueryStatus(QueryId queryId); + QueryStatus getQueryStatus(QueryId queryId) throws QueryNotFoundException; - ResultSet getQueryResult(QueryId queryId) throws SQLException; + ResultSet getQueryResult(QueryId queryId) throws TajoException; - ResultSet createNullResultSet(QueryId queryId) throws SQLException; + ResultSet createNullResultSet(QueryId queryId); - ClientProtos.GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException; + GetQueryResultResponse getResultResponse(QueryId queryId) throws TajoException; - TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException; + TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws TajoException; boolean updateQuery(final String sql) throws TajoException; boolean updateQueryWithJson(final String json) throws TajoException; - List<ClientProtos.BriefQueryInfo> getRunningQueryList() throws SQLException; + List<ClientProtos.BriefQueryInfo> getRunningQueryList(); List<ClientProtos.BriefQueryInfo> getFinishedQueryList(); - List<ClientProtos.WorkerResourceInfo> getClusterInfo() throws SQLException; + List<ClientProtos.WorkerResourceInfo> getClusterInfo(); - QueryStatus killQuery(final QueryId queryId); + QueryStatus killQuery(final QueryId queryId) throws QueryNotFoundException; - QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException; + QueryInfoProto getQueryInfo(final QueryId queryId) throws QueryNotFoundException; - QueryHistoryProto getQueryHistory(final QueryId queryId) throws SQLException; + QueryHistoryProto getQueryHistory(final QueryId queryId) throws QueryNotFoundException; } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 02110c0..20e56ac 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 @@ -21,16 +21,17 @@ package org.apache.tajo.client; import com.google.protobuf.ServiceException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.tajo.*; +import org.apache.tajo.QueryId; +import org.apache.tajo.QueryIdFactory; +import org.apache.tajo.SessionVars; import org.apache.tajo.TajoIdProtos.SessionIdProto; +import org.apache.tajo.TajoProtos; 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.client.v2.exception.ClientUnableToConnectException; +import org.apache.tajo.exception.*; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.ipc.QueryMasterClientProtocol; import org.apache.tajo.ipc.TajoMasterClientProtocol.TajoMasterClientProtocolService.BlockingInterface; @@ -38,20 +39,20 @@ import org.apache.tajo.jdbc.FetchResultSet; import org.apache.tajo.jdbc.TajoMemoryResultSet; import org.apache.tajo.rpc.NettyClientBase; import org.apache.tajo.rpc.RpcClientManager; +import org.apache.tajo.util.NetUtils; import org.apache.tajo.util.ProtoUtil; import java.net.ConnectException; import java.net.InetSocketAddress; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import static org.apache.tajo.exception.ExceptionUtil.throwIfError; +import static org.apache.tajo.exception.ExceptionUtil.throwsIfThisError; 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; import static org.apache.tajo.ipc.ClientProtos.*; import static org.apache.tajo.ipc.QueryMasterClientProtocol.QueryMasterClientProtocolService; @@ -118,17 +119,17 @@ public class QueryClientImpl implements QueryClient { } @Override - public Boolean selectDatabase(String databaseName) throws UndefinedDatabaseException { - return conn.selectDatabase(databaseName); + public void selectDatabase(String databaseName) throws UndefinedDatabaseException { + conn.selectDatabase(databaseName); } @Override - public Map<String, String> updateSessionVariables(Map<String, String> variables) throws NoSuchSessionVariableException { + public Map<String, String> updateSessionVariables(Map<String, String> variables) { return conn.updateSessionVariables(variables); } @Override - public Map<String, String> unsetSessionVariables(List<String> variables) throws NoSuchSessionVariableException { + public Map<String, String> unsetSessionVariables(List<String> variables) { return conn.unsetSessionVariables(variables); } @@ -138,7 +139,7 @@ public class QueryClientImpl implements QueryClient { } @Override - public Boolean existSessionVariable(String varname) { + public boolean existSessionVariable(String varname) { return conn.existSessionVariable(varname); } @@ -184,7 +185,7 @@ public class QueryClientImpl implements QueryClient { public ResultSet executeQueryAndGetResult(String sql) throws TajoException { ClientProtos.SubmitQueryResponse response = executeQuery(sql); - ensureOk(response.getState()); + throwIfError(response.getState()); QueryId queryId = new QueryId(response.getQueryId()); @@ -202,7 +203,7 @@ public class QueryClientImpl implements QueryClient { public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException { ClientProtos.SubmitQueryResponse response = executeQueryWithJson(json); - ensureOk(response.getState()); + throwIfError(response.getState()); QueryId queryId = new QueryId(response.getQueryId()); @@ -216,7 +217,7 @@ public class QueryClientImpl implements QueryClient { } } - public ResultSet getQueryResultAndWait(QueryId queryId) { + public ResultSet getQueryResultAndWait(QueryId queryId) throws QueryNotFoundException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); @@ -254,12 +255,11 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(t); } - ensureOk(res.getState()); return res; } @Override - public QueryStatus getQueryStatus(QueryId queryId) { + public QueryStatus getQueryStatus(QueryId queryId) throws QueryNotFoundException { final BlockingInterface stub = conn.getTMStub(); final GetQueryStatusRequest request = GetQueryStatusRequest.newBuilder() @@ -274,19 +274,20 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(t); } + throwsIfThisError(res.getState(), QueryNotFoundException.class); ensureOk(res.getState()); return new QueryStatus(res); } @Override - public ResultSet getQueryResult(QueryId queryId) { + public ResultSet getQueryResult(QueryId queryId) throws QueryNotFoundException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return createNullResultSet(queryId); } GetQueryResultResponse response = getResultResponse(queryId); - ensureOk(response.getState()); + TableDesc tableDesc = CatalogUtil.newTableDesc(response.getTableDesc()); return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows); } @@ -297,7 +298,7 @@ public class QueryClientImpl implements QueryClient { } @Override - public GetQueryResultResponse getResultResponse(QueryId queryId) { + public GetQueryResultResponse getResultResponse(QueryId queryId) throws QueryNotFoundException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return null; } @@ -315,12 +316,13 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(t); } + throwsIfThisError(response.getState(), QueryNotFoundException.class); ensureOk(response.getState()); return response; } @Override - public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException { + public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws TajoException { final BlockingInterface stub = conn.getTMStub(); final GetQueryResultDataRequest request = GetQueryResultDataRequest.newBuilder() @@ -359,7 +361,7 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(e); } - ClientExceptionUtil.throwIfError(response.getState()); + throwIfError(response.getState()); conn.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars())); return true; @@ -378,12 +380,12 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(e); } - ClientExceptionUtil.throwIfError(response.getState()); + throwIfError(response.getState()); return true; } @Override - public List<ClientProtos.BriefQueryInfo> getRunningQueryList() throws SQLException { + public List<ClientProtos.BriefQueryInfo> getRunningQueryList() { final BlockingInterface stmb = conn.getTMStub(); @@ -394,7 +396,7 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(e); } - throwIfError(res.getState()); + ensureOk(res.getState()); return res.getQueryListList(); } @@ -415,7 +417,7 @@ public class QueryClientImpl implements QueryClient { } @Override - public List<ClientProtos.WorkerResourceInfo> getClusterInfo() throws SQLException { + public List<ClientProtos.WorkerResourceInfo> getClusterInfo() { final BlockingInterface stub = conn.getTMStub(); final GetClusterInfoRequest request = GetClusterInfoRequest.newBuilder() @@ -429,18 +431,18 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(e); } - throwIfError(res.getState()); + ensureOk(res.getState()); return res.getWorkerListList(); } @Override - public QueryStatus killQuery(final QueryId queryId) { + public QueryStatus killQuery(final QueryId queryId) throws QueryNotFoundException { final BlockingInterface stub = conn.getTMStub(); QueryStatus status = getQueryStatus(queryId); /* send a kill to the TM */ - QueryIdRequest request = buildQueryIdRequest(queryId); + final QueryIdRequest request = buildQueryIdRequest(queryId); try { stub.killQuery(null, request); } catch (ServiceException e) { @@ -475,7 +477,7 @@ public class QueryClientImpl implements QueryClient { return this.maxRows; } - public QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException { + public QueryInfoProto getQueryInfo(final QueryId queryId) throws QueryNotFoundException { final BlockingInterface stub = conn.getTMStub(); final QueryIdRequest request = buildQueryIdRequest(queryId); @@ -487,11 +489,12 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(e); } - throwIfError(res.getState()); + throwsIfThisError(res.getState(), QueryNotFoundException.class); + ensureOk(res.getState()); return res.getQueryInfo(); } - public QueryHistoryProto getQueryHistory(final QueryId queryId) throws SQLException { + public QueryHistoryProto getQueryHistory(final QueryId queryId) throws QueryNotFoundException { final QueryInfoProto queryInfo = getQueryInfo(queryId); if (queryInfo.getHostNameOfQM() == null || queryInfo.getQueryMasterClientPort() == 0) { @@ -504,6 +507,7 @@ public class QueryClientImpl implements QueryClient { RpcClientManager manager = RpcClientManager.getInstance(); NettyClientBase qmClient = null; + try { qmClient = manager.newClient( @@ -516,6 +520,7 @@ public class QueryClientImpl implements QueryClient { false ); + conn.checkSessionAndGet(conn.getTajoMasterConnection()); QueryIdRequest request = QueryIdRequest.newBuilder() @@ -531,19 +536,18 @@ public class QueryClientImpl implements QueryClient { throw new RuntimeException(e); } - throwIfError(res.getState()); + ensureOk(res.getState()); return res.getQueryHistory(); + } catch (NoSuchMethodException | ClassNotFoundException e) { + throw new TajoInternalError(e); } catch (ConnectException e) { - throw SQLExceptionUtil.makeUnableToEstablishConnection(e); - } catch (ClassNotFoundException e) { - throw SQLExceptionUtil.makeUnableToEstablishConnection(e); - } catch (NoSuchMethodException e) { - throw SQLExceptionUtil.makeUnableToEstablishConnection(e); - } catch (SQLException e) { - throw e; + throw new TajoRuntimeException( + new ClientUnableToConnectException(NetUtils.normalizeInetSocketAddress(qmAddress))); } finally { - qmClient.close(); + if (qmClient != null) { + qmClient.close(); + } } } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 a97cb33..105830f 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,10 +26,10 @@ 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.exception.ExceptionUtil; +import org.apache.tajo.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; import org.apache.tajo.ipc.ClientProtos.UpdateSessionVariableRequest; @@ -61,7 +61,6 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.apache.tajo.error.Errors.ResultCode.NO_SUCH_SESSION_VARIABLE; 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; @@ -226,7 +225,7 @@ public class SessionConnection implements Closeable { return Collections.unmodifiableMap(sessionVarsCache); } - public Map<String, String> unsetSessionVariables(final List<String> variables) throws NoSuchSessionVariableException { + public Map<String, String> unsetSessionVariables(final List<String> variables) { final BlockingInterface stub = getTMStub(); final UpdateSessionVariableRequest request = UpdateSessionVariableRequest.newBuilder() @@ -241,10 +240,6 @@ public class SessionConnection implements Closeable { throw new RuntimeException(e); } - 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); @@ -285,7 +280,7 @@ public class SessionConnection implements Closeable { return response.getValue(); } - public Boolean existSessionVariable(final String varname) { + public boolean existSessionVariable(final String varname) { ReturnState state; try { @@ -319,27 +314,19 @@ public class SessionConnection implements Closeable { return ProtoUtil.convertToMap(response.getValue()); } - public Boolean selectDatabase(final String dbName) throws UndefinedDatabaseException { + public void selectDatabase(final String dbName) throws UndefinedDatabaseException { - BlockingInterface stub = getTMStub(); - boolean selected; try { - ReturnState state = stub.selectDatabase(null, getSessionedString(dbName)); - - if (isThisError(state, UNDEFINED_DATABASE)) { - throw new UndefinedDatabaseException(dbName); - } + final BlockingInterface stub = getTMStub(); + final ReturnState state = stub.selectDatabase(null, getSessionedString(dbName)); - selected = ensureOk(state); + ExceptionUtil.throwsIfThisError(state, UndefinedDatabaseException.class); + ensureOk(state); + this.baseDatabase = dbName; } catch (ServiceException e) { throw new RuntimeException(e); } - - if (selected) { - this.baseDatabase = dbName; - } - return selected; } @Override http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 8c167a4..a6c07ea 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,11 +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.exception.*; import org.apache.tajo.ipc.ClientProtos.*; import org.apache.tajo.jdbc.TajoMemoryResultSet; import org.apache.tajo.service.ServiceTracker; @@ -96,7 +95,7 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que queryClient.closeQuery(queryId); } - public void closeNonForwardQuery(final QueryId queryId) throws SQLException { + public void closeNonForwardQuery(final QueryId queryId) { queryClient.closeNonForwardQuery(queryId); } @@ -116,23 +115,23 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que return queryClient.executeJsonQueryAndGetResult(json); } - public QueryStatus getQueryStatus(QueryId queryId) { + public QueryStatus getQueryStatus(QueryId queryId) throws QueryNotFoundException { return queryClient.getQueryStatus(queryId); } - public ResultSet getQueryResult(QueryId queryId) throws SQLException { + public ResultSet getQueryResult(QueryId queryId) throws TajoException { return queryClient.getQueryResult(queryId); } - public ResultSet createNullResultSet(QueryId queryId) throws SQLException { + public ResultSet createNullResultSet(QueryId queryId) { return TajoClientUtil.createNullResultSet(queryId); } - public GetQueryResultResponse getResultResponse(QueryId queryId) throws SQLException { + public GetQueryResultResponse getResultResponse(QueryId queryId) throws TajoException { return queryClient.getResultResponse(queryId); } - public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws SQLException { + public TajoMemoryResultSet fetchNextQueryResult(final QueryId queryId, final int fetchRowNum) throws TajoException { return queryClient.fetchNextQueryResult(queryId, fetchRowNum); } @@ -144,11 +143,11 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que return queryClient.updateQueryWithJson(json); } - public QueryStatus killQuery(final QueryId queryId) { + public QueryStatus killQuery(final QueryId queryId) throws QueryNotFoundException { return queryClient.killQuery(queryId); } - public List<BriefQueryInfo> getRunningQueryList() throws SQLException { + public List<BriefQueryInfo> getRunningQueryList() { return queryClient.getRunningQueryList(); } @@ -156,15 +155,15 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que return queryClient.getFinishedQueryList(); } - public List<WorkerResourceInfo> getClusterInfo() throws SQLException { + public List<WorkerResourceInfo> getClusterInfo() { return queryClient.getClusterInfo(); } - public QueryInfoProto getQueryInfo(final QueryId queryId) throws SQLException { + public QueryInfoProto getQueryInfo(final QueryId queryId) throws QueryNotFoundException { return queryClient.getQueryInfo(queryId); } - public QueryHistoryProto getQueryHistory(final QueryId queryId) throws SQLException { + public QueryHistoryProto getQueryHistory(final QueryId queryId) throws QueryNotFoundException { return queryClient.getQueryHistory(queryId); } @@ -180,16 +179,18 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que // CatalogClient wrappers /*------------------------------------------------------------------------*/ - public boolean createDatabase(final String databaseName) throws DuplicateDatabaseException { - return catalogClient.createDatabase(databaseName); + public void createDatabase(final String databaseName) throws DuplicateDatabaseException { + catalogClient.createDatabase(databaseName); } public boolean existDatabase(final String databaseName) { return catalogClient.existDatabase(databaseName); } - public boolean dropDatabase(final String databaseName) throws UndefinedDatabaseException { - return catalogClient.dropDatabase(databaseName); + public void dropDatabase(final String databaseName) throws UndefinedDatabaseException, + InsufficientPrivilegeException { + + catalogClient.dropDatabase(databaseName); } public List<String> getAllDatabaseNames() { @@ -200,23 +201,28 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que return catalogClient.existTable(tableName); } - public TableDesc createExternalTable(final String tableName, final Schema schema, final URI path, - final TableMeta meta) throws DuplicateTableException { + public TableDesc createExternalTable(final String tableName, + final Schema schema, + final URI path, + final TableMeta meta) + throws DuplicateTableException, UnavailableTableLocationException, InsufficientPrivilegeException { + 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 DuplicateTableException { + throws DuplicateTableException, UnavailableTableLocationException, InsufficientPrivilegeException { return catalogClient.createExternalTable(tableName, schema, path, meta, partitionMethodDesc); } - public boolean dropTable(final String tableName) throws UndefinedTableException { - return dropTable(tableName, false); + public void dropTable(final String tableName) throws UndefinedTableException, InsufficientPrivilegeException { + dropTable(tableName, false); } - public boolean dropTable(final String tableName, final boolean purge) throws UndefinedTableException { - return catalogClient.dropTable(tableName, purge); + public void dropTable(final String tableName, final boolean purge) throws UndefinedTableException, + InsufficientPrivilegeException { + catalogClient.dropTable(tableName, purge); } public List<String> getTableList(@Nullable final String databaseName) { @@ -232,37 +238,37 @@ public class TajoClientImpl extends SessionConnection implements TajoClient, Que } @Override - public IndexDescProto getIndex(String indexName) throws SQLException { + public IndexDescProto getIndex(String indexName) { return catalogClient.getIndex(indexName); } @Override - public boolean existIndex(String indexName) throws SQLException { + public boolean existIndex(String indexName) { return catalogClient.existIndex(indexName); } @Override - public List<IndexDescProto> getIndexes(String tableName) throws SQLException { + public List<IndexDescProto> getIndexes(String tableName) { return catalogClient.getIndexes(tableName); } @Override - public boolean hasIndexes(String tableName) throws SQLException { + public boolean hasIndexes(String tableName) { return catalogClient.hasIndexes(tableName); } @Override - public IndexDescProto getIndex(String tableName, String[] columnNames) throws SQLException { + public IndexDescProto getIndex(String tableName, String[] columnNames) { return catalogClient.getIndex(tableName, columnNames); } @Override - public boolean existIndex(String tableName, String[] columnName) throws SQLException { + public boolean existIndex(String tableName, String[] columnName) { return catalogClient.existIndex(tableName, columnName); } @Override - public boolean dropIndex(String indexName) throws SQLException { + public boolean dropIndex(String indexName) { return catalogClient.dropIndex(indexName); } } http://git-wip-us.apache.org/repos/asf/tajo/blob/903151ea/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 c79b756..3f30f97 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 @@ -25,6 +25,7 @@ import org.apache.tajo.TajoProtos; import org.apache.tajo.catalog.CatalogUtil; import org.apache.tajo.catalog.Schema; import org.apache.tajo.catalog.TableDesc; +import org.apache.tajo.exception.QueryNotFoundException; import org.apache.tajo.ipc.ClientProtos; import org.apache.tajo.jdbc.FetchResultSet; import org.apache.tajo.jdbc.TajoMemoryResultSet; @@ -58,7 +59,7 @@ public class TajoClientUtil { return !isQueryWaitingForSchedule(state) && !isQueryRunning(state); } - public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) { + public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) throws QueryNotFoundException { QueryStatus status = client.getQueryStatus(queryId); while(!isQueryComplete(status.getState())) {
