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

Xinyi Yan commented on PHOENIX-2265:
------------------------------------

I check if ViewType is mapped to HBase table and no PK at 
CreateTableCompiler.compile, then raise an exception.

Locally tested sad path, as well as a happy path.
{code:java}
0: jdbc:phoenix:localhost:2181:/hbase> CREATE VIEW "users_data" ( ROWKEY 
VARCHAR, "personal_info"."firstName" VARCHAR);
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:494)
at 
org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:150)
at 
org.apache.phoenix.compile.CreateTableCompiler.compile(CreateTableCompiler.java:141)
at 
org.apache.phoenix.jdbc.PhoenixStatement$ExecutableCreateTableStatement.compilePlan(PhoenixStatement.java:819)
at 
org.apache.phoenix.jdbc.PhoenixStatement$ExecutableCreateTableStatement.compilePlan(PhoenixStatement.java:808)
at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:401)
at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:391)
at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
at 
org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:390)
at 
org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:378)
at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1825)
at sqlline.Commands.execute(Commands.java:822)
at sqlline.Commands.sql(Commands.java:732)
at sqlline.SqlLine.dispatch(SqlLine.java:813)
at sqlline.SqlLine.begin(SqlLine.java:686)
at sqlline.SqlLine.start(SqlLine.java:398)
at sqlline.SqlLine.main(SqlLine.java:291)
0: jdbc:phoenix:localhost:2181:/hbase> CREATE VIEW "users_data" ( ROWKEY 
VARCHAR PRIMARY KEY, "personal_info"."firstName" VARCHAR);
No rows affected (0.012 seconds)
0: jdbc:phoenix:localhost:2181:/hbase> select * from "users_data";
+----------+------------+
| ROWKEY | firstName |
+----------+------------+
| rowKey1 | foo |
+----------+------------+
1 row selected (0.021 seconds)
{code}
 

 

However, I have no idea how to create unit tests because we have to create an 
HBase table first...

Any comments? 

[~dbwong] [~vincentpoon] [~tdsilva]

> Disallow creation of view over HBase table if PK not specified
> --------------------------------------------------------------
>
>                 Key: PHOENIX-2265
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2265
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: James Taylor
>            Assignee: Xinyi Yan
>            Priority: Major
>              Labels: newbie
>
> We currently allow a Phoenix view to be defined over an HBase table without 
> specifying a primary key.
> To repro, create an HBase table in the HBase shell:
> {code}
>  create 'hb1', 'f1'
> {code}
> Then create a view in Phoenix:
> {code}
> create view "hb1"("f1".a varchar);
> {code}
> This should yield an error, as we haven't specified a primary key.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to