-
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
6 changed files
with
96 additions
and
10 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
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,62 @@ | ||
# 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. | ||
|
||
""" | ||
Exit Node | ||
This is a SQL Query Execution Plan Node. | ||
This does the final preparation before returning results to users. | ||
This does two things that the projection node doesn't do: | ||
- renames columns from the internal names | ||
- removes all columns not being returned to the user | ||
This node doesn't do any calculations, it is a pure Projection. | ||
""" | ||
from typing import Iterable | ||
|
||
from opteryx.exceptions import SqlError | ||
from opteryx.models import QueryProperties | ||
from opteryx.operators import BasePlanNode | ||
|
||
|
||
class ExitNode(BasePlanNode): | ||
def __init__(self, properties: QueryProperties, **config): | ||
super().__init__(properties=properties) | ||
self.columns = config["columns"] | ||
|
||
@property | ||
def config(self): # pragma: no cover | ||
return None | ||
|
||
@property | ||
def name(self): # pragma: no cover | ||
return "Exit" | ||
|
||
def execute(self) -> Iterable: | ||
if len(self._producers) != 1: # pragma: no cover | ||
raise SqlError(f"{self.name} expects a single producer") | ||
|
||
morsels = self._producers[0] # type:ignore | ||
|
||
final_columns = [] | ||
final_names = [] | ||
for column in self.columns: | ||
final_columns.append(str(column.source_column)) | ||
final_names.append(column.query_column) | ||
|
||
for morsel in morsels.execute(): | ||
morsel = morsel.select(final_columns) | ||
morsel = morsel.rename_columns(final_names) | ||
|
||
yield morsel |