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/24 20:33:45 UTC

[GitHub] [spark] amaliujia opened a new pull request, #36983: [SPARK-39583] Make RefreshTable be compatible with 3 layer namespace

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

   <!--
   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.
   -->
   
   Make RefreshTable be compatible with 3 layer namespace
   
   ### 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.
   -->
   
   This is a part of the effort to make Catalog API support 3l namespace
   
   ### 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. The API will support 3l namespace but maintain backwards compatibility
   
   ### 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.
   -->
   
   UT


-- 
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] cloud-fan closed pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace
URL: https://github.com/apache/spark/pull/36983


-- 
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] cloud-fan commented on pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #36983:
URL: https://github.com/apache/spark/pull/36983#issuecomment-1171270353

   thanks, merging 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] amaliujia commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala:
##########
@@ -749,4 +750,25 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf
     assert(spark.catalog.currentCatalog().equals("spark_catalog"))
     assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat"))
   }
+
+  test("SPARK-39583: Make RefreshTable be compatible with 3 layer namespace") {
+    withTempDir { dir =>
+      val tableName = "testcat.testdb.my_table"
+
+      sql("CREATE NAMESPACE testcat.testdb")
+      sql(s"""
+           | CREATE TABLE ${tableName}(col STRING) USING TEXT
+           | LOCATION '${dir.getAbsolutePath}'
+           |""".stripMargin)
+      sql(s"""INSERT INTO ${tableName} SELECT 'abc'""".stripMargin)
+      spark.catalog.cacheTable(tableName)
+      assert(spark.table(tableName).collect().length == 1)
+
+      FileUtils.deleteDirectory(dir)

Review Comment:
   It is wired that this dir is empty. I expected that after the `INSERT INTO`, Spark will create data file under the text table 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


[GitHub] [spark] AmplabJenkins commented on pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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

   Can one of the admins verify this patch?


-- 
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] cloud-fan commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36983:
URL: https://github.com/apache/spark/pull/36983#discussion_r906997943


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -647,15 +647,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * @since 2.0.0
    */
   override def refreshTable(tableName: String): Unit = {
-    val tableIdent = sparkSession.sessionState.sqlParser.parseTableIdentifier(tableName)
-    val relation = sparkSession.table(tableIdent).queryExecution.analyzed
+    val relation = sparkSession.table(tableName).queryExecution.analyzed
 
     relation.refresh()
 
+    val ident = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName)
     // Temporary and global temporary views are not supposed to be put into the relation cache
     // since they are tracked separately.
-    if (!sessionCatalog.isTempView(tableIdent)) {
-      sessionCatalog.invalidateCachedTable(tableIdent)
+    if (!sessionCatalog.isTempView(ident)) {
+      sessionCatalog.invalidateCachedTable(makeTableIdentifier(ident))

Review Comment:
   the idea LGTM, to fully support refresh table in any catalog.



-- 
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] amaliujia commented on pull request #36983: [SPARK-39583] Make RefreshTable be compatible with 3 layer namespace

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

   R: @cloud-fan 


-- 
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] amaliujia commented on pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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

   R: @cloud-fan 
   
   PR updated. 
   
   The documentation/license check is failing due to a R's issue. I think that is not related to this 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] cloud-fan commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36983:
URL: https://github.com/apache/spark/pull/36983#discussion_r906998878


##########
sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala:
##########
@@ -749,4 +749,22 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf
     assert(spark.catalog.currentCatalog().equals("spark_catalog"))
     assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat"))
   }
+
+  test("SPARK-39583: Make RefreshTable be compatible with 3 layer namespace") {
+    val catalogName = "testcat"
+    val dbName = "default"
+    val tableName = "my_table"
+    val tableSchema = new StructType().add("i", "int")
+    val description = "this is a test table"
+    val fullTableName = "testcat.default.my_table"
+
+    createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema,
+      Map.empty[String, String], description)
+    spark.catalog.refreshTable(fullTableName)
+    assert(!spark.catalog.isCached(fullTableName))
+
+    spark.catalog.cacheTable(fullTableName)
+    spark.catalog.refreshTable(fullTableName)
+    assert(spark.catalog.isCached(fullTableName))

Review Comment:
   We can use `spark.table(...).collect` to fetch the data. If we add/remove files, we can simply check the number of rows.



-- 
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] cloud-fan commented on pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #36983:
URL: https://github.com/apache/spark/pull/36983#issuecomment-1170238800

   can you fix the failed tests?
   ```
   [error] Failed tests:
   [error] 	org.apache.spark.sql.hive.execution.command.AlterTableRenamePartitionSuite
   [error] 	org.apache.spark.sql.hive.execution.command.AlterTableDropPartitionSuite
   [error] 	org.apache.spark.sql.hive.execution.command.AlterTableAddPartitionSuite
   ```


-- 
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] amaliujia commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala:
##########
@@ -749,4 +750,25 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf
     assert(spark.catalog.currentCatalog().equals("spark_catalog"))
     assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat"))
   }
