Skip to content

Commit 0bd8b99

Browse files
amanomercloud-fan
authored andcommitted
[SPARK-30093][SQL] Improve error message for creating view
### What changes were proposed in this pull request? Improved error message while creating views. ### Why are the changes needed? Error message should suggest user to use TEMPORARY keyword while creating permanent view referred by temporary view. apache#26317 (comment) ### Does this PR introduce any user-facing change? No ### How was this patch tested? Updated test case. Closes apache#26731 from amanomer/imp_err_msg. Authored-by: Aman Omer <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent ebd83a5 commit 0bd8b99

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ case class CreateViewCommand(
162162
if sparkSession.sessionState.catalog.isTemporaryTable(ident) =>
163163
// temporary views are only stored in the session catalog
164164
throw new AnalysisException(s"Not allowed to create a permanent view $name by " +
165-
s"referencing a temporary view $ident")
165+
s"referencing a temporary view $ident. " +
166+
"Please create a temp view instead by CREATE TEMP VIEW")
166167
case other if !other.resolved => other.expressions.flatMap(_.collect {
167168
// Traverse subquery plan for any unresolved relations.
168169
case e: SubqueryExpression => verify(e.plan)

sql/core/src/test/resources/sql-tests/results/postgreSQL/create_view.sql.out

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ CREATE VIEW v1_temp AS SELECT * FROM temp_table
267267
struct<>
268268
-- !query 27 output
269269
org.apache.spark.sql.AnalysisException
270-
Not allowed to create a permanent view `v1_temp` by referencing a temporary view `temp_table`;
270+
Not allowed to create a permanent view `v1_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
271271

272272

273273
-- !query 28
@@ -323,7 +323,7 @@ CREATE VIEW temp_view_test.v3_temp AS SELECT * FROM temp_table
323323
struct<>
324324
-- !query 32 output
325325
org.apache.spark.sql.AnalysisException
326-
Not allowed to create a permanent view `temp_view_test`.`v3_temp` by referencing a temporary view `temp_table`;
326+
Not allowed to create a permanent view `temp_view_test`.`v3_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
327327

328328

329329
-- !query 33
@@ -372,7 +372,7 @@ CREATE VIEW v4_temp AS
372372
struct<>
373373
-- !query 35 output
374374
org.apache.spark.sql.AnalysisException
375-
Not allowed to create a permanent view `v4_temp` by referencing a temporary view `temp_table`;
375+
Not allowed to create a permanent view `v4_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
376376

377377

378378
-- !query 36
@@ -384,7 +384,7 @@ CREATE VIEW v5_temp AS
384384
struct<>
385385
-- !query 36 output
386386
org.apache.spark.sql.AnalysisException
387-
Not allowed to create a permanent view `v5_temp` by referencing a temporary view `temp_table`;
387+
Not allowed to create a permanent view `v5_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
388388

389389

390390
-- !query 37
@@ -543,7 +543,7 @@ CREATE VIEW v6_temp AS SELECT * FROM base_table WHERE id IN (SELECT id FROM temp
543543
struct<>
544544
-- !query 47 output
545545
org.apache.spark.sql.AnalysisException
546-
Not allowed to create a permanent view `v6_temp` by referencing a temporary view `temp_table`;
546+
Not allowed to create a permanent view `v6_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
547547

548548

549549
-- !query 48
@@ -552,7 +552,7 @@ CREATE VIEW v7_temp AS SELECT t1.id, t2.a FROM base_table t1, (SELECT * FROM tem
552552
struct<>
553553
-- !query 48 output
554554
org.apache.spark.sql.AnalysisException
555-
Not allowed to create a permanent view `v7_temp` by referencing a temporary view `temp_table`;
555+
Not allowed to create a permanent view `v7_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
556556

557557

558558
-- !query 49
@@ -561,7 +561,7 @@ CREATE VIEW v8_temp AS SELECT * FROM base_table WHERE EXISTS (SELECT 1 FROM temp
561561
struct<>
562562
-- !query 49 output
563563
org.apache.spark.sql.AnalysisException
564-
Not allowed to create a permanent view `v8_temp` by referencing a temporary view `temp_table`;
564+
Not allowed to create a permanent view `v8_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
565565

566566

567567
-- !query 50
@@ -570,7 +570,7 @@ CREATE VIEW v9_temp AS SELECT * FROM base_table WHERE NOT EXISTS (SELECT 1 FROM
570570
struct<>
571571
-- !query 50 output
572572
org.apache.spark.sql.AnalysisException
573-
Not allowed to create a permanent view `v9_temp` by referencing a temporary view `temp_table`;
573+
Not allowed to create a permanent view `v9_temp` by referencing a temporary view `temp_table`. Please create a temp view instead by CREATE TEMP VIEW;
574574

575575

576576
-- !query 51
@@ -679,7 +679,7 @@ CREATE VIEW temporal1 AS SELECT * FROM t1 CROSS JOIN tt
679679
struct<>
680680
-- !query 61 output
681681
org.apache.spark.sql.AnalysisException
682-
Not allowed to create a permanent view `temporal1` by referencing a temporary view `tt`;
682+
Not allowed to create a permanent view `temporal1` by referencing a temporary view `tt`. Please create a temp view instead by CREATE TEMP VIEW;
683683

684684

685685
-- !query 62
@@ -720,7 +720,7 @@ CREATE VIEW temporal2 AS SELECT * FROM t1 INNER JOIN tt ON t1.num = tt.num2
720720
struct<>
721721
-- !query 64 output
722722
org.apache.spark.sql.AnalysisException
723-
Not allowed to create a permanent view `temporal2` by referencing a temporary view `tt`;
723+
Not allowed to create a permanent view `temporal2` by referencing a temporary view `tt`. Please create a temp view instead by CREATE TEMP VIEW;
724724

725725

726726
-- !query 65
@@ -761,7 +761,7 @@ CREATE VIEW temporal3 AS SELECT * FROM t1 LEFT JOIN tt ON t1.num = tt.num2
761761
struct<>
762762
-- !query 67 output
763763
org.apache.spark.sql.AnalysisException
764-
Not allowed to create a permanent view `temporal3` by referencing a temporary view `tt`;
764+
Not allowed to create a permanent view `temporal3` by referencing a temporary view `tt`. Please create a temp view instead by CREATE TEMP VIEW;
765765

766766

767767
-- !query 68
@@ -802,7 +802,7 @@ CREATE VIEW temporal4 AS SELECT * FROM t1 LEFT JOIN tt ON t1.num = tt.num2 AND t
802802
struct<>
803803
-- !query 70 output
804804
org.apache.spark.sql.AnalysisException
805-
Not allowed to create a permanent view `temporal4` by referencing a temporary view `tt`;
805+
Not allowed to create a permanent view `temporal4` by referencing a temporary view `tt`. Please create a temp view instead by CREATE TEMP VIEW;
806806

807807

808808
-- !query 71
@@ -811,7 +811,7 @@ CREATE VIEW temporal5 AS SELECT * FROM t1 WHERE num IN (SELECT num FROM t1 WHERE
811811
struct<>
812812
-- !query 71 output
813813
org.apache.spark.sql.AnalysisException
814-
Not allowed to create a permanent view `temporal5` by referencing a temporary view `tt`;
814+
Not allowed to create a permanent view `temporal5` by referencing a temporary view `tt`. Please create a temp view instead by CREATE TEMP VIEW;
815815

816816

817817
-- !query 72

sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
8080
sql("CREATE VIEW jtv1 AS SELECT * FROM temp_jtv1 WHERE id < 6")
8181
}.getMessage
8282
assert(e.contains("Not allowed to create a permanent view `jtv1` by " +
83-
"referencing a temporary view `temp_jtv1`"))
83+
"referencing a temporary view `temp_jtv1`. " +
84+
"Please create a temp view instead by CREATE TEMP VIEW"))
8485

8586
val globalTempDB = spark.sharedState.globalTempViewManager.database
8687
sql("CREATE GLOBAL TEMP VIEW global_temp_jtv1 AS SELECT * FROM jt WHERE id > 0")

0 commit comments

Comments
 (0)