本文整理了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
[英]Query metadata to see if a database with the given name already exists.
[中]查询元数据以查看具有给定名称的数据库是否已存在。
代码示例来源:origin: apache/hive
private void validateDatabase(String databaseName) throws SemanticException {
try {
if (!db.databaseExists(databaseName)) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
}
} catch (HiveException e) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
}
}
代码示例来源:origin: apache/drill
private void validateDatabase(String databaseName) throws SemanticException {
try {
if (!db.databaseExists(databaseName)) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
}
} catch (HiveException e) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
}
}
代码示例来源:origin: apache/hive
if (!db.databaseExists(dbName)) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
代码示例来源:origin: apache/drill
if (!db.databaseExists(dbName)) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
代码示例来源:origin: apache/hive
/**
* Switch to a different Database
* @param db
* @param switchDb
* @return Always returns 0
* @throws HiveException
*/
private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
throws HiveException {
String dbName = switchDb.getDatabaseName();
if (!db.databaseExists(dbName)) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
}
SessionState.get().setCurrentDatabase(dbName);
// set database specific parameters
Database database = db.getDatabase(dbName);
assert(database != null);
Map<String, String> dbParams = database.getParameters();
if (dbParams != null) {
for (HiveConf.ConfVars var: HiveConf.dbVars) {
String newValue = dbParams.get(var.varname);
if (newValue != null) {
LOG.info("Changing {} from {} to {}", var.varname, conf.getVar(var),
newValue);
conf.setVar(var, newValue);
}
}
}
return 0;
}
代码示例来源:origin: apache/drill
/**
* Switch to a different Database
* @param db
* @param switchDb
* @return Always returns 0
* @throws HiveException
*/
private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
throws HiveException {
String dbName = switchDb.getDatabaseName();
if (!db.databaseExists(dbName)) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
}
SessionState.get().setCurrentDatabase(dbName);
// set database specific parameters
Database database = db.getDatabase(dbName);
assert(database != null);
Map<String, String> dbParams = database.getParameters();
if (dbParams != null) {
for (HiveConf.ConfVars var: HiveConf.dbVars) {
String newValue = dbParams.get(var.varname);
if (newValue != null) {
LOG.info("Changing " + var.varname +
" from " + conf.getVar(var) + " to " + newValue);
conf.setVar(var, newValue);
}
}
}
return 0;
}
代码示例来源:origin: apache/hive
private Path getDefaultCtasLocation(final ParseContext pCtx) throws SemanticException {
try {
String protoName = null;
boolean isExternal = false;
if (pCtx.getQueryProperties().isCTAS()) {
protoName = pCtx.getCreateTable().getTableName();
isExternal = pCtx.getCreateTable().isExternal();
} else if (pCtx.getQueryProperties().isMaterializedView()) {
protoName = pCtx.getCreateViewDesc().getViewName();
}
String[] names = Utilities.getDbTableName(protoName);
if (!db.databaseExists(names[0])) {
throw new SemanticException("ERROR: The database " + names[0] + " does not exist.");
}
Warehouse wh = new Warehouse(conf);
return wh.getDefaultTablePath(db.getDatabase(names[0]), names[1], isExternal);
} catch (HiveException e) {
throw new SemanticException(e);
} catch (MetaException e) {
throw new SemanticException(e);
}
}
代码示例来源:origin: apache/drill
if (!db.databaseExists(names[0])) {
throw new SemanticException("ERROR: The database " + names[0]
+ " does not exist.");
代码示例来源:origin: com.facebook.presto.hive/hive-apache
static public String getDBName(Hive db, ASTNode ast) {
String dbName = null;
String fullyQualifiedName = getFullyQualifiedName(ast);
// if database.table or database.table.column or table.column
// first try the first component of the DOT separated name
if (ast.getChildCount() >= 2) {
dbName = fullyQualifiedName.substring(0,
fullyQualifiedName.indexOf('.') == -1 ?
fullyQualifiedName.length() :
fullyQualifiedName.indexOf('.'));
try {
// if the database name is not valid
// it is table.column
// return null as dbName
if (!db.databaseExists(dbName)) {
return null;
}
} catch (HiveException e) {
return null;
}
} else {
// in other cases, return null
// database is not validated if null
return null;
}
return dbName;
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
private void validateDatabase(String databaseName) throws SemanticException {
try {
if (!db.databaseExists(databaseName)) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
}
} catch (HiveException e) {
throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
}
}
代码示例来源:origin: org.apache.hadoop.hive/hive-exec
String dbName = showTbls.getDbName();
if (!db.databaseExists(dbName)) {
throw new HiveException("ERROR: The database " + dbName + " does not exist.");
代码示例来源:origin: apache/lens
@Override
public List<String> getAllNativeTableNames(LensSessionHandle sessionid,
String dbOption, String dbName) throws LensException {
try (SessionContext ignored = new SessionContext(sessionid)){
if (!StringUtils.isBlank(dbName)) {
if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(dbName)) {
throw new NotFoundException("Database " + dbName + " does not exist");
}
}
if (StringUtils.isBlank(dbName)
&& (StringUtils.isBlank(dbOption)
|| dbOption.equalsIgnoreCase("current"))) {
// use current db if no dbname/dboption is passed
dbName = getSession(sessionid).getCurrentDatabase();
}
List<String> tables;
if (!StringUtils.isBlank(dbName)) {
tables = getNativeTablesFromDB(sessionid, dbName, false);
} else {
log.info("Getting tables from all dbs");
tables = new ArrayList<>();
for (String db : getAllDatabases(sessionid)) {
tables.addAll(getNativeTablesFromDB(sessionid, db, true));
}
}
return tables;
} catch (HiveException e) {
throw new LensException(e);
}
}
代码示例来源:origin: org.apache.hadoop.hive/hive-exec
/**
* Switch to a different Database
* @param db
* @param switchDb
* @return Always returns 0
* @throws HiveException
*/
private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
throws HiveException {
String dbName = switchDb.getDatabaseName();
if (!db.databaseExists(dbName)) {
throw new HiveException("ERROR: The database " + dbName + " does not exist.");
}
db.setCurrentDatabase(dbName);
// set database specific parameters
Database database = db.getDatabase(dbName);
assert(database != null);
Map<String, String> dbParams = database.getParameters();
if (dbParams != null) {
for (HiveConf.ConfVars var: HiveConf.dbVars) {
String newValue = dbParams.get(var.varname);
if (newValue != null) {
LOG.info("Changing " + var.varname +
" from " + conf.getVar(var) + " to " + newValue);
conf.setVar(var, newValue);
}
}
}
return 0;
}
代码示例来源:origin: apache/lens
/**
* Change the current database used by the CubeMetastoreClient
*
* @param database current database to set
*/
@Override
public void setCurrentDatabase(LensSessionHandle sessionid, String database) throws LensException {
try (SessionContext ignored = new SessionContext(sessionid)) {
if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(database)) {
throw new NotFoundException("Database " + database + " does not exist");
}
log.info("Set database " + database);
getSession(sessionid).setCurrentDatabase(database);
} catch (HiveException e) {
throw new LensException(e);
}
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
String dbName = showTbls.getDbName();
if (!db.databaseExists(dbName)) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
代码示例来源:origin: apache/lens
if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(database)) {
closeSession(sessionid);
log.info("Closed session " + sessionid.getPublicId().toString() + " as db " + database + " does not exist");
代码示例来源:origin: com.facebook.presto.hive/hive-apache
/**
* Switch to a different Database
* @param db
* @param switchDb
* @return Always returns 0
* @throws HiveException
*/
private int switchDatabase(Hive db, SwitchDatabaseDesc switchDb)
throws HiveException {
String dbName = switchDb.getDatabaseName();
if (!db.databaseExists(dbName)) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
}
SessionState.get().setCurrentDatabase(dbName);
// set database specific parameters
Database database = db.getDatabase(dbName);
assert(database != null);
Map<String, String> dbParams = database.getParameters();
if (dbParams != null) {
for (HiveConf.ConfVars var: HiveConf.dbVars) {
String newValue = dbParams.get(var.varname);
if (newValue != null) {
LOG.info("Changing " + var.varname +
" from " + conf.getVar(var) + " to " + newValue);
conf.setVar(var, newValue);
}
}
}
return 0;
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
String[] names = Utilities.getDbTableName(
pCtx.getCreateTable().getTableName());
if (!db.databaseExists(names[0])) {
throw new SemanticException("ERROR: The database " + names[0]
+ " does not exist.");
内容来源于网络,如有侵权,请联系作者删除!