[ 
https://issues.apache.org/jira/browse/PHOENIX-5960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17238884#comment-17238884
 ] 

ASF GitHub Bot commented on PHOENIX-5960:
-----------------------------------------

virajjasani commented on a change in pull request #987:
URL: https://github.com/apache/phoenix/pull/987#discussion_r530592231



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
##########
@@ -801,6 +802,37 @@ public void testSetTableDescriptorPropertyOnView() throws 
Exception {
         conn2.close();
     }
 
+    @Test
+    public void testCreateViewFromNonExistentTable() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.createStatement().execute(
+                "CREATE TABLE IF NOT EXISTS S.T1 (A INTEGER PRIMARY KEY, B 
INTEGER)");
+            // 1. create view from non-existent table (without schema)
+            try {
+                conn.createStatement().execute(
+                    "CREATE VIEW IF NOT EXISTS V1(C INTEGER) AS SELECT * FROM 
T2");
+            } catch (TableNotFoundException e) {
+                assertEquals("T2", e.getTableName());
+                assertEquals("", e.getSchemaName());
+                assertEquals("ERROR 1012 (42M03): Table undefined. 
tableName=T2",
+                    e.getMessage());
+            }
+            // 2. create view from existing table - successful
+            conn.createStatement().execute(
+                "CREATE VIEW IF NOT EXISTS V1(C INTEGER) AS SELECT * FROM 
S.T1");
+            // 3. create view from non-existent table (with schema)
+            try {
+                conn.createStatement().execute(

Review comment:
       Done




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

For queries about this service, please contact Infrastructure at:
[email protected]


> Creating a view on a non-existent table throws the wrong exception
> ------------------------------------------------------------------
>
>                 Key: PHOENIX-5960
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-5960
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.15.0
>            Reporter: Chinmay Kulkarni
>            Assignee: Viraj Jasani
>            Priority: Minor
>              Labels: beginner, newbie, phoenix-hardening, quality-improvement
>             Fix For: 5.1.0, 4.16.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Ran across this by accident as a result of a typo in my create view statement:
> # CREATE TABLE IF NOT EXISTS *T1* (A INTEGER PRIMARY KEY, B INTEGER);
> # CREATE VIEW IF NOT EXISTS V (new_col INTEGER) AS SELECT * FROM *T2*;
> View creation fails with the following:
> {noformat}
> Error: ERROR 509 (42888): The table does not have a primary key. 
> (state=42888,code=509)
> java.sql.SQLException: ERROR 509 (42888): The table does not have a primary 
> key.
>       at 
> org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:575)
>       at 
> org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:195)
>       at 
> org.apache.phoenix.compile.CreateTableCompiler.compile(CreateTableCompiler.java:182)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$ExecutableCreateTableStatement.compilePlan(PhoenixStatement.java:841)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$ExecutableCreateTableStatement.compilePlan(PhoenixStatement.java:830)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:407)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:397)
>       at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:396)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:384)
>       at 
> org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1886)
>       at sqlline.Commands.execute(Commands.java:814)
>       at sqlline.Commands.sql(Commands.java:754)
>       at sqlline.SqlLine.dispatch(SqlLine.java:646)
>       at sqlline.SqlLine.begin(SqlLine.java:510)
>       at sqlline.SqlLine.start(SqlLine.java:233)
>       at sqlline.SqlLine.main(SqlLine.java:175)
> {noformat}
> Ideally, this should throw a TableNotFoundException. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to