[
https://issues.apache.org/jira/browse/PHOENIX-3263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15487831#comment-15487831
]
Eric Lomore commented on PHOENIX-3263:
--------------------------------------
At the moment, Phoenix supports both comma and no comma in front of the
constraint, and Phoenix-Calcite supports only no comma in front of the
constraint.
The reason phoenix is able to do this is because it immediately parses the SQL
query into a CompilableStatement and then executes it.
{code:title=PhoenixStatement.java|borderStyle=solid}
CompilableStatement stmt = parseStatement(sql);
executeQuery(stmt);
{code}
In Phoenix-Calcite the raw SQL query is handed down to Calcite logic. Hence, we
could raise this issue in a Calcite jira, since the standard is to support both
and Calcite does not.
Alternatively, we can add a parsing layer on top of Phoenix-calcite to remove
the comma and then pass it to the Calcite execution runtime.
{code:title=AvaticaStatement.java|borderStyle=solid}
Meta.ExecuteResult x = connection.prepareAndExecuteInternal(this, sql,
maxRowCount1);
{code}
To further illustrate that I don't believe this is a phoenix issue, the
following test case passes on the calcite branch.
{code}
@Test
public void testParseCreateTableCommaBeforePrimaryKeyConstraint() throws
Exception {
for (String leadingComma : new String[]{",", ""}) {
String s = "create table core.entity_history_archive (id CHAR(15),
name VARCHAR(150)${o} constraint pk primary key (id))".replace("${o}",
leadingComma);
CreateTableStatement stmt = (CreateTableStatement)new
SQLParser((s)).parseStatement();
assertEquals(2, stmt.getColumnDefs().size());
assertNotNull(stmt.getPrimaryKeyConstraint());
}
}
{code}
> Allow comma before CONSTRAINT to be optional
> --------------------------------------------
>
> Key: PHOENIX-3263
> URL: https://issues.apache.org/jira/browse/PHOENIX-3263
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: James Taylor
>
> In Phoenix, the comma before the CONSTRAINT is optional (which matches
> Oracle). Can this be supported in Calcite Phoenix?
> For example, this is ok in Phoenix:
> {code}
> CREATE TABLE T (
> K VARCHAR
> CONSTRAINT PK PRIMARY KEY (K));
> {code}
> as is this:
> {code}
> CREATE TABLE T (
> K VARCHAR,
> CONSTRAINT PK PRIMARY KEY (K));
> {code}
> If this is not feasible, we could require the comma and change the tests.
> This is leading to a lot of failures.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)