Skip to content
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

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

cfhowes
Copy link
Contributor

@cfhowes cfhowes commented Jan 25, 2024

resolves #236

Updated parsing of UNIQUE and UNIQUE KEY clauses and statements. Now when multiple columns are specified in a UNIQUE clause/statement it will be treated as a compound UNIQUE statement and put in the constraints section of the parse dict. It also means that the individual columns will have unique=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.

@@ -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.
Copy link
Contributor Author

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
Copy link
Contributor Author

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,
Copy link
Contributor Author

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():
Copy link
Contributor Author

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():
Copy link
Contributor Author

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.

@xnuinside
Copy link
Owner

@cfhowes thanks for your PR, I can take a look on this weekends

@xnuinside xnuinside merged commit b162a34 into xnuinside:main Jan 29, 2024
8 checks passed
@xnuinside
Copy link
Owner

@cfhowes thanks for amazing update

@cfhowes cfhowes deleted the issue_236_unique branch January 31, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems with UNIQUE parsing
2 participants