From a33c640a4afa97927658b14713f5518f6ecb0663 Mon Sep 17 00:00:00 2001 From: zouxxyy Date: Tue, 4 Nov 2025 21:11:29 +0800 Subject: [PATCH] 1 --- docs/content/spark/sql-ddl.md | 12 ++++++------ docs/content/spark/sql-functions.md | 4 ++-- .../extensions/RewritePaimonViewCommands.scala | 8 ++++++++ .../extensions/RewritePaimonViewCommands.scala | 8 ++++++++ .../extensions/RewritePaimonViewCommands.scala | 6 ++++++ .../paimon/spark/sql/PaimonViewTestBase.scala | 17 +++++++++++++++++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/docs/content/spark/sql-ddl.md b/docs/content/spark/sql-ddl.md index 654c391e71cc..1494216e3510 100644 --- a/docs/content/spark/sql-ddl.md +++ b/docs/content/spark/sql-ddl.md @@ -295,11 +295,11 @@ And in this case, views are supported when the `metastore` type is `hive` or `re CREATE VIEW constructs a virtual table that has no physical data. ```sql --- create a view. -CREATE [TEMPORARY] VIEW v1 AS SELECT * FROM t1; +-- create a view or a temporary view. (temporary view should not specify database name) +CREATE [TEMPORARY] VIEW .v1 AS SELECT * FROM t1; --- create a view, if a view of same name already exists, it will be replaced. -CREATE OR REPLACE [TEMPORARY] VIEW v1 AS SELECT * FROM t1; +-- create a view or a temporary view, if a view of same name already exists, it will be replaced. (temporary view should not specify database name) +CREATE OR REPLACE [TEMPORARY] VIEW .v1 AS SELECT * FROM t1; ``` ### Drop View @@ -307,8 +307,8 @@ CREATE OR REPLACE [TEMPORARY] VIEW v1 AS SELECT * FROM t1; DROP VIEW removes the metadata associated with a specified view from the catalog. ```sql --- drop a view -DROP VIEW v1; +-- drop a view or a temporary view. +DROP VIEW .v1; ``` ## Tag diff --git a/docs/content/spark/sql-functions.md b/docs/content/spark/sql-functions.md index 99f4dcb153ca..d17afc92ab13 100644 --- a/docs/content/spark/sql-functions.md +++ b/docs/content/spark/sql-functions.md @@ -100,8 +100,8 @@ CREATE [TEMPORARY] FUNCTION .simple_udf AS 'com.example.SimpleUdf' USING JAR '/tmp/SimpleUdf.jar' [, JAR '/tmp/SimpleUdfR.jar']; --- Create or Replace Function -CREATE OR REPLACE FUNCTION .simple_udf +-- Create or Replace Temporary Function (Temporary function should not specify database name) +CREATE OR REPLACE [TEMPORARY] FUNCTION .simple_udf AS 'com.example.SimpleUdf' USING JAR '/tmp/SimpleUdf.jar'; diff --git a/paimon-spark/paimon-spark-3.2/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala b/paimon-spark/paimon-spark-3.2/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala index e759edd0c2c6..c8080ba7ade2 100644 --- a/paimon-spark/paimon-spark-3.2/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala +++ b/paimon-spark/paimon-spark-3.2/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala @@ -67,10 +67,18 @@ case class RewritePaimonViewCommands(spark: SparkSession) output) } + private def isTempView(nameParts: Seq[String]): Boolean = { + catalogManager.v1SessionCatalog.isTempView(nameParts) + } + private object ResolvedIdent { def unapply(unresolved: Any): Option[ResolvedIdentifier] = unresolved match { + case nameParts: Seq[String] if isTempView(nameParts) => + None case CatalogAndIdentifier(viewCatalog: SupportView, ident) => Some(ResolvedIdentifier(viewCatalog, ident)) + case UnresolvedView(ident, _, true, _) if isTempView(ident) => + None case UnresolvedView(CatalogAndIdentifier(viewCatalog: SupportView, ident), _, _, _) => Some(ResolvedIdentifier(viewCatalog, ident)) case _ => diff --git a/paimon-spark/paimon-spark-3.3/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala b/paimon-spark/paimon-spark-3.3/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala index 5d57cda2f34b..e914ef1d7601 100644 --- a/paimon-spark/paimon-spark-3.3/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala +++ b/paimon-spark/paimon-spark-3.3/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala @@ -66,10 +66,18 @@ case class RewritePaimonViewCommands(spark: SparkSession) output) } + private def isTempView(nameParts: Seq[String]): Boolean = { + catalogManager.v1SessionCatalog.isTempView(nameParts) + } + private object ResolvedIdent { def unapply(unresolved: Any): Option[ResolvedIdentifier] = unresolved match { + case UnresolvedDBObjectName(ident, _) if isTempView(ident) => + None case UnresolvedDBObjectName(CatalogAndIdentifier(viewCatalog: SupportView, ident), _) => Some(ResolvedIdentifier(viewCatalog, ident)) + case UnresolvedView(ident, _, true, _) if isTempView(ident) => + None case UnresolvedView(CatalogAndIdentifier(viewCatalog: SupportView, ident), _, _, _) => Some(ResolvedIdentifier(viewCatalog, ident)) case _ => diff --git a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala index f69e5d92038e..30b09a48e42b 100644 --- a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala +++ b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/RewritePaimonViewCommands.scala @@ -66,8 +66,14 @@ case class RewritePaimonViewCommands(spark: SparkSession) output) } + private def isTempView(nameParts: Seq[String]): Boolean = { + catalogManager.v1SessionCatalog.isTempView(nameParts) + } + private object ResolvedIdent { def unapply(unresolved: Any): Option[ResolvedIdentifier] = unresolved match { + case UnresolvedIdentifier(nameParts, true) if isTempView(nameParts) => + None case UnresolvedIdentifier(CatalogAndIdentifier(viewCatalog: SupportView, ident), _) => Some(ResolvedIdentifier(viewCatalog, ident)) case _ => diff --git a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/PaimonViewTestBase.scala b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/PaimonViewTestBase.scala index 6d59d96cf4c8..fa58b99aee48 100644 --- a/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/PaimonViewTestBase.scala +++ b/paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sql/PaimonViewTestBase.scala @@ -176,4 +176,21 @@ abstract class PaimonViewTestBase extends PaimonHiveTestBase { } } } + + test("Paimon View: drop temp view") { + sql(s"USE $paimonHiveCatalogName") + withDatabase("test_db") { + sql("CREATE DATABASE test_db") + sql("USE test_db") + withTable("t") { + withTempView("v1") { + sql("CREATE TABLE t (id INT) USING paimon") + sql("INSERT INTO t VALUES (1), (2)") + + sql("CREATE TEMPORARY VIEW v1 AS SELECT * FROM t") + sql("DROP VIEW v1") + } + } + } + } }