Skip to content

Commit

Permalink
handle generator function
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Oct 31, 2024
1 parent 166dcee commit 739777d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions mo_sql_parsing/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def dispatch(self, json, prec=100):
return self._literal(json, prec)
elif "substring" in json:
return self._substring(json, prec)
elif "generator" in json:
return self._generator(json, prec)
elif "group_concat" in json:
return self._group_concat(json, prec)
elif "value" in json:
Expand Down Expand Up @@ -362,6 +364,11 @@ def _substring(self, json, prec):
params = ", ".join(self.dispatch(p) for p in json["substring"])
return f"SUBSTRING({params})"

def _generator(self, json, prec):
# TODO: replace with function-using-keywords
rowcount = self.dispatch(json["rowcount"])
return f"GENERATOR(ROWCOUNT=>{rowcount})"

def _group_concat(self, json, prec):
acc = ["group_concat(", self.dispatch(json["group_concat"]), " "]
if "orderby" in json.keys():
Expand Down
2 changes: 1 addition & 1 deletion mo_sql_parsing/sql_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def matching(type):
one_param = (
# KEYWORD PARAMETERS?
# https://docs.snowflake.com/en/sql-reference/functions/generator.html
Group(ident + Literal("=>").suppress() + Group(expression))("kwargs")
Group(ident/ (lambda t: t[0].lower()) + Literal("=>").suppress() + Group(expression))("kwargs")
/ to_kwarg
) | Group(expression)("params")

Expand Down

0 comments on commit 739777d

Please sign in to comment.