-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import orjson | ||
|
||
from opteryx.managers.expression import NodeType | ||
from opteryx.third_party.travers import Graph | ||
|
||
|
||
def _load_views(): | ||
try: | ||
with open("views.json", "rb") as defs: | ||
return orjson.loads(defs.read()) | ||
except Exception as err: | ||
print(f"[OPTERYX] Unable to open views definition file. {err}") | ||
return {} | ||
|
||
|
||
VIEWS = _load_views() | ||
|
||
|
||
def is_view(view_name: str) -> bool: | ||
return view_name in VIEWS | ||
|
||
|
||
def view_as_plan(view_name: str) -> Graph: | ||
from opteryx.planner.logical_planner import do_logical_planning_phase | ||
from opteryx.third_party import sqloxide | ||
from opteryx.utils.sql import clean_statement | ||
from opteryx.utils.sql import remove_comments | ||
|
||
operation = VIEWS.get(view_name)["statement"] | ||
|
||
clean_sql = clean_statement(remove_comments(operation)) | ||
parsed_statements = sqloxide.parse_sql(clean_sql, dialect="mysql") | ||
logical_plan, _, _ = next(do_logical_planning_phase(parsed_statements)) | ||
|
||
return logical_plan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"mission_reports": { | ||
"statement": "/* A test case for VIEW functionality */ SELECT s.name AS satellite_name FROM $satellites AS s INNER JOIN $planets AS p ON p.id = s.planetId" | ||
}, | ||
"my_mission_reports": { | ||
"statement": "/* A test case for row-permissions functionality */ SELECT * FROM $astronauts WHERE LIST_CONTAINS_ANY(missions, @@user_memberships)" | ||
} | ||
} |