Skip to content

Commit

Permalink
fix parserutils bug
Browse files Browse the repository at this point in the history
-s
  • Loading branch information
qidi1 committed Sep 20, 2023
1 parent 4804c7f commit b0d5783
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 122 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "sqlgpt-parser"
version = "0.0.1a4"
version = "0.0.1a5"
authors = [
{ name="luliwjc", email="[email protected]" },
{ name="Ifffff", email="[email protected]" },
Expand Down
8 changes: 5 additions & 3 deletions sqlgpt_parser/format/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,19 +424,21 @@ def visit_list_expression(self, node, unmangle_names):
def visit_window_func(self, node, unmangle_names):
args = ", ".join([self.process(arg, unmangle_names) for arg in node.func_args])
ignore_null = f" {node.ignore_null} NULLS" if node.ignore_null else ""
window_spec = " OVER (" + self.process(node.window_spec, unmangle_names) + ")"
window_spec = " OVER " + self.process(node.window_spec, unmangle_names)
return f"{node.func_name.upper()}({args}){ignore_null}{window_spec}"

def visit_window_spec(self, node, unmangle_names):
if node.window_name is not None:
return node.window_name

parts = []
if node.partition_by:
self.process(node.partition_by, unmangle_names)
if node.order_by:
parts.append("ORDER BY " + format_sort_items(node.order_by, unmangle_names))
if node.frame_clause:
parts.append(self.process(node.frame_clause, unmangle_names))

return ' '.join(parts)
return '(' + ' '.join(parts) + ')'

def visit_partition_by_clause(self, node, unmangle_names):
return "PARTITION BY " + self._join_expressions(node.items, unmangle_names)
Expand Down
6 changes: 3 additions & 3 deletions sqlgpt_parser/parser/mysql_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ def p_alias_opt(p):
if p.slice[1].type == "alias":
p[0] = p[1]
else:
p[0] = ()
p[0] = []


def p_alias(p):
Expand All @@ -1215,9 +1215,9 @@ def p_alias(p):
| AS string_lit
| string_lit"""
if len(p) == 3:
p[0] = (p[1], p[2])
p[0] = [p[1], p[2]]
else:
p[0] = p[1]
p[0] = [p[1]]


def p_expression(p):
Expand Down
6 changes: 3 additions & 3 deletions sqlgpt_parser/parser/oceanbase_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ def p_alias_opt(p):
if p.slice[1].type == "alias":
p[0] = p[1]
else:
p[0] = ()
p[0] = []


def p_alias(p):
Expand All @@ -1212,9 +1212,9 @@ def p_alias(p):
| AS string_lit
| string_lit"""
if len(p) == 3:
p[0] = (p[1], p[2])
p[0] = [p[1], p[2]]
else:
p[0] = p[1]
p[0] = [p[1]]


def p_expression(p):
Expand Down
4 changes: 2 additions & 2 deletions sqlgpt_parser/parser/odps_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ def p_alias_opt(p):
if p.slice[1].type == "alias":
p[0] = p[1]
else:
p[0] = ()
p[0] = []


def p_alias(p):
Expand All @@ -1214,7 +1214,7 @@ def p_alias(p):
| AS string_lit
| string_lit"""
if len(p) == 3:
p[0] = (p[1], p[2])
p[0] = [p[1], p[2]]
else:
p[0] = p[1]

Expand Down
Loading

0 comments on commit b0d5783

Please sign in to comment.