Skip to content

Commit ad757d2

Browse files
authored
[spark] support 'SHOW VIEWS FROM' syntax (#6873)
1 parent 4c31fbb commit ad757d2

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

paimon-spark/paimon-spark-3.2/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.apache.paimon.spark.catalyst.plans.logical.{CreatePaimonView, DropPai
2323

2424
import org.apache.spark.sql.SparkSession
2525
import org.apache.spark.sql.catalyst.analysis.{CTESubstitution, ResolvedNamespace, UnresolvedView}
26+
import org.apache.spark.sql.catalyst.analysis.SimpleAnalyzer.ResolveNamespace
2627
import org.apache.spark.sql.catalyst.plans.logical._
2728
import org.apache.spark.sql.catalyst.rules.Rule
2829
import org.apache.spark.sql.connector.catalog.{CatalogManager, LookupCatalog}
@@ -60,11 +61,13 @@ case class RewritePaimonViewCommands(spark: SparkSession)
6061
case DropView(ResolvedIdent(resolved), ifExists: Boolean) =>
6162
DropPaimonView(resolved, ifExists)
6263

63-
case ShowViews(_, pattern, output) if catalogManager.currentCatalog.isInstanceOf[SupportView] =>
64-
ShowPaimonViews(
65-
ResolvedNamespace(catalogManager.currentCatalog, catalogManager.currentNamespace),
66-
pattern,
67-
output)
64+
case ShowViews(namespace, pattern, output)
65+
if catalogManager.currentCatalog.isInstanceOf[SupportView] =>
66+
val resolvedNamespace = ResolveNamespace(catalogManager)(namespace).transform {
67+
case r: ResolvedNamespace if r.namespace.isEmpty =>
68+
r.copy(namespace = catalogManager.currentNamespace)
69+
}
70+
ShowPaimonViews(resolvedNamespace, pattern, output)
6871
}
6972

7073
private def isTempView(nameParts: Seq[String]): Boolean = {

paimon-spark/paimon-spark-3.3/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.apache.paimon.spark.catalyst.plans.logical.{CreatePaimonView, DropPai
2323

2424
import org.apache.spark.sql.SparkSession
2525
import org.apache.spark.sql.catalyst.analysis.{CTESubstitution, ResolvedNamespace, UnresolvedDBObjectName, UnresolvedView}
26+
import org.apache.spark.sql.catalyst.analysis.SimpleAnalyzer.ResolveNamespace
2627
import org.apache.spark.sql.catalyst.plans.logical._
2728
import org.apache.spark.sql.catalyst.rules.Rule
2829
import org.apache.spark.sql.connector.catalog.{CatalogManager, LookupCatalog}
@@ -59,11 +60,13 @@ case class RewritePaimonViewCommands(spark: SparkSession)
5960
case DropView(ResolvedIdent(resolved), ifExists: Boolean) =>
6061
DropPaimonView(resolved, ifExists)
6162

62-
case ShowViews(_, pattern, output) if catalogManager.currentCatalog.isInstanceOf[SupportView] =>
63-
ShowPaimonViews(
64-
ResolvedNamespace(catalogManager.currentCatalog, catalogManager.currentNamespace),
65-
pattern,
66-
output)
63+
case ShowViews(namespace, pattern, output)
64+
if catalogManager.currentCatalog.isInstanceOf[SupportView] =>
65+
val resolvedNamespace = ResolveNamespace(catalogManager)(namespace).transform {
66+
case r: ResolvedNamespace if r.namespace.isEmpty =>
67+
r.copy(namespace = catalogManager.currentNamespace)
68+
}
69+
ShowPaimonViews(resolvedNamespace, pattern, output)
6770
}
6871

6972
private def isTempView(nameParts: Seq[String]): Boolean = {

paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.apache.paimon.spark.catalog.SupportView
2222
import org.apache.paimon.spark.catalyst.plans.logical.{CreatePaimonView, DropPaimonView, ResolvedIdentifier, ShowPaimonViews}
2323

2424
import org.apache.spark.sql.SparkSession
25-
import org.apache.spark.sql.catalyst.analysis.{CTESubstitution, ResolvedNamespace, UnresolvedIdentifier}
25+
import org.apache.spark.sql.catalyst.analysis.{CTESubstitution, ResolveCatalogs, ResolvedNamespace, UnresolvedIdentifier}
2626
import org.apache.spark.sql.catalyst.plans.logical._
2727
import org.apache.spark.sql.catalyst.rules.Rule
2828
import org.apache.spark.sql.connector.catalog.{CatalogManager, LookupCatalog}
@@ -59,11 +59,13 @@ case class RewritePaimonViewCommands(spark: SparkSession)
5959
case DropView(ResolvedIdent(resolved), ifExists: Boolean) =>
6060
DropPaimonView(resolved, ifExists)
6161

62-
case ShowViews(_, pattern, output) if catalogManager.currentCatalog.isInstanceOf[SupportView] =>
63-
ShowPaimonViews(
64-
ResolvedNamespace(catalogManager.currentCatalog, catalogManager.currentNamespace),
65-
pattern,
66-
output)
62+
case ShowViews(namespace, pattern, output)
63+
if catalogManager.currentCatalog.isInstanceOf[SupportView] =>
64+
val resolvedNamespace = new ResolveCatalogs(catalogManager)(namespace).transform {
65+
case r: ResolvedNamespace if r.namespace.isEmpty =>
66+
r.copy(namespace = catalogManager.currentNamespace)
67+
}
68+
ShowPaimonViews(resolvedNamespace, pattern, output)
6769
}
6870

6971
private def isTempView(nameParts: Seq[String]): Boolean = {

paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/PaimonViewTestBase.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ abstract class PaimonViewTestBase extends PaimonHiveTestBase {
8484
Row("test_db", "va", false),
8585
Row("test_db", "vab", false),
8686
Row("test_db", "vc", false)))
87+
88+
// show views from database
89+
sql(s"USE $hiveDbName")
90+
checkAnswer(
91+
sql("SHOW VIEWS FROM test_db"),
92+
Seq(
93+
Row("test_db", "va", false),
94+
Row("test_db", "vab", false),
95+
Row("test_db", "vc", false)))
96+
sql("USE test_db")
97+
8798
checkAnswer(
8899
sql("SHOW VIEWS LIKE 'va*'"),
89100
Seq(Row("test_db", "va", false), Row("test_db", "vab", false)))

0 commit comments

Comments
 (0)