-
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.
Browse files
Browse the repository at this point in the history
Feature/#351 Support `SHOW FUNCTIONS`
- Loading branch information
Showing
8 changed files
with
143 additions
and
6 deletions.
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
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 |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
r"FULL\sOUTER\sJOIN", | ||
r"JOIN", | ||
r"WITH", | ||
r"SHOW", | ||
] | ||
|
||
COMBINE_WHITESPACE_REGEX = re.compile(r"\s+") | ||
|
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
File renamed without changes.
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,60 @@ | ||
# 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. | ||
|
||
""" | ||
Show Functions Node | ||
This is a SQL Query Execution Plan Node. | ||
""" | ||
from typing import Iterable | ||
import pyarrow | ||
|
||
from opteryx import operators, functions | ||
from opteryx.models import Columns, QueryDirectives, QueryStatistics | ||
from opteryx.operators import BasePlanNode | ||
|
||
|
||
class ShowFunctionsNode(BasePlanNode): | ||
def __init__( | ||
self, directives: QueryDirectives, statistics: QueryStatistics, **config | ||
): | ||
super().__init__(directives=directives, statistics=statistics) | ||
self._full = config.get("full") | ||
self._extended = config.get("extended") | ||
|
||
@property | ||
def name(self): # pragma: no cover | ||
return "Show Functions" | ||
|
||
@property | ||
def config(self): # pragma: no cover | ||
return "" | ||
|
||
def execute(self) -> Iterable: | ||
|
||
buffer = [] | ||
|
||
for function in functions.functions(): | ||
buffer.append({"name": function, "type": "function"}) | ||
for aggregate in operators.aggregators(): | ||
buffer.append({"name": aggregate, "type": "aggregator"}) | ||
|
||
table = pyarrow.Table.from_pylist(buffer) | ||
table = Columns.create_table_metadata( | ||
table=table, | ||
expected_rows=len(buffer), | ||
name="show_columns", | ||
table_aliases=[], | ||
) | ||
|
||
yield table | ||
return |
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,30 @@ | ||
""" | ||
Test show functions works; the number of functions is constantly changing so test it's | ||
more than it was when we last reviewed this test. | ||
""" | ||
import os | ||
import sys | ||
|
||
sys.path.insert(1, os.path.join(sys.path[0], "../..")) | ||
|
||
|
||
def test_documentation_connect_example(): | ||
|
||
import opteryx | ||
|
||
conn = opteryx.connect() | ||
cur = conn.cursor() | ||
cur.execute("SHOW FUNCTIONS") | ||
rows = cur.fetchall() | ||
|
||
# below here is not in the documentation | ||
rows = list(rows) | ||
assert len(rows) > 85, len(rows) | ||
conn.close() | ||
|
||
|
||
if __name__ == "__main__": # pragma: no cover | ||
|
||
test_documentation_connect_example() | ||
|
||
print("✅ okay") |