-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #236: Updates to handle stand-alone UNIQUE and UNIQUE KEY statements #237
Conversation
…KEY statements.
@@ -324,6 +324,7 @@ def p_column(self, p: List) -> None: | |||
p[0] = {"index_stmt": True, "name": p[2]["type"], "columns": ""} | |||
return | |||
if p[1] and isinstance(p[1], dict) and p[1].get("index_stmt") is True: | |||
# @TODO: if we are normalizing columns, we need to normalize them here too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my TODO's got added, but this is also on my list....
@@ -1606,9 +1638,22 @@ def p_expression_primary_key(self, p): | |||
p[0] = p[1] | |||
|
|||
def p_uniq(self, p: List) -> None: | |||
"""uniq : UNIQUE LP pid RP""" | |||
"""uniq : UNIQUE LP pid RP | |||
| UNIQUE KEY id LP pid RP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before UNIQUE KEY
statements were causing the parser to (silently) error and the table to not be generated.
@@ -226,7 +226,7 @@ def test_constraint_unique(): | |||
"references": None, | |||
"size": None, | |||
"type": "BIGINT", | |||
"unique": True, | |||
"unique": False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these changes were from the move to handle compound unique clauses/statements.
@@ -275,164 +275,6 @@ def test_parser_multiple_tables(): | |||
assert DDLParser(ddl).run() == expected | |||
|
|||
|
|||
def test_unique_statement_in_columns(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i moved the tests specific to UNIQUE
statements into a new file. If you dislike I can put them back here.
from simple_ddl_parser import DDLParser | ||
|
||
|
||
def test_unique_statement_in_columns(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2/3 of these are copy-paste from test_simple_ddl_parser.py. The last test here is the new one for UNIQUE KEY
statements.
@cfhowes thanks for your PR, I can take a look on this weekends |
@cfhowes thanks for amazing update |
resolves #236
Updated parsing of
UNIQUE
andUNIQUE KEY
clauses and statements. Now when multiple columns are specified in aUNIQUE
clause/statement it will be treated as a compound UNIQUE statement and put in theconstraints
section of the parse dict. It also means that the individual columns will haveunique=False
since the individual column does not actually have a UNIQUE constraint. If I have done this correctly it will match the SQL spec more closely then before.