Skip to content

Commit

Permalink
added lost files
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside committed Aug 5, 2021
1 parent 8410e72 commit b5db0f9
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 0 deletions.
16 changes: 16 additions & 0 deletions simple_ddl_parser/dialects/snowflake.py
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]
27 changes: 27 additions & 0 deletions tests/test_create_database.py
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
181 changes: 181 additions & 0 deletions tests/test_snowflake.py
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

0 comments on commit b5db0f9

Please sign in to comment.