-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31709][SQL] Proper base path for database/table location when it is a relative path #28527
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,12 +219,20 @@ class SessionCatalog( | |
| "you cannot create a database with this name.") | ||
| } | ||
| validateName(dbName) | ||
| val qualifiedPath = makeQualifiedPath(dbDefinition.locationUri) | ||
| externalCatalog.createDatabase( | ||
| dbDefinition.copy(name = dbName, locationUri = qualifiedPath), | ||
| dbDefinition.copy(name = dbName, locationUri = makeQualifiedDBPath(dbDefinition.locationUri)), | ||
| ignoreIfExists) | ||
| } | ||
|
|
||
| private def makeQualifiedDBPath(locationUri: URI): URI = { | ||
| if (locationUri.isAbsolute) { | ||
| locationUri | ||
| } else { | ||
| val fullPath = new Path(conf.warehousePath, CatalogUtils.URIToString(locationUri)) | ||
| makeQualifiedPath(fullPath.toUri) | ||
| } | ||
| } | ||
|
|
||
| def dropDatabase(db: String, ignoreIfNotExists: Boolean, cascade: Boolean): Unit = { | ||
| val dbName = formatDatabaseName(db) | ||
| if (dbName == DEFAULT_DATABASE) { | ||
|
|
@@ -241,7 +249,8 @@ class SessionCatalog( | |
| def alterDatabase(dbDefinition: CatalogDatabase): Unit = { | ||
| val dbName = formatDatabaseName(dbDefinition.name) | ||
| requireDbExists(dbName) | ||
| externalCatalog.alterDatabase(dbDefinition.copy(name = dbName)) | ||
| externalCatalog.alterDatabase(dbDefinition.copy( | ||
| name = dbName, locationUri = makeQualifiedDBPath(dbDefinition.locationUri))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update the location uri here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. |
||
| } | ||
|
|
||
| def getDatabaseMetadata(db: String): CatalogDatabase = { | ||
|
|
@@ -283,8 +292,7 @@ class SessionCatalog( | |
| * by users. | ||
| */ | ||
| def getDefaultDBPath(db: String): URI = { | ||
| val database = formatDatabaseName(db) | ||
| new Path(new Path(conf.warehousePath), database + ".db").toUri | ||
| CatalogUtils.stringToURI(formatDatabaseName(db) + ".db") | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
@@ -317,7 +325,7 @@ class SessionCatalog( | |
| && !tableDefinition.storage.locationUri.get.isAbsolute) { | ||
| // make the location of the table qualified. | ||
| val qualifiedTableLocation = | ||
| makeQualifiedPath(tableDefinition.storage.locationUri.get) | ||
| makeQualifiedTablePath(tableDefinition.storage.locationUri.get, db) | ||
| tableDefinition.copy( | ||
| storage = tableDefinition.storage.copy(locationUri = Some(qualifiedTableLocation)), | ||
| identifier = tableIdentifier) | ||
|
|
@@ -350,6 +358,16 @@ class SessionCatalog( | |
| } | ||
| } | ||
|
|
||
| private def makeQualifiedTablePath(locationUri: URI, database: String): URI = { | ||
| if (locationUri.isAbsolute) { | ||
| locationUri | ||
| } else { | ||
| val dbName = formatDatabaseName(database) | ||
| val dbLocation = makeQualifiedDBPath(getDatabaseMetadata(dbName).locationUri) | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit concerned about it as it adds an extra database lookup. Is it better to push this work to the underlying external catalog?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean that we are calling
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it seem make no difference even we put this into external catalogs, we have to call the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if we don't qualify the path here and leave it to hive metastore? Will it still be a relative path in the hive metastore?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, #17254
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok we did the same thing for partition. LGTM then |
||
| new Path(new Path(dbLocation), CatalogUtils.URIToString(locationUri)).toUri | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Alter the metadata of an existing metastore table identified by `tableDefinition`. | ||
| * | ||
|
|
@@ -369,7 +387,7 @@ class SessionCatalog( | |
| && !tableDefinition.storage.locationUri.get.isAbsolute) { | ||
| // make the location of the table qualified. | ||
| val qualifiedTableLocation = | ||
| makeQualifiedPath(tableDefinition.storage.locationUri.get) | ||
| makeQualifiedTablePath(tableDefinition.storage.locationUri.get, db) | ||
| tableDefinition.copy( | ||
| storage = tableDefinition.storage.copy(locationUri = Some(qualifiedTableLocation)), | ||
| identifier = tableIdentifier) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.