/** * check if the database exists. Otherwise, it throws an exception * * @param dbName Database name * @throws UndefinedDatabaseException */ private void ensureIfDBExists(String dbName) throws UndefinedDatabaseException { if (!providerMap.containsKey(dbName)) { throw new UndefinedDatabaseException(dbName); } }
/** * check if the database exists. Otherwise, it throws an exception * * @param dbName Database name * @throws UndefinedDatabaseException */ private void ensureIfDBExists(String dbName) throws UndefinedDatabaseException { if (!providerMap.containsKey(dbName)) { throw new UndefinedDatabaseException(dbName); } }
private boolean assertDatabaseExistence(VerificationState state, String name) { if (!catalog.existDatabase(name)) { state.addVerification(new UndefinedDatabaseException(name)); return false; } return true; }
private int getDatabaseId(String databaseName) throws UndefinedDatabaseException { String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES); if (LOG.isDebugEnabled()) { LOG.debug(sql); } ResultSet res = null; try (PreparedStatement pstmt = getConnection().prepareStatement(sql)) { pstmt.setString(1, databaseName); res = pstmt.executeQuery(); if (!res.next()) { throw new UndefinedDatabaseException(databaseName); } return res.getInt("DB_ID"); } catch (SQLException e) { throw new TajoInternalError(e); } finally { CatalogUtil.closeQuietly(res); } }
private boolean assertDatabaseExistence(VerificationState state, String name) { if (!catalog.existDatabase(name)) { state.addVerification(new UndefinedDatabaseException(name)); return false; } return true; }
private int getDatabaseId(String databaseName) throws UndefinedDatabaseException { String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES); if (LOG.isDebugEnabled()) { LOG.debug(sql); } Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; try { conn = getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setString(1, databaseName); res = pstmt.executeQuery(); if (!res.next()) { throw new UndefinedDatabaseException(databaseName); } return res.getInt("DB_ID"); } catch (SQLException e) { throw new TajoInternalError(e); } finally { CatalogUtil.closeQuietly(pstmt, res); } }
public Pair<Integer, String> getDatabaseIdAndUri(String databaseName) throws UndefinedDatabaseException { String sql = "SELECT DB_ID, SPACE_URI from " + TB_DATABASES + " natural join " + TB_SPACES + " WHERE db_name = ?"; if (LOG.isDebugEnabled()) { LOG.debug(sql); } ResultSet res = null; try (PreparedStatement pstmt = getConnection().prepareStatement(sql)) { pstmt.setString(1, databaseName); res = pstmt.executeQuery(); if (!res.next()) { throw new UndefinedDatabaseException(databaseName); } return new Pair<>(res.getInt(1), res.getString(2) + "/" + databaseName); } catch (SQLException e) { throw new TajoInternalError(e); } finally { CatalogUtil.closeQuietly(res); } }
public Pair<Integer, String> getDatabaseIdAndUri(String databaseName) throws UndefinedDatabaseException { String sql = "SELECT DB_ID, SPACE_URI from " + TB_DATABASES + " natural join " + TB_SPACES + " WHERE db_name = ?"; if (LOG.isDebugEnabled()) { LOG.debug(sql); } Connection conn = null; PreparedStatement pstmt = null; ResultSet res = null; try { conn = getConnection(); pstmt = conn.prepareStatement(sql); pstmt.setString(1, databaseName); res = pstmt.executeQuery(); if (!res.next()) { throw new UndefinedDatabaseException(databaseName); } return new Pair<>(res.getInt(1), res.getString(2) + "/" + databaseName); } catch (SQLException e) { throw new TajoInternalError(e); } finally { CatalogUtil.closeQuietly(pstmt, res); } }
public void dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) throws UndefinedDatabaseException, InsufficientPrivilegeException, CannotDropCurrentDatabaseException { boolean exists = catalog.existDatabase(databaseName); if (!exists) { if (ifExists) { // DROP DATABASE IF EXISTS LOG.info("database \"" + databaseName + "\" does not exists."); return; } else { // Otherwise, it causes an exception. throw new UndefinedDatabaseException(databaseName); } } if (queryContext.getCurrentDatabase().equals(databaseName)) { throw new CannotDropCurrentDatabaseException(); } catalog.dropDatabase(databaseName); }
public void dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) throws UndefinedDatabaseException, InsufficientPrivilegeException, CannotDropCurrentDatabaseException { boolean exists = catalog.existDatabase(databaseName); if (!exists) { if (ifExists) { // DROP DATABASE IF EXISTS LOG.info("database \"" + databaseName + "\" does not exists."); return; } else { // Otherwise, it causes an exception. throw new UndefinedDatabaseException(databaseName); } } if (queryContext.getCurrentDatabase().equals(databaseName)) { throw new CannotDropCurrentDatabaseException(); } catalog.dropDatabase(databaseName); }
@Override public void dropDatabase(String databaseName) throws UndefinedDatabaseException { HiveCatalogStoreClientPool.HiveCatalogStoreClient client = null; try { client = clientPool.getClient(); client.getHiveClient().dropDatabase(databaseName); } catch (NoSuchObjectException e) { throw new UndefinedDatabaseException(databaseName); } catch (Throwable t) { throw new TajoInternalError(t); } finally { if (client != null) { client.release(); } } }
@Override public List<CatalogProtos.PartitionDescProto> getPartitionsOfTable(String databaseName, String tableName) throws UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionMethodException { List<PartitionDescProto> list = null; try { if (!existDatabase(databaseName)) { throw new UndefinedDatabaseException(tableName); } if (!existTable(databaseName, tableName)) { throw new UndefinedTableException(tableName); } if (!existPartitionMethod(databaseName, tableName)) { throw new UndefinedPartitionMethodException(tableName); } list = getPartitionsFromHiveMetaStore(databaseName, tableName, ""); } catch (Exception se) { throw new TajoInternalError(se); } return list; }
@Override public CreateSessionResponse createSession(RpcController controller, CreateSessionRequest request) throws ServiceException { try { // create a new session with base database name. If no database name is give, we use default database. String databaseName = request.hasBaseDatabaseName() ? request.getBaseDatabaseName() : DEFAULT_DATABASE_NAME; if (!context.getCatalog().existDatabase(databaseName)) { LOG.info("Session creation is canceled due to absent base database \"" + databaseName + "\"."); throw new UndefinedDatabaseException(databaseName); } String sessionId = context.getSessionManager().createSession(request.getUsername(), databaseName); CreateSessionResponse.Builder builder = CreateSessionResponse.newBuilder(); builder.setState(OK); builder.setSessionId(TajoIdProtos.SessionIdProto.newBuilder().setId(sessionId).build()); builder.setSessionVars(ProtoUtil.convertFromMap(context.getSessionManager().getAllVariables(sessionId))); return builder.build(); } catch (Throwable t) { printStackTraceIfError(LOG, t); CreateSessionResponse.Builder builder = CreateSessionResponse.newBuilder(); builder.setState(returnError(t)); return builder.build(); } }
@Override public CreateSessionResponse createSession(RpcController controller, CreateSessionRequest request) throws ServiceException { try { // create a new session with base database name. If no database name is give, we use default database. String databaseName = request.hasBaseDatabaseName() ? request.getBaseDatabaseName() : DEFAULT_DATABASE_NAME; if (!context.getCatalog().existDatabase(databaseName)) { LOG.info("Session creation is canceled due to absent base database \"" + databaseName + "\"."); throw new UndefinedDatabaseException(databaseName); } String sessionId = context.getSessionManager().createSession(request.getUsername(), databaseName); CreateSessionResponse.Builder builder = CreateSessionResponse.newBuilder(); builder.setState(OK); builder.setSessionId(TajoIdProtos.SessionIdProto.newBuilder().setId(sessionId).build()); builder.setSessionVars(ProtoUtil.convertFromMap(context.getSessionManager().getAllVariables(sessionId))); return builder.build(); } catch (Throwable t) { printStackTraceIfError(LOG, t); CreateSessionResponse.Builder builder = CreateSessionResponse.newBuilder(); builder.setState(returnError(t)); return builder.build(); } }
@Override public List<PartitionDescProto> getPartitionsByAlgebra(PartitionsByAlgebraProto request) throws UndefinedDatabaseException, UndefinedTableException, UndefinedPartitionMethodException, UnsupportedException { List<PartitionDescProto> list = null; try { String databaseName = request.getDatabaseName(); String tableName = request.getTableName(); if (!existDatabase(databaseName)) { throw new UndefinedDatabaseException(tableName); } if (!existTable(databaseName, tableName)) { throw new UndefinedTableException(tableName); } if (!existPartitionMethod(databaseName, tableName)) { throw new UndefinedPartitionMethodException(tableName); } TableDescProto tableDesc = getTable(databaseName, tableName); String filter = getFilter(databaseName, tableName, tableDesc.getPartition().getExpressionSchema().getFieldsList() , request.getAlgebra()); list = getPartitionsFromHiveMetaStore(databaseName, tableName, filter); } catch (UnsupportedException ue) { throw ue; } catch (Exception se) { throw new TajoInternalError(se); } return list; }