org.apache.hadoop.hive.ql.metadata.Hive.databaseExists()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.apache.hadoop.hive.ql.metadata.Hive.databaseExists()方法的一些代码示例,展示了Hive.databaseExists()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hive.databaseExists()方法的具体详情如下:
包路径:org.apache.hadoop.hive.ql.metadata.Hive
类名称:Hive
方法名:databaseExists

Hive.databaseExists介绍

[英]Query metadata to see if a database with the given name already exists.
[中]查询元数据以查看具有给定名称的数据库是否已存在。

代码示例

代码示例来源:origin: apache/hive

  1. private void validateDatabase(String databaseName) throws SemanticException {
  2. try {
  3. if (!db.databaseExists(databaseName)) {
  4. throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
  5. }
  6. } catch (HiveException e) {
  7. throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
  8. }
  9. }

代码示例来源:origin: apache/drill

  1. private void validateDatabase(String databaseName) throws SemanticException {
  2. try {
  3. if (!db.databaseExists(databaseName)) {
  4. throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
  5. }
  6. } catch (HiveException e) {
  7. throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
  8. }
  9. }

代码示例来源:origin: apache/hive

  1. if (!db.databaseExists(dbName)) {
  2. throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);

代码示例来源:origin: apache/drill

  1. if (!db.databaseExists(dbName)) {
  2. throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);

代码示例来源:origin: apache/hive

  1. /**
  2. * Switch to a different Database
  3. * @param db
  4. * @param switchDb
  5. * @return Always returns 0
  6. * @throws HiveException
  7. */
  8. private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
  9. throws HiveException {
  10. String dbName = switchDb.getDatabaseName();
  11. if (!db.databaseExists(dbName)) {
  12. throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
  13. }
  14. SessionState.get().setCurrentDatabase(dbName);
  15. // set database specific parameters
  16. Database database = db.getDatabase(dbName);
  17. assert(database != null);
  18. Map<String, String> dbParams = database.getParameters();
  19. if (dbParams != null) {
  20. for (HiveConf.ConfVars var: HiveConf.dbVars) {
  21. String newValue = dbParams.get(var.varname);
  22. if (newValue != null) {
  23. LOG.info("Changing {} from {} to {}", var.varname, conf.getVar(var),
  24. newValue);
  25. conf.setVar(var, newValue);
  26. }
  27. }
  28. }
  29. return 0;
  30. }

代码示例来源:origin: apache/drill

  1. /**
  2. * Switch to a different Database
  3. * @param db
  4. * @param switchDb
  5. * @return Always returns 0
  6. * @throws HiveException
  7. */
  8. private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
  9. throws HiveException {
  10. String dbName = switchDb.getDatabaseName();
  11. if (!db.databaseExists(dbName)) {
  12. throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
  13. }
  14. SessionState.get().setCurrentDatabase(dbName);
  15. // set database specific parameters
  16. Database database = db.getDatabase(dbName);
  17. assert(database != null);
  18. Map<String, String> dbParams = database.getParameters();
  19. if (dbParams != null) {
  20. for (HiveConf.ConfVars var: HiveConf.dbVars) {
  21. String newValue = dbParams.get(var.varname);
  22. if (newValue != null) {
  23. LOG.info("Changing " + var.varname +
  24. " from " + conf.getVar(var) + " to " + newValue);
  25. conf.setVar(var, newValue);
  26. }
  27. }
  28. }
  29. return 0;
  30. }

代码示例来源:origin: apache/hive

  1. private Path getDefaultCtasLocation(final ParseContext pCtx) throws SemanticException {
  2. try {
  3. String protoName = null;
  4. boolean isExternal = false;
  5. if (pCtx.getQueryProperties().isCTAS()) {
  6. protoName = pCtx.getCreateTable().getTableName();
  7. isExternal = pCtx.getCreateTable().isExternal();
  8. } else if (pCtx.getQueryProperties().isMaterializedView()) {
  9. protoName = pCtx.getCreateViewDesc().getViewName();
  10. }
  11. String[] names = Utilities.getDbTableName(protoName);
  12. if (!db.databaseExists(names[0])) {
  13. throw new SemanticException("ERROR: The database " + names[0] + " does not exist.");
  14. }
  15. Warehouse wh = new Warehouse(conf);
  16. return wh.getDefaultTablePath(db.getDatabase(names[0]), names[1], isExternal);
  17. } catch (HiveException e) {
  18. throw new SemanticException(e);
  19. } catch (MetaException e) {
  20. throw new SemanticException(e);
  21. }
  22. }

