[ https://issues.apache.org/jira/browse/PHOENIX-3298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15533521#comment-15533521 ]
Eric Lomore commented on PHOENIX-3298: -------------------------------------- Quick summary of what I was talking about: During grammar execution, we parse nodes as either Nullable or Not Nullable. If no option is stated, then by default, Nullable. No information is preserved on whether it was set by default or explicitly. Once all ColumnDefs are created, and ColumnDefInPkConstraints are created, we need to identify the case where there is a single PK column node, and it was set to Nullable by default. The issue arises in passing this "default" information down. Hence far, my 2 ideas were to change the primitive isNull field to a Boolean isNull field, or to introduce a new field called implicitlyNull. Both of these changes require large changes to the underlying Phoenix code, which would cause changes to PhoenixSQL.g which is not what we want because this functionality works in Phoenix. The idea of solving this in the grammar execution doesn't work either since the ColumnDefs are constructed long before we have any info on PKConstraints, which aren't processed until MetaDataClient.java. See the attached patch that would convert "Nullable" to "Not Nullable" for ANY single column primary key (not just those implicitly set). The relevant grammar code: {code:java|title=parserImpls.ftl} SqlColumnDefNode ColumnDef() : { SqlIdentifier columnName; SqlDataTypeNode dataType; boolean isNull = true; boolean isPk = false; SortOrder sortOrder = SortOrder.getDefault(); boolean isRowTimestamp = false; SqlParserPos pos; } { columnName = DualIdentifier() dataType = PhoenixDataType() [ <NOT> <NULL> {isNull = false;} | <NULL> {isNull = true;} ] [ <PRIMARY> <KEY> {isPk = true;} ] [ <ASC> {sortOrder = SortOrder.ASC;} | <DESC> {sortOrder = SortOrder.DESC;} ] [ <ROW_TIMESTAMP> {isRowTimestamp = true;} ] { pos = columnName.getParserPosition().plus(getPos()); return new SqlColumnDefNode(pos, columnName, dataType, isNull, isPk, sortOrder, null, isRowTimestamp); } } {code} > Create Table: Single column primary key may not be null > ------------------------------------------------------- > > Key: PHOENIX-3298 > URL: https://issues.apache.org/jira/browse/PHOENIX-3298 > Project: Phoenix > Issue Type: Sub-task > Reporter: Eric Lomore > Assignee: Eric Lomore > Attachments: PHOENIX-3298-WIP > > > Create table statements with a single column currently must have "NOT NULL" > identifier to pass tests. > Running this code results in failure > {code}CREATE TABLE t (k VARCHAR PRIMARY KEY DESC){code} > While this allows tests to pass > {code}CREATE TABLE t (k VARCHAR NOT NULL PRIMARY KEY DESC){code} > Must either enforce the not null condition and update test cases, or apply a > fix. -- This message was sent by Atlassian JIRA (v6.3.4#6332)