diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java index ae622c8be5..8c764e2be5 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -1088,6 +1088,15 @@ public static void doAuthorization(HiveOperation op, BaseSemanticAnalyzer sem, S additionalInputs.add(new ReadEntity(e.getTable())); } } + // skipping the auth check for the "CREATE DATABASE" operation if database already exists + // we know that if the database already exists then "CREATE DATABASE" operation will fail. + if(op.equals(HiveOperation.CREATEDATABASE)){ + for (WriteEntity e : sem.getOutputs()) { + if(e.getType() == Entity.Type.DATABASE && db.databaseExists(e.getName().split(":")[1])){ + return; + } + } + } Set additionalOutputs = new HashSet(); for (WriteEntity e : sem.getOutputs()) {