+
+  test("SPARK-39583: Make RefreshTable be compatible with 3 layer namespace") {
+    withTempDir { dir =>
+      val tableName = "testcat.testdb.my_table"
+
+      sql("CREATE NAMESPACE testcat.testdb")
+      sql(s"""
+           | CREATE TABLE ${tableName}(col STRING) USING TEXT
+           | LOCATION '${dir.getAbsolutePath}'
+           |""".stripMargin)
+      sql(s"""INSERT INTO ${tableName} SELECT 'abc'""".stripMargin)
+      spark.catalog.cacheTable(tableName)
+      assert(spark.table(tableName).collect().length == 1)
+
+      FileUtils.deleteDirectory(dir)

Review Comment:
   As of the result, the last assert `assert(spark.table(tableName).collect().length == 0)` cannot pass: it is still length = 1 meaning the data is not deleted.



-- 
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] cloud-fan commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36983:
URL: https://github.com/apache/spark/pull/36983#discussion_r906998878


##########
sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala:
##########
@@ -749,4 +749,22 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf
     assert(spark.catalog.currentCatalog().equals("spark_catalog"))
     assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat"))
   }
+
+  test("SPARK-39583: Make RefreshTable be compatible with 3 layer namespace") {
+    val catalogName = "testcat"
+    val dbName = "default"
+    val tableName = "my_table"
+    val tableSchema = new StructType().add("i", "int")
+    val description = "this is a test table"
+    val fullTableName = "testcat.default.my_table"
+
+    createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema,
+      Map.empty[String, String], description)
+    spark.catalog.refreshTable(fullTableName)
+    assert(!spark.catalog.isCached(fullTableName))
+
+    spark.catalog.cacheTable(fullTableName)
+    spark.catalog.refreshTable(fullTableName)
+    assert(spark.catalog.isCached(fullTableName))

Review Comment:
   We can use `spark.table(...).collect` to fetch the data. If we add/remove files for file source tables, we can simply check the number of rows.



-- 
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] amaliujia commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala:
##########
@@ -749,4 +749,22 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf
     assert(spark.catalog.currentCatalog().equals("spark_catalog"))
     assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat"))
   }
+
+  test("SPARK-39583: Make RefreshTable be compatible with 3 layer namespace") {
+    val catalogName = "testcat"
+    val dbName = "default"
+    val tableName = "my_table"
+    val tableSchema = new StructType().add("i", "int")
+    val description = "this is a test table"
+    val fullTableName = "testcat.default.my_table"
+
+    createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema,
+      Map.empty[String, String], description)
+    spark.catalog.refreshTable(fullTableName)
+    assert(!spark.catalog.isCached(fullTableName))
+
+    spark.catalog.cacheTable(fullTableName)
+    spark.catalog.refreshTable(fullTableName)
+    assert(spark.catalog.isCached(fullTableName))

Review Comment:
   ```
       spark.range(10).write.saveAsTable(tableName)
       spark.catalog.cacheTable(tableName)
       assert(spark.table(tableName).collect().length == 10)
   
       spark.range(5).write.mode(SaveMode.Overwrite)
         .saveAsTable(tableName)
       assert(spark.table(tableName).collect().length == 10)
       spark.catalog.refresh(tableName)
       assert(spark.table(tableName).collect().length == 5)
   ```
   
   I am doing this but I found `spark.catalog.cacheTable(tableName)` does not take effect as I expect? I expect it will return length == 10 because of the cache. However the second `assert(spark.table(tableName).collect().length == 10)` will just fail to say the test contains 5 rows?



-- 
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] cloud-fan commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36983:
URL: https://github.com/apache/spark/pull/36983#discussion_r906997789


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -647,15 +647,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * @since 2.0.0
    */
   override def refreshTable(tableName: String): Unit = {
-    val tableIdent = sparkSession.sessionState.sqlParser.parseTableIdentifier(tableName)
-    val relation = sparkSession.table(tableIdent).queryExecution.analyzed
+    val relation = sparkSession.table(tableName).queryExecution.analyzed
 
     relation.refresh()
 
+    val ident = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName)
     // Temporary and global temporary views are not supposed to be put into the relation cache
     // since they are tracked separately.
-    if (!sessionCatalog.isTempView(tableIdent)) {
-      sessionCatalog.invalidateCachedTable(tableIdent)
+    if (!sessionCatalog.isTempView(ident)) {
+      sessionCatalog.invalidateCachedTable(makeTableIdentifier(ident))

Review Comment:
   we should use `executePlan(RefreshTable).assertCommandExecuted`



-- 
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] amaliujia commented on pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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

   @zhengruifeng this PR is merged so the Python side work can be started.


-- 
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] HyukjinKwon commented on pull request #36983: [SPARK-39583] Make RefreshTable be compatible with 3 layer namespace

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

   cc @zhengruifeng FYI


-- 
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] amaliujia commented on a diff in pull request #36983: [SPARK-39583] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala:
##########
@@ -749,4 +749,22 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf
     assert(spark.catalog.currentCatalog().equals("spark_catalog"))
     assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat"))
   }
