Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIVE-20001: With doas set to true, running select query as hrt_qa use… #387

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -90,6 +90,7 @@ protected void authorizeDDLWork(HiveSemanticAnalyzerHookContext context,
if (createDb != null) {
Database db = new Database(createDb.getName(), createDb.getComment(),
createDb.getLocationUri(), createDb.getDatabaseProperties());
db.setExternalLocationUri(createDb.getLocationExternalUri());
authorize(db, Privilege.CREATE);
}
}
Expand Down
Expand Up @@ -34,6 +34,7 @@ public class HCatCreateDBDesc {

private String dbName;
private String locationUri;
private String externalLocationUri;
private String comment;
private Map<String, String> dbProperties;
private boolean ifNotExits = false;
Expand Down Expand Up @@ -74,6 +75,15 @@ public String getLocation() {
return this.locationUri;
}

/**
* Gets the external location.
*
* @return the external location
*/
public String getExternalLocation() {
return this.externalLocationUri;
}

/**
* Gets the database name.
*
Expand All @@ -93,6 +103,8 @@ public String toString() {
+ (dbName != null ? "dbName=" + dbName + ", " : "dbName=null")
+ (locationUri != null ? "location=" + locationUri + ", "
: "location=null")
+ (externalLocationUri != null ? "externalLocationUri=" + externalLocationUri + ", "
: "externalLocationUri=null")
+ (comment != null ? "comment=" + comment + ", " : "comment=null")
+ (dbProperties != null ? "dbProperties=" + dbProperties + ", "
: "dbProperties=null") + "ifNotExits=" + ifNotExits + "]";
Expand All @@ -112,6 +124,7 @@ Database toHiveDb() {
Database hiveDB = new Database();
hiveDB.setDescription(this.comment);
hiveDB.setLocationUri(this.locationUri);
hiveDB.setExternalLocationUri(this.externalLocationUri);
hiveDB.setName(this.dbName);
hiveDB.setParameters(this.dbProperties);
return hiveDB;
Expand All @@ -120,6 +133,7 @@ Database toHiveDb() {
public static class Builder {

private String innerLoc;
private String innerExternalLoc;
private String innerComment;
private Map<String, String> innerDBProps;
private String dbName;
Expand All @@ -140,6 +154,17 @@ public Builder location(String value) {
return this;
}

/**
* External location.
*
* @param value the external location of the database.
* @return the builder
*/
public Builder externalLocation(String value) {
this.innerExternalLoc = value;
return this;
}

/**
* Comment.
*
Expand Down Expand Up @@ -187,6 +212,7 @@ public HCatCreateDBDesc build() throws HCatException {
HCatCreateDBDesc desc = new HCatCreateDBDesc(this.dbName);
desc.comment = this.innerComment;
desc.locationUri = this.innerLoc;
desc.externalLocationUri = this.innerExternalLoc;
desc.dbProperties = this.innerDBProps;
desc.ifNotExits = this.ifNotExists;
return desc;
Expand Down
Expand Up @@ -34,25 +34,36 @@ public class HCatDatabase {

private String dbName;
private String dbLocation;
private String dbExternalLocation;
private String comment;
private Map<String, String> props;

HCatDatabase(Database db) {
this.dbName = db.getName();
this.props = db.getParameters();
this.dbLocation = db.getLocationUri();
this.dbExternalLocation = db.getExternalLocationUri();
this.comment = db.getDescription();
}

/**
* Gets the database name.
*
*public String getExternalLocation() {
* @return the database name
*/
public String getName() {
return dbName;
}

/**
* Gets the external dB location.
*
* @return the external dB location
*/
public String getExternalLocation() {
return dbExternalLocation;
}

/**
* Gets the dB location.
*
Expand Down Expand Up @@ -85,6 +96,7 @@ public String toString() {
return "HCatDatabase ["
+ (dbName != null ? "dbName=" + dbName + ", " : "dbName=null")
+ (dbLocation != null ? "dbLocation=" + dbLocation + ", " : "dbLocation=null")
+ (dbExternalLocation != null ? "dbExternalLocation=" + dbExternalLocation + ", " : "dbExternalLocation=null")
+ (comment != null ? "comment=" + comment + ", " : "comment=null")
+ (props != null ? "props=" + props : "props=null") + "]";
}
Expand Down
1 change: 1 addition & 0 deletions ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
Expand Up @@ -4824,6 +4824,7 @@ private int createDatabase(Hive db, CreateDatabaseDesc crtDb)
database.setName(crtDb.getName());
database.setDescription(crtDb.getComment());
database.setLocationUri(crtDb.getLocationUri());
database.setExternalLocationUri(crtDb.getLocationExternalUri());
database.setParameters(crtDb.getDatabaseProperties());
database.setOwnerName(SessionState.getUserFromAuthenticator());
database.setOwnerType(PrincipalType.USER);
Expand Down
10 changes: 10 additions & 0 deletions ql/src/java/org/apache/hadoop/hive/ql/plan/CreateDatabaseDesc.java
Expand Up @@ -34,6 +34,7 @@ public class CreateDatabaseDesc extends DDLDesc implements Serializable {

String databaseName;
String locationUri;
String locationExternalUri;
String comment;
boolean ifNotExists;
Map<String, String> dbProperties;
Expand Down Expand Up @@ -97,4 +98,13 @@ public String getLocationUri() {
public void setLocationUri(String locationUri) {
this.locationUri = locationUri;
}

@Explain(displayName="externalLocationUri")
public String getLocationExternalUri() {
return locationExternalUri;
}

public void setLocationExternalUri(String locationExternalUri) {
this.locationExternalUri = locationExternalUri;
}
}
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;

import javax.security.auth.login.LoginException;

Expand Down Expand Up @@ -138,7 +139,12 @@ public void authorize(Privilege[] readRequiredPriv, Privilege[] writeRequiredPri
@Override
public void authorize(Database db, Privilege[] readRequiredPriv, Privilege[] writeRequiredPriv)
throws HiveException, AuthorizationException {
Path path = getDbLocation(db);
Path path = getExternalDbLocation(db);

if (path == null) {
throw new AuthorizationException("Couldn't determine external directory for database "
+ db.getName() + ", which the authorization is based on");
}

// extract drop privileges
DropPrivilegeExtractor privExtractor = new DropPrivilegeExtractor(readRequiredPriv,
Expand Down Expand Up @@ -430,6 +436,25 @@ protected Path getDbLocation(Database db) throws HiveException {
}
}

private Path getExternalDbLocation(Database db) throws HiveException {
try {
initWh();
String location = db.getExternalLocationUri();
if (location == null) {
return wh.getDefaultExternalDatabasePath(db.getName());
} else {
Optional<Path> path = wh.getDatabaseExternalPath(db);
if (path.isPresent()) {
return wh.getDnsPath(path.get());
} else {
return null;
}
}
} catch (MetaException ex) {
throw hiveException(ex);
}
}

private HiveException hiveException(Exception e) {
return new HiveException(e);
}
Expand Down
4 changes: 4 additions & 0 deletions standalone-metastore/pom.xml
Expand Up @@ -45,6 +45,7 @@
<log4j.conf.dir>${project.basedir}/src/test/resources</log4j.conf.dir>
<test.tmp.dir>${project.build.directory}/tmp</test.tmp.dir>
<test.warehouse.dir>${project.build.directory}/warehouse</test.warehouse.dir>
<test.warehouse.external.dir>${project.build.directory}/external</test.warehouse.external.dir>
<test.warehouse.scheme>file://</test.warehouse.scheme>
<test.forkcount>1</test.forkcount>
<skipITests>true</skipITests>
Expand Down Expand Up @@ -580,8 +581,10 @@
<target>
<delete dir="${test.tmp.dir}" />
<delete dir="${test.warehouse.dir}" />
<delete dir="${test.warehouse.external.dir}" />
<mkdir dir="${test.tmp.dir}" />
<mkdir dir="${test.warehouse.dir}" />
<mkdir dir="${test.warehouse.external.dir}" />
</target>
</configuration>
</execution>
Expand Down Expand Up @@ -745,6 +748,7 @@
<metastore.schema.verification>false</metastore.schema.verification>
<test.tmp.dir>${test.tmp.dir}</test.tmp.dir>
<metastore.warehouse.dir>${test.warehouse.scheme}${test.warehouse.dir}</metastore.warehouse.dir>
<hive.metastore.warehouse.external.dir>${test.warehouse.scheme}${test.warehouse.external.dir}</hive.metastore.warehouse.external.dir>
</systemPropertyVariables>
<additionalClasspathElements>
<additionalClasspathElement>${log4j.conf.dir}</additionalClasspathElement>
Expand Down