Skip to content

Commit d46eba3

Browse files
committed
Add expression Fusion SQL rule
1 parent 8819d3e commit d46eba3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

singlestoredb/fusion/handler.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
close_paren = ws* ")" ws*
3434
open_repeats = ws* ~r"[\(\[\{]" ws*
3535
close_repeats = ws* ~r"[\)\]\}]" ws*
36-
select = ~r"SELECT"i ws+ ~r".+" ws*
36+
expression = ~r"[\s\S]*" ws*
3737
table = ~r"(?:([A-Za-z0-9_\-]+)|`([^\`]+)`)(?:\.(?:([A-Za-z0-9_\-]+)|`([^\`]+)`))?" ws*
3838
column = ~r"(?:([A-Za-z0-9_\-]+)|`([^\`]+)`)(?:\.(?:([A-Za-z0-9_\-]+)|`([^\`]+)`))?" ws*
3939
link_name = ~r"(?:([A-Za-z0-9_\-]+)|`([^\`]+)`)(?:\.(?:([A-Za-z0-9_\-]+)|`([^\`]+)`))?" ws*
@@ -77,6 +77,7 @@
7777
'<file-type>': r'''
7878
file_type = { FILE | FOLDER }
7979
''',
80+
'<expression>': '',
8081
}
8182

8283
BUILTIN_DEFAULTS = { # type: ignore
@@ -627,6 +628,18 @@ def register(cls, overwrite: bool = False) -> None:
627628
cls.compile()
628629
registry.register_handler(cls, overwrite=overwrite)
629630

631+
def create_result(self) -> result.FusionSQLResult:
632+
"""
633+
Create a new result object.
634+
635+
Returns
636+
-------
637+
FusionSQLResult
638+
A new result object for this handler
639+
640+
"""
641+
return result.FusionSQLResult()
642+
630643
def execute(self, sql: str) -> result.FusionSQLResult:
631644
"""
632645
Parse the SQL and invoke the handler method.
@@ -746,9 +759,9 @@ def visit_init(self, node: Node, visited_children: Iterable[Any]) -> Any:
746759
_, out, *_ = visited_children
747760
return out
748761

749-
def visit_select(self, node: Node, visited_children: Iterable[Any]) -> Any:
750-
out = ' '.join(flatten(visited_children))
751-
return {'select': out}
762+
def visit_expression(self, node: Node, visited_children: Iterable[Any]) -> Any:
763+
out = ' '.join(flatten(visited_children)).strip()
764+
return {'expression': out}
752765

753766
def visit_order_by(self, node: Node, visited_children: Iterable[Any]) -> Any:
754767
"""Handle ORDER BY."""

0 commit comments

Comments
 (0)