+
+  test("SPARK-39583: Make RefreshTable be compatible with 3 layer namespace") {
+    val catalogName = "testcat"
+    val dbName = "default"
+    val tableName = "my_table"
+    val tableSchema = new StructType().add("i", "int")
+    val description = "this is a test table"
+    val fullTableName = "testcat.default.my_table"
+
+    createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema,
+      Map.empty[String, String], description)
+    spark.catalog.refreshTable(fullTableName)
+    assert(!spark.catalog.isCached(fullTableName))
+
+    spark.catalog.cacheTable(fullTableName)
+    spark.catalog.refreshTable(fullTableName)
+    assert(spark.catalog.isCached(fullTableName))

Review Comment:
   @cloud-fan what would be the best way to test `refreshTable`?
   
   
   I would imagine it is better to 
   1. cache the table and fetch the cached data into a local variable
   2. change the table
   3. refresh the table
   4. then compare current cached data from the result in 1.
   
   However I didn't find a good example for how to achieve above steps.
   
   



-- 
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] amaliujia commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -647,15 +647,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * @since 2.0.0
    */
   override def refreshTable(tableName: String): Unit = {
-    val tableIdent = sparkSession.sessionState.sqlParser.parseTableIdentifier(tableName)
-    val relation = sparkSession.table(tableIdent).queryExecution.analyzed
+    val relation = sparkSession.table(tableName).queryExecution.analyzed
 
     relation.refresh()
 
+    val ident = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName)
     // Temporary and global temporary views are not supposed to be put into the relation cache
     // since they are tracked separately.
-    if (!sessionCatalog.isTempView(tableIdent)) {
-      sessionCatalog.invalidateCachedTable(tableIdent)
+    if (!sessionCatalog.isTempView(ident)) {
+      sessionCatalog.invalidateCachedTable(makeTableIdentifier(ident))

Review Comment:
   What is a different of `executePlan(RefreshTable).analyzed` and `executePlan(RefreshTable).rdd`? Which one triggers  to have `RefreshTableExec` created and executed?



-- 
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] amaliujia commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -647,15 +647,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * @since 2.0.0
    */
   override def refreshTable(tableName: String): Unit = {
-    val tableIdent = sparkSession.sessionState.sqlParser.parseTableIdentifier(tableName)
-    val relation = sparkSession.table(tableIdent).queryExecution.analyzed
+    val relation = sparkSession.table(tableName).queryExecution.analyzed
 
     relation.refresh()
 
+    val ident = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName)
     // Temporary and global temporary views are not supposed to be put into the relation cache
     // since they are tracked separately.
-    if (!sessionCatalog.isTempView(tableIdent)) {
-      sessionCatalog.invalidateCachedTable(tableIdent)
+    if (!sessionCatalog.isTempView(ident)) {
+      sessionCatalog.invalidateCachedTable(makeTableIdentifier(ident))

Review Comment:
   cc @cloud-fan what do you think of this idea?



-- 
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] ulysses-you commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #36983:
URL: https://github.com/apache/spark/pull/36983#discussion_r906912293


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -647,15 +647,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
    * @since 2.0.0
    */
   override def refreshTable(tableName: String): Unit = {
-    val tableIdent = sparkSession.sessionState.sqlParser.parseTableIdentifier(tableName)
-    val relation = sparkSession.table(tableIdent).queryExecution.analyzed
+    val relation = sparkSession.table(tableName).queryExecution.analyzed
 
     relation.refresh()
 
+    val ident = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName)
     // Temporary and global temporary views are not supposed to be put into the relation cache
     // since they are tracked separately.
-    if (!sessionCatalog.isTempView(tableIdent)) {
-      sessionCatalog.invalidateCachedTable(tableIdent)
+    if (!sessionCatalog.isTempView(ident)) {
+      sessionCatalog.invalidateCachedTable(makeTableIdentifier(ident))

Review Comment:
   TableCatalog has its own `invalidateTable` so it seems we can not only do it with session catalog. An option may be: construct a `RefreshTable` and call `sessionState.executePlan(RefreshTable)`, so the analyzer can decide use which catalog, i.e. session catalog or other catalog.



-- 
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] cloud-fan commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36983:
URL: https://github.com/apache/spark/pull/36983#discussion_r909127133


##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -670,6 +671,18 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
     }
   }
 
+  private def makeTableIdentifier(ident: Seq[String]): TableIdentifier = {

Review Comment:
   can we use `MultipartIdentifierHelper.asTableIdentifier`?



-- 
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] amaliujia commented on a diff in pull request #36983: [SPARK-39583][SQL] Make RefreshTable be compatible with 3 layer namespace

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


##########
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/AlterTableAddPartitionSuite.scala:
##########
@@ -36,11 +36,11 @@ class AlterTableAddPartitionSuite
           sql(s"INSERT INTO $t PARTITION (part=0) SELECT 0")
           assert(!statsOn || getTableSize(t) > 0)
 
-          checkHiveClientCalls(expected = 17) {
+          checkHiveClientCalls(expected = 23) {

Review Comment:
   We need such change because we now call `executePlan` in `catalog.refreshTable`. This is similar to other changes.



-- 
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