-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Snowflake: | ||
def p_clone(self, p): | ||
"""clone : CLONE ID""" | ||
p_list = list(p) | ||
p[0] = {"clone": {"from": p_list[-1]}} | ||
|
||
def p_table_properties(self, p): | ||
"""table_properties : ID ID ID""" | ||
p_list = list(p) | ||
p[0] = {p_list[-3]: p_list[-1]} | ||
|
||
def p_expression_cluster_by(self, p): | ||
"""expr : expr CLUSTER BY LP pid RP""" | ||
p[0] = p[1] | ||
p_list = list(p) | ||
p[0]["cluster_by"] = p_list[-2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from simple_ddl_parser import DDLParser | ||
|
||
|
||
def test_parse_properties_in_create_db(): | ||
|
||
ddl = """ | ||
create database mytestdb2 data_retention_time_in_days = 10 ENCRYPTED = True some_other_property = 'value'; | ||
""" | ||
result = DDLParser(ddl).run(group_by_type=True) | ||
expected = { | ||
"databases": [ | ||
{ | ||
"database_name": "mytestdb2", | ||
"properties": { | ||
"ENCRYPTED": "True", | ||
"data_retention_time_in_days": "10", | ||
"some_other_property": "'value'", | ||
}, | ||
} | ||
], | ||
"domains": [], | ||
"schemas": [], | ||
"sequences": [], | ||
"tables": [], | ||
"types": [], | ||
} | ||
assert expected == result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
from simple_ddl_parser import DDLParser | ||
|
||
|
||
def test_clone_db(): | ||
|
||
ddl = """ | ||
create database mytestdb_clone clone mytestdb; | ||
""" | ||
result = DDLParser(ddl).run(group_by_type=True) | ||
expected = { | ||
"databases": [ | ||
{"clone": {"from": "mytestdb"}, "database_name": "mytestdb_clone"} | ||
], | ||
"domains": [], | ||
"schemas": [], | ||
"sequences": [], | ||
"tables": [], | ||
"types": [], | ||
} | ||
assert result == expected | ||
|
||
|
||
def test_clone_table(): | ||
expected = { | ||
"domains": [], | ||
"schemas": [], | ||
"sequences": [], | ||
"tables": [ | ||
{ | ||
"alter": {}, | ||
"checks": [], | ||
"columns": [], | ||
"index": [], | ||
"like": {"schema": None, "table_name": "orders"}, | ||
"partitioned_by": [], | ||
"primary_key": [], | ||
"schema": None, | ||
"table_name": "orders_clone", | ||
"tablespace": None, | ||
} | ||
], | ||
"types": [], | ||
} | ||
|
||
ddl = """ | ||
create table orders_clone clone orders; | ||
""" | ||
result = DDLParser(ddl).run(group_by_type=True) | ||
assert expected == result | ||
|
||
|
||
def test_clone_schema(): | ||
expected = { | ||
"domains": [], | ||
"schemas": [ | ||
{"clone": {"from": "testschema"}, "schema_name": "mytestschema_clone"} | ||
], | ||
"sequences": [], | ||
"tables": [], | ||
"types": [], | ||
} | ||
|
||
ddl = """ | ||
create schema mytestschema_clone clone testschema; | ||
""" | ||
result = DDLParser(ddl).run(group_by_type=True) | ||
assert expected == result | ||
|
||
|
||
def test_cluster_by(): | ||
|
||
ddl = """ | ||
create table mytable (date timestamp_ntz, id number, content variant) cluster by (date, id); | ||
""" | ||
result = DDLParser(ddl).run(group_by_type=True) | ||
expected = { | ||
"domains": [], | ||
"schemas": [], | ||
"sequences": [], | ||
"tables": [ | ||
{ | ||
"alter": {}, | ||
"checks": [], | ||
"cluster_by": ["date", "id"], | ||
"columns": [ | ||
{ | ||
"check": None, | ||
"default": None, | ||
"name": "date", | ||
"nullable": True, | ||
"references": None, | ||
"size": None, | ||
"type": "timestamp_ntz", | ||
"unique": False, | ||
}, | ||
{ | ||
"check": None, | ||
"default": None, | ||
"name": "id", | ||
"nullable": True, | ||
"references": None, | ||
"size": None, | ||
"type": "number", | ||
"unique": False, | ||
}, | ||
{ | ||
"check": None, | ||
"default": None, | ||
"name": "content", | ||
"nullable": True, | ||
"references": None, | ||
"size": None, | ||
"type": "variant", | ||
"unique": False, | ||
}, | ||
], | ||
"index": [], | ||
"partitioned_by": [], | ||
"primary_key": [], | ||
"schema": None, | ||
"table_name": "mytable", | ||
"tablespace": None, | ||
} | ||
], | ||
"types": [], | ||
} | ||
assert expected == result | ||
|
||
|
||
def test_enforced(): | ||
|
||
ddl = """ | ||
create table table2 ( | ||
col1 integer not null, | ||
col2 integer not null, | ||
constraint pkey_1 primary key (col1, col2) not enforced | ||
); | ||
""" | ||
result = DDLParser(ddl).run(group_by_type=True) | ||
expected = { | ||
"domains": [], | ||
"schemas": [], | ||
"sequences": [], | ||
"tables": [ | ||
{ | ||
"alter": {}, | ||
"checks": [], | ||
"columns": [ | ||
{ | ||
"check": None, | ||
"default": None, | ||
"name": "col1", | ||
"nullable": False, | ||
"references": None, | ||
"size": None, | ||
"type": "integer", | ||
"unique": False, | ||
}, | ||
{ | ||
"check": None, | ||
"default": None, | ||
"name": "col2", | ||
"nullable": False, | ||
"references": None, | ||
"size": None, | ||
"type": "integer", | ||
"unique": False, | ||
}, | ||
], | ||
"index": [], | ||
"partitioned_by": [], | ||
"primary_key": [], | ||
"primary_key_enforced": False, | ||
"schema": None, | ||
"table_name": "table2", | ||
"tablespace": None, | ||
} | ||
], | ||
"types": [], | ||
} | ||
assert expected == result |