Skip to content

Commit 7e2bb21

Browse files
committed
update parser version & fix tests
1 parent 6018b07 commit 7e2bb21

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

poetry.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ classifiers = [
1313

1414
[tool.poetry.dependencies]
1515
python = "^3.8"
16-
table-meta = "^0.1.5"
16+
table-meta = "^0.2.1"
1717
jinja2 = "^3.0.3"
1818

1919
[tool.poetry.dev-dependencies]
2020
pytest = "^5.2"
21-
simple-ddl-parser = "^0.24.0"
21+
simple-ddl-parser = "^0.24.1"
2222
m2r2 = "^0.3.2"
2323
twine = "^3.7.1"
2424
pre-commit = "^2.16.0"

simple_ddl_generator/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def __init__(self, data: Dict, dialect: str = 'sql') -> None:
1212

1313
def generate(self) -> str:
1414
self.tables = ddl_to_meta(self.data)
15+
1516
self.generate_ddl()
1617
return self.ddl_output
1718

simple_ddl_generator/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, tables: TableMeta, dialect: str) -> None:
1919

2020
def render_template(self) -> str:
2121
template = jinja2_env.get_template('common.jinja2')
22-
22+
print(self.tables)
2323
return template.render(
2424
properties_as_is=hql_table_properties,
2525
**self.tables)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{"EXTERNAL" if table.properties.external}}
1+
{{" EXTERNAL" if table.properties.external else ""}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CREATE{% include "before_table.jinja2" %} TABLE "{%if table.project%}{{table.project}}.{%endif%}{%if table.table_schema%}{{table.table_schema}}.{%endif%}{{table.name}}{% if table.columns %}" ({%for column in table.columns %}
1+
CREATE{% include "before_table.jinja2" %} TABLE{{" IF NOT EXISTS" if table.properties.if_not_exists else ""}} "{%if table.project%}{{table.project}}.{%endif%}{%if table.table_schema%}{{table.table_schema}}.{%endif%}{{table.name}}{% if table.columns %}" ({%for column in table.columns %}
22
{% include "column.jinja2" %}{{"," if not loop.last }}{%endfor%}){% else %}"{% endif %}{% include "table_properties.jinja2" %};

tests/test_simple_ddl_generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_simple_generation():
1313

1414

1515
def test_partitioned_by():
16-
expected = """CREATE TABLE "database.new_table_name" (
16+
expected = """CREATE EXTERNAL TABLE IF NOT EXISTS "database.new_table_name" (
1717
day_long_nm string,
1818
calendar_dt date,
1919
source_batch_id string,
@@ -38,7 +38,7 @@ def test_partitioned_by():
3838
field_long bigint
3939
) PARTITIONED BY (batch_id int);"""
4040
# get result from parser
41-
data = DDLParser(ddl).run(group_by_type=True, output_mode="bigquery")
41+
data = DDLParser(ddl).run(group_by_type=True, output_mode="hql")
4242

4343
# rename, for example, table name
4444

@@ -72,15 +72,15 @@ def test_hql_several_more_properties():
7272
g = DDLGenerator(data)
7373
data["tables"][0]["location"] = "s3://new_location"
7474
g.generate()
75-
expected = r"""CREATE TABLE "default.salesorderdetail" (
75+
expected = r"""CREATE TABLE IF NOT EXISTS "default.salesorderdetail" (
7676
SalesOrderID int,
7777
ProductID int,
7878
OrderQty int,
7979
LineTotal decimal)
8080
PARTITIONED BY (batch_id int, batch_id2 string, batch_32 some_type)
8181
LOCATION s3://new_location
8282
ROW FORMAT DELIMITED
83-
FIELDS TERMINATED BY ,
83+
FIELDS TERMINATED BY ','
8484
MAP KEYS TERMINATED BY '\003'
8585
COLLECTION ITEMS TERMINATED BY '\002'
8686
STORED AS TEXTFILE;"""

0 commit comments

Comments
 (0)