Skip to content

Commit

Permalink
Merge pull request #222 from dmaresma/feature/221
Browse files Browse the repository at this point in the history
fix _file_format snowflake ddl option
  • Loading branch information
xnuinside authored Jan 5, 2024
2 parents e60c7ee + 66b604b commit eafca71
Show file tree
Hide file tree
Showing 4 changed files with 476 additions and 46,134 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
**v0.31.3**
**v0.31.5**
### Improvements
1. Support for KEY statement in CREATE TABLE statements. KEY statements will now create INDEX entries in the DDL parser.

**v0.31.4**
### Improvements
#### Snowflake update:
1. enforce support for Snowflake _FILE_FORMAT options in External Column ddl statement - https://github.com/xnuinside/simple-ddl-parser/issues/221

**v0.31.3**
### Improvements
#### Snowflake update:
Expand Down
24 changes: 20 additions & 4 deletions simple_ddl_parser/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@ def p_expression_cluster_by(self, p):
p_list = remove_par(list(p))
p[0]["cluster_by"] = p_list[-1]

def p_multiple_format_equals(self0, p: List) -> None:
"""multiple_format_equals : fmt_equals
| multiple_format_equals fmt_equals
"""
# Handles multiple format in the same format statement
p[0] = p[1]

def p_fmt_equals(self, p: List) -> None:
"""fmt_equals : id LP RP
| id LP fmt_equals RP
| id LP multi_id RP
"""
p_list = list(p)
p[0] = p_list[2:][1].split(" ")

def p_table_property_equals(self, p: List) -> None:
"""table_property_equals : id id id_or_string
| id id_or_string
| LP id id id_or_string RP
| LP id_or_string RP
| id table_property_equals
| id_equals
"""
p_list = remove_par(list(p))
p[0] = str(p_list[-1])
Expand Down Expand Up @@ -138,16 +155,16 @@ def p_expression_catalog(self, p):
p[0]["catalog"] = p_list[-1]

def p_expression_file_format(self, p):
"""expr : expr FILE_FORMAT table_property_equals"""
"""expr : expr FILE_FORMAT multiple_format_equals"""
p[0] = p[1]
p_list = remove_par(list(p))
p[0]["file_format"] = p_list[-1]

def p_expression_stage_file_format(self, p):
"""expr : expr STAGE_FILE_FORMAT table_property_equals"""
"""expr : expr STAGE_FILE_FORMAT multiple_format_equals"""
p[0] = p[1]
p_list = remove_par(list(p))
p[0]["stage_file_format"] = p_list[-1]
p[0]["stage_file_format"] = p_list[-1] if len(p_list[-1]) > 1 else p_list[-1][0]

def p_expression_table_format(self, p):
"""expr : expr TABLE_FORMAT table_property_equals"""
Expand All @@ -170,7 +187,6 @@ def p_as_virtual(self, p: List):
if len(p) == 5:
_as = p[3]
else:
# _as = p[3]+p[4]+p[5]+p[6]+",".join(p[7])+p[8]+p[9]+",".join(p[10])+p[11]
for i in p[3:len(p) - 1]:
_as += i if isinstance(i, str) else ",".join(i)
p[0] = {"generated": {"as": _as}}
Loading

0 comments on commit eafca71

Please sign in to comment.