You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/06/02 15:17:24 UTC

[GitHub] [spark] sunchao opened a new pull request, #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

sunchao opened a new pull request, #36750:
URL: https://github.com/apache/spark/pull/36750

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   Currently Spark throws exception when Hive client version is not 3.0/3.1. This removes the restriction so that the command works as long as the HMS version supports the alter database location feature (i.e., have HIVE-8472). 
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   Spark currently throws the following exception:
   ```
   AnalysisException: Hive 2.3.9 does not support altering database location
   ```
   
   This is not very accurate since it only considers the client version, while the feature support is on the Hive metastore side. For instance, the command should succeed if Spark with Hive 2.3.9 is talking to a remote HMS of version 3.1. On the other hand, the command won't be effective even if Spark uses Hive 3.1 (thus no exception) talking to a remote HMS of version 2.3.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   Yes, previously users using Spark with built-in Hive client won't be able to run `ALTER TABLE SET LOCATION` command against HMS 3.x. Now it works.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   Modified the existing test case.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
wangyum commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145534550

   Merged to master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
wangyum commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888507803


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala:
##########
@@ -355,14 +355,17 @@ private[hive] class HiveClientImpl(
   }
 
   override def alterDatabase(database: CatalogDatabase): Unit = withHiveState {
-    if (!getDatabase(database.name).locationUri.equals(database.locationUri)) {
-      // SPARK-29260: Enable supported versions once it support altering database location.
-      if (!(version.equals(hive.v3_0) || version.equals(hive.v3_1))) {
-        throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError(version.fullVersion)
-      }
-    }
+    val loc = getDatabase(database.name).locationUri
+    val changeLoc = !database.locationUri.equals(loc)
+
     val hiveDb = toHiveDatabase(database)
     shim.alterDatabase(client, database.name, hiveDb)
+
+    if (changeLoc && getDatabase(database.name).locationUri.equals(loc)) {
+      // Some Hive versions don't support changing database location, so we check here to see if
+      // the location is actually changed, and throw an error if not.
+      throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError()
+    }

Review Comment:
   Just silently ignore it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum closed pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
wangyum closed pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports
URL: https://github.com/apache/spark/pull/36750


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a diff in pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888506874


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala:
##########
@@ -355,14 +355,17 @@ private[hive] class HiveClientImpl(
   }
 
   override def alterDatabase(database: CatalogDatabase): Unit = withHiveState {
-    if (!getDatabase(database.name).locationUri.equals(database.locationUri)) {
-      // SPARK-29260: Enable supported versions once it support altering database location.
-      if (!(version.equals(hive.v3_0) || version.equals(hive.v3_1))) {
-        throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError(version.fullVersion)
-      }
-    }
+    val loc = getDatabase(database.name).locationUri
+    val changeLoc = !database.locationUri.equals(loc)
+
     val hiveDb = toHiveDatabase(database)
     shim.alterDatabase(client, database.name, hiveDb)
+
+    if (changeLoc && getDatabase(database.name).locationUri.equals(loc)) {
+      // Some Hive versions don't support changing database location, so we check here to see if
+      // the location is actually changed, and throw an error if not.
+      throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError()
+    }

Review Comment:
   So for the hive server which doesn't support it, there is no any exception in above `alterDatabase` but it just silently ignore it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
sunchao commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888477757


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   It's hard for Spark to give warning in this case since it doesn't know the Hive version used by the remote Hive metastore. It's possible in unit tests since both client and the metastore are of the same Hive version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
sunchao commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145425002

   The `ALTER DATABASE SET LOCATION` command will change the default location for new tables created afterwards. So in step 2) above, if table location is not explicitly specified, the new tables will be created under the new location defined in step 1), while the old tables remain unchanged.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
sunchao commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145087595

   cc @wangyum @viirya @dongjoon-hyun 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888478943


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   Can we do double-check the location inside this method after invoking `shim.alterDatabase`?
   
   https://github.com/apache/spark/blob/52e2717c2d1b6e1f449de5714b6e202074bac26f/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala#L357-L366



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145456039

   Lastly, could you make the PR description up-to-date? For example, the following?
   > This PR removes the check so that the command works as long as the Hive version used by the HMS...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
sunchao commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888490510


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   Updated the PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145110352

   Thank you for pinging me, @sunchao 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888477684


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   Sorry for misleading you, @sunchao . I was wondering this case which didn't throw exception. If there is no sign of failures (or no-op), the customer will be surprised at the next session.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888477684


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   Sorry for misleading you, @sunchao . I was wondering this case which didn't throw exception. If there is no sign of failures (or no-op), the customer will surprise at the next session.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888508050


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala:
##########
@@ -355,14 +355,17 @@ private[hive] class HiveClientImpl(
   }
 
   override def alterDatabase(database: CatalogDatabase): Unit = withHiveState {
-    if (!getDatabase(database.name).locationUri.equals(database.locationUri)) {
-      // SPARK-29260: Enable supported versions once it support altering database location.
-      if (!(version.equals(hive.v3_0) || version.equals(hive.v3_1))) {
-        throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError(version.fullVersion)
-      }
-    }
+    val loc = getDatabase(database.name).locationUri
+    val changeLoc = !database.locationUri.equals(loc)
+
     val hiveDb = toHiveDatabase(database)
     shim.alterDatabase(client, database.name, hiveDb)
+
+    if (changeLoc && getDatabase(database.name).locationUri.equals(loc)) {
+      // Some Hive versions don't support changing database location, so we check here to see if
+      // the location is actually changed, and throw an error if not.
+      throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError()
+    }

Review Comment:
   If some HMS forks raises exceptions, it will be enough because it will propagate to Spark users.
   So, this is only for silent HMS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
sunchao commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888482028


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   Good idea! Instead of warning, I'm thinking maybe we should throw exception when the location is not changed. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
sunchao commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145407388

   Fixed. @viirya pls take another look, thanks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sunchao commented on pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
sunchao commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145471603

   > Lastly, could you make the PR description up-to-date? For example, the following seems to need some changes.
   > 
   > > This PR removes the check so that the command works as long as the Hive version used by the HMS...
   
   Updated the PR description.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888508050


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala:
##########
@@ -355,14 +355,17 @@ private[hive] class HiveClientImpl(
   }
 
   override def alterDatabase(database: CatalogDatabase): Unit = withHiveState {
-    if (!getDatabase(database.name).locationUri.equals(database.locationUri)) {
-      // SPARK-29260: Enable supported versions once it support altering database location.
-      if (!(version.equals(hive.v3_0) || version.equals(hive.v3_1))) {
-        throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError(version.fullVersion)
-      }
-    }
+    val loc = getDatabase(database.name).locationUri
+    val changeLoc = !database.locationUri.equals(loc)
+
     val hiveDb = toHiveDatabase(database)
     shim.alterDatabase(client, database.name, hiveDb)
+
+    if (changeLoc && getDatabase(database.name).locationUri.equals(loc)) {
+      // Some Hive versions don't support changing database location, so we check here to see if
+      // the location is actually changed, and throw an error if not.
+      throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError()
+    }

Review Comment:
   If some HMS forks raise exceptions, it will be enough because it will propagate to Spark users.
   So, this is only for silent HMS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888476932


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   If there is no exception from HMS side in this case, we had better give a warning from Spark side here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888482892


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientSuite.scala:
##########
@@ -165,19 +165,19 @@ class HiveClientSuite(version: String, allVersions: Seq[String])
     assert(client.getDatabase("temporary").properties.contains("flag"))
 
     // test alter database location
+    val oldDatabasePath = database.locationUri.getPath
     val tempDatabasePath2 = Utils.createTempDir().toURI
-    // Hive support altering database location since HIVE-8472.
+    client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
+    val uriInCatalog = client.getDatabase("temporary").locationUri
+    assert("file" === uriInCatalog.getScheme)
+
     if (version == "3.0" || version == "3.1") {
-      client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      val uriInCatalog = client.getDatabase("temporary").locationUri
-      assert("file" === uriInCatalog.getScheme)
+      // Hive support altering database location since HIVE-8472
       assert(new Path(tempDatabasePath2.getPath).toUri.getPath === uriInCatalog.getPath,
         "Failed to alter database location")
     } else {
-      val e = intercept[AnalysisException] {
-        client.alterDatabase(database.copy(locationUri = tempDatabasePath2))
-      }
-      assert(e.getMessage.contains("does not support altering database location"))
+      // .. otherwise, the command should be non-effective against older versions of Hive
+      assert(oldDatabasePath === uriInCatalog.getPath, "Expected database location to be unchanged")

Review Comment:
   +1 for throwing exception!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a diff in pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888508050


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala:
##########
@@ -355,14 +355,17 @@ private[hive] class HiveClientImpl(
   }
 
   override def alterDatabase(database: CatalogDatabase): Unit = withHiveState {
-    if (!getDatabase(database.name).locationUri.equals(database.locationUri)) {
-      // SPARK-29260: Enable supported versions once it support altering database location.
-      if (!(version.equals(hive.v3_0) || version.equals(hive.v3_1))) {
-        throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError(version.fullVersion)
-      }
-    }
+    val loc = getDatabase(database.name).locationUri
+    val changeLoc = !database.locationUri.equals(loc)
+
     val hiveDb = toHiveDatabase(database)
     shim.alterDatabase(client, database.name, hiveDb)
+
+    if (changeLoc && getDatabase(database.name).locationUri.equals(loc)) {
+      // Some Hive versions don't support changing database location, so we check here to see if
+      // the location is actually changed, and throw an error if not.
+      throw QueryCompilationErrors.alterDatabaseLocationUnsupportedError()
+    }

Review Comment:
   If some HMS raises exceptions, it will be enough because it will propagate to Spark users.
   So, this is only for silent HMS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on pull request #36750: [SPARK-29260][SQL] Support alter database location for Hive client versions other than 3.0/3.1

Posted by GitBox <gi...@apache.org>.
viirya commented on PR #36750:
URL: https://github.com/apache/spark/pull/36750#issuecomment-1145188518

   `AlterNamespaceSetLocationSuite` seems failed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a diff in pull request #36750: [SPARK-29260][SQL] Support `ALTER DATABASE SET LOCATION` if HMS supports

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #36750:
URL: https://github.com/apache/spark/pull/36750#discussion_r888506364


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala:
##########
@@ -1628,8 +1628,8 @@ object QueryCompilationErrors extends QueryErrorsBase {
     new AnalysisException(s"$tableIdentifier should be converted to HadoopFsRelation.")
   }
 
-  def alterDatabaseLocationUnsupportedError(version: String): Throwable = {
-    new AnalysisException(s"Hive $version does not support altering database location")
+  def alterDatabaseLocationUnsupportedError(): Throwable = {
+    new AnalysisException(s"Hive metastore does not support altering database location")

Review Comment:
   nit:
   ```suggestion
       new AnalysisException("Hive metastore does not support altering database location")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org