代码示例来源:origin: apache/drill

  1. if (!db.databaseExists(names[0])) {
  2. throw new SemanticException("ERROR: The database " + names[0]
  3. + " does not exist.");

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. static public String getDBName(Hive db, ASTNode ast) {
  2. String dbName = null;
  3. String fullyQualifiedName = getFullyQualifiedName(ast);
  4. // if database.table or database.table.column or table.column
  5. // first try the first component of the DOT separated name
  6. if (ast.getChildCount() >= 2) {
  7. dbName = fullyQualifiedName.substring(0,
  8. fullyQualifiedName.indexOf('.') == -1 ?
  9. fullyQualifiedName.length() :
  10. fullyQualifiedName.indexOf('.'));
  11. try {
  12. // if the database name is not valid
  13. // it is table.column
  14. // return null as dbName
  15. if (!db.databaseExists(dbName)) {
  16. return null;
  17. }
  18. } catch (HiveException e) {
  19. return null;
  20. }
  21. } else {
  22. // in other cases, return null
  23. // database is not validated if null
  24. return null;
  25. }
  26. return dbName;
  27. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. private void validateDatabase(String databaseName) throws SemanticException {
  2. try {
  3. if (!db.databaseExists(databaseName)) {
  4. throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
  5. }
  6. } catch (HiveException e) {
  7. throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
  8. }
  9. }

代码示例来源:origin: org.apache.hadoop.hive/hive-exec

  1. String dbName = showTbls.getDbName();
  2. if (!db.databaseExists(dbName)) {
  3. throw new HiveException("ERROR: The database " + dbName + " does not exist.");

代码示例来源:origin: apache/lens

  1. @Override
  2. public List<String> getAllNativeTableNames(LensSessionHandle sessionid,
  3. String dbOption, String dbName) throws LensException {
  4. try (SessionContext ignored = new SessionContext(sessionid)){
  5. if (!StringUtils.isBlank(dbName)) {
  6. if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(dbName)) {
  7. throw new NotFoundException("Database " + dbName + " does not exist");
  8. }
  9. }
  10. if (StringUtils.isBlank(dbName)
  11. && (StringUtils.isBlank(dbOption)
  12. || dbOption.equalsIgnoreCase("current"))) {
  13. // use current db if no dbname/dboption is passed
  14. dbName = getSession(sessionid).getCurrentDatabase();
  15. }
  16. List<String> tables;
  17. if (!StringUtils.isBlank(dbName)) {
  18. tables = getNativeTablesFromDB(sessionid, dbName, false);
  19. } else {
  20. log.info("Getting tables from all dbs");
  21. tables = new ArrayList<>();
  22. for (String db : getAllDatabases(sessionid)) {
  23. tables.addAll(getNativeTablesFromDB(sessionid, db, true));
  24. }
  25. }
  26. return tables;
  27. } catch (HiveException e) {
  28. throw new LensException(e);
  29. }
  30. }

代码示例来源:origin: org.apache.hadoop.hive/hive-exec

  1. /**
  2. * Switch to a different Database
  3. * @param db
  4. * @param switchDb
  5. * @return Always returns 0
  6. * @throws HiveException
  7. */
  8. private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
  9. throws HiveException {
  10. String dbName = switchDb.getDatabaseName();
  11. if (!db.databaseExists(dbName)) {
  12. throw new HiveException("ERROR: The database " + dbName + " does not exist.");
  13. }
  14. db.setCurrentDatabase(dbName);
  15. // set database specific parameters
  16. Database database = db.getDatabase(dbName);
  17. assert(database != null);
  18. Map<String, String> dbParams = database.getParameters();
  19. if (dbParams != null) {
  20. for (HiveConf.ConfVars var: HiveConf.dbVars) {
  21. String newValue = dbParams.get(var.varname);
  22. if (newValue != null) {
  23. LOG.info("Changing " + var.varname +
  24. " from " + conf.getVar(var) + " to " + newValue);
  25. conf.setVar(var, newValue);
  26. }
  27. }
  28. }
  29. return 0;
  30. }

代码示例来源:origin: apache/lens

  1. /**
  2. * Change the current database used by the CubeMetastoreClient
  3. *
  4. * @param database current database to set
  5. */
  6. @Override
  7. public void setCurrentDatabase(LensSessionHandle sessionid, String database) throws LensException {
  8. try (SessionContext ignored = new SessionContext(sessionid)) {
  9. if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(database)) {
  10. throw new NotFoundException("Database " + database + " does not exist");
  11. }
  12. log.info("Set database " + database);
  13. getSession(sessionid).setCurrentDatabase(database);
  14. } catch (HiveException e) {
  15. throw new LensException(e);
  16. }
  17. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. String dbName = showTbls.getDbName();
  2. if (!db.databaseExists(dbName)) {
  3. throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);

代码示例来源:origin: apache/lens

  1. if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(database)) {
  2. closeSession(sessionid);
  3. log.info("Closed session " + sessionid.getPublicId().toString() + " as db " + database + " does not exist");

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. /**
  2. * Switch to a different Database
  3. * @param db
  4. * @param switchDb
  5. * @return Always returns 0
  6. * @throws HiveException
  7. */
  8. private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
  9. throws HiveException {
  10. String dbName = switchDb.getDatabaseName();
  11. if (!db.databaseExists(dbName)) {
  12. throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
  13. }
  14. SessionState.get().setCurrentDatabase(dbName);
  15. // set database specific parameters
  16. Database database = db.getDatabase(dbName);
  17. assert(database != null);
  18. Map<String, String> dbParams = database.getParameters();
  19. if (dbParams != null) {
  20. for (HiveConf.ConfVars var: HiveConf.dbVars) {
  21. String newValue = dbParams.get(var.varname);
  22. if (newValue != null) {
  23. LOG.info("Changing " + var.varname +
  24. " from " + conf.getVar(var) + " to " + newValue);
  25. conf.setVar(var, newValue);
  26. }
  27. }
  28. }
  29. return 0;
  30. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. String[] names = Utilities.getDbTableName(
  2. pCtx.getCreateTable().getTableName());
  3. if (!db.databaseExists(names[0])) {
  4. throw new SemanticException("ERROR: The database " + names[0]
  5. + " does not exist.");

相关文章

Hive类方法