xnuinside/simple-ddl-parser

Snowflake support { AUTOINCREMENT | IDENTITY } with [ { ORDER | NOORDER } ] optional parameter

dmaresma opened this issue · 1 comments

Describe the bug
Adding support Snowflake CREATE TABLE { AUTOINCREMENT | IDENTITY } column definition with explicit Order or NoOrder optional parameters

https://docs.snowflake.com/en/sql-reference/sql/create-table
To Reproduce
run the following tests
`
def test_autoincrement_order():
# test for https://github.com/xnuinside/simple-ddl-parser/issues/20x
ddl = """CREATE TABLE table (surrogatekey_SK NUMBER(38,0) NOT NULL autoincrement start 1 increment 1 ORDER COMMENT 'Record Identification Number Ordered')"""
result = DDLParser(ddl).run(group_by_type=True)
expected = {
"ddl_properties": [],
"domains": [],
"schemas": [],
"sequences": [],
"tables": [
{
"alter": {},
"checks": [],
"columns": [
{
"check": None,
"comment": "Record Identification Number Ordered",
"default": None,
"name": "surrogatekey_SK",
"nullable": True,
"references": None,
"size": None,
"type": "int",
"unique": False,
"autoincrement":True,
"start" : 1,
"increment": 1
}
],
"index": [],
"partitioned_by": [],
"primary_key": [],
"schema": None,
"table_name": "table",
"tablespace": None,
}
],
"types": [],
}
assert result == expected

def test_autoincrement_noorder():
# test for https://github.com/xnuinside/simple-ddl-parser/issues/20x
ddl = """CREATE TABLE table (surrogatekey_SK NUMBER(38,0) NOT NULL autoincrement start 1 increment 1 NOORDER COMMENT 'Record Identification Number NoOrdered')"""
result = DDLParser(ddl).run(group_by_type=True)
expected = {
"ddl_properties": [],
"domains": [],
"schemas": [],
"sequences": [],
"tables": [
{
"alter": {},
"checks": [],
"columns": [
{
"check": None,
"comment": "Record Identification Number NoOrdered",
"default": None,
"name": "surrogatekey_SK",
"nullable": True,
"references": None,
"size": None,
"type": "int",
"unique": False,
"autoincrement":True,
"start" : 1,
"increment": None
}
],
"index": [],
"partitioned_by": [],
"primary_key": [],
"schema": None,
"table_name": "table",
"tablespace": None,
}
],
"types": [],
}
assert result == expected`

Expected behavior
no regression, keep autoincrement: true , increment:none in case of NOORDER and 1 in case of ORDER

@dmaresma thanks one more time for your PR, I released 0.31.2 with your changes