-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from georgia-tech-db/limit
Limit Implementation
- Loading branch information
Showing
16 changed files
with
417 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2020 EVA | ||
# | ||
# 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. | ||
from typing import Iterator | ||
|
||
from src.models.storage.batch import Batch | ||
from src.executor.abstract_executor import AbstractExecutor | ||
from src.planner.limit_plan import LimitPlan | ||
from src.configuration.configuration_manager import ConfigurationManager | ||
|
||
|
||
class LimitExecutor(AbstractExecutor): | ||
""" | ||
Limits the number of rows returned | ||
Arguments: | ||
node (AbstractPlan): The Limit Plan | ||
""" | ||
|
||
def __init__(self, node: LimitPlan): | ||
super().__init__(node) | ||
self._limit_count = node.limit_value | ||
self.BATCH_MAX_SIZE = ConfigurationManager().get_value( | ||
"executor", "batch_size") | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self) -> Iterator[Batch]: | ||
child_executor = self.children[0] | ||
remaining_tuples = self._limit_count | ||
# aggregates the batches into one large batch | ||
for batch in child_executor.exec(): | ||
if len(batch) > remaining_tuples: | ||
yield batch[:remaining_tuples] | ||
return | ||
|
||
remaining_tuples -= len(batch) | ||
yield batch |
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
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,42 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2020 EVA | ||
# | ||
# 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. | ||
|
||
from src.planner.abstract_plan import AbstractPlan | ||
from src.planner.types import PlanNodeType | ||
from src.expression.constant_value_expression import ConstantValueExpression | ||
|
||
|
||
class LimitPlan(AbstractPlan): | ||
""" | ||
This plan is used for storing information required for limit | ||
operations. | ||
Arguments: | ||
limit_count: ConstantValueExpression | ||
A ConstantValueExpression which is the count of the | ||
number of rows returned | ||
""" | ||
|
||
def __init__(self, limit_count: ConstantValueExpression): | ||
self._limit_count = limit_count | ||
super().__init__(PlanNodeType.LIMIT) | ||
|
||
@property | ||
def limit_expression(self): | ||
return self._limit_count | ||
|
||
@property | ||
def limit_value(self): | ||
return self._limit_count.value |
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 |
---|---|---|
|
@@ -26,4 +26,5 @@ class PlanNodeType(IntEnum): | |
LOAD_DATA = 7 | ||
UNION = 8 | ||
ORDER_BY = 9 | ||
LIMIT = 10 | ||
# add other types |
Oops, something went wrong.