-
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.
- Loading branch information
Showing
56 changed files
with
1,894 additions
and
141 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import List | ||
from eva.expression.abstract_expression import AbstractExpression | ||
from eva.models.storage.batch import Batch | ||
|
||
|
||
def apply_project(batch: Batch, project_list: List[AbstractExpression]): | ||
if not batch.empty() and project_list: | ||
batches = [expr.evaluate(batch) for expr in project_list] | ||
batch = Batch.merge_column_wise(batches) | ||
return batch | ||
|
||
|
||
def apply_predicate(batch: Batch, predicate: AbstractExpression): | ||
if not batch.empty() and predicate is not None: | ||
outcomes = predicate.evaluate(batch).frames | ||
batch = Batch( | ||
batch.frames[(outcomes > 0).to_numpy()].reset_index(drop=True)) | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 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 eva.planner.function_scan_plan import FunctionScanPlan | ||
from eva.executor.abstract_executor import AbstractExecutor | ||
from eva.models.storage.batch import Batch | ||
|
||
|
||
class FunctionScanExecutor(AbstractExecutor): | ||
""" | ||
Executes functional expression which yields a table of rows | ||
Arguments: | ||
node (AbstractPlan): FunctionScanPlan | ||
""" | ||
|
||
def __init__(self, node: FunctionScanPlan): | ||
super().__init__(node) | ||
self.func_expr = node.func_expr | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self, *args, **kwargs) -> Iterator[Batch]: | ||
print(kwargs) | ||
assert 'lateral_input' in kwargs, ( | ||
'Key lateral_input not passed to the FunctionScan') | ||
lateral_input = kwargs.get('lateral_input') | ||
if not lateral_input.empty(): | ||
res = self.func_expr.evaluate(lateral_input) | ||
|
||
if not res.empty(): | ||
yield res |
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,53 @@ | ||
# 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 eva.executor.executor_utils import apply_predicate, apply_project | ||
|
||
from eva.models.storage.batch import Batch | ||
from eva.executor.abstract_executor import AbstractExecutor | ||
from eva.planner.hash_join_probe_plan import HashJoinProbePlan | ||
|
||
|
||
class HashJoinExecutor(AbstractExecutor): | ||
|
||
def __init__(self, node: HashJoinProbePlan): | ||
super().__init__(node) | ||
self.predicate = node.join_predicate | ||
self.join_type = node.join_type | ||
self.probe_keys = node.probe_keys | ||
self.join_project = node.join_project | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self, *args, **kwargs) -> Iterator[Batch]: | ||
|
||
build_table = self.children[0] | ||
probe_table = self.children[1] | ||
hash_keys = [key.col_alias for key in self.probe_keys] | ||
for build_batch in build_table.exec(): | ||
for probe_batch in probe_table.exec(): | ||
probe_batch.frames.index = probe_batch.frames[ | ||
hash_keys].apply( | ||
lambda x: hash(tuple(x)), axis=1) | ||
join_batch = probe_batch.frames.merge(build_batch.frames, | ||
left_index=True, | ||
right_index=True, | ||
how='inner') | ||
join_batch.reset_index(drop=True, inplace=True) | ||
join_batch = Batch(join_batch) | ||
join_batch = apply_predicate(join_batch, self.predicate) | ||
join_batch = apply_project(join_batch, self.join_project) | ||
yield join_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Iterator | ||
|
||
from eva.models.storage.batch import Batch | ||
|
||
from eva.executor.abstract_executor import AbstractExecutor | ||
from eva.planner.hash_join_build_plan import HashJoinBuildPlan | ||
|
||
|
||
class BuildJoinExecutor(AbstractExecutor): | ||
def __init__(self, node: HashJoinBuildPlan): | ||
super().__init__(node) | ||
self.predicate = None # node.join_predicate | ||
self.join_type = node.join_type | ||
self.build_keys = node.build_keys | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self, *args, **kwargs) -> Iterator[Batch]: | ||
child_executor = self.children[0] | ||
# build in memory hash table and pass to the probe phase | ||
# Assumption the hash table fits in memory | ||
# Todo: Implement a partition based hash join (grace hash join) | ||
cumm_batches = [batch for batch in child_executor.exec() | ||
if not batch.empty()] | ||
cumm_batches = Batch.concat(cumm_batches) | ||
hash_keys = [key.col_alias for key in self.build_keys] | ||
cumm_batches.frames.index = cumm_batches.frames[hash_keys].apply( | ||
lambda x: hash(tuple(x)), axis=1) | ||
yield cumm_batches |
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,46 @@ | ||
# 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 eva.executor.executor_utils import apply_predicate, apply_project | ||
|
||
from eva.models.storage.batch import Batch | ||
from eva.executor.abstract_executor import AbstractExecutor | ||
from eva.planner.lateral_join_plan import LateralJoinPlan | ||
|
||
|
||
class LateralJoinExecutor(AbstractExecutor): | ||
|
||
def __init__(self, node: LateralJoinPlan): | ||
super().__init__(node) | ||
self.predicate = node.join_predicate | ||
self.join_project = node.join_project | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self, *args, **kwargs) -> Iterator[Batch]: | ||
|
||
outer = self.children[0] | ||
inner = self.children[1] | ||
|
||
for outer_batch in outer.exec(): | ||
for result_batch in inner.exec(lateral_input=outer_batch): | ||
# merge | ||
result_batch = Batch.merge_column_wise( | ||
[outer_batch, result_batch]) | ||
result_batch = apply_predicate(result_batch, self.predicate) | ||
result_batch = apply_project(result_batch, self.join_project) | ||
if not result_batch.empty(): | ||
return result_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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 eva.executor.executor_utils import apply_predicate | ||
|
||
from eva.models.storage.batch import Batch | ||
from eva.executor.abstract_executor import AbstractExecutor | ||
from eva.planner.predicate_plan import PredicatePlan | ||
|
||
|
||
class PredicateExecutor(AbstractExecutor): | ||
""" | ||
""" | ||
|
||
def __init__(self, node: PredicatePlan): | ||
super().__init__(node) | ||
self.predicate = node.predicate | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self) -> Iterator[Batch]: | ||
child_executor = self.children[0] | ||
for batch in child_executor.exec(): | ||
batch = apply_predicate(batch, self.predicate) | ||
if not batch.empty(): | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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 eva.executor.executor_utils import apply_project | ||
|
||
from eva.models.storage.batch import Batch | ||
from eva.executor.abstract_executor import AbstractExecutor | ||
from eva.planner.project_plan import ProjectPlan | ||
|
||
|
||
class ProjectExecutor(AbstractExecutor): | ||
""" | ||
""" | ||
|
||
def __init__(self, node: ProjectPlan): | ||
super().__init__(node) | ||
self.target_list = node.target_list | ||
|
||
def validate(self): | ||
pass | ||
|
||
def exec(self) -> Iterator[Batch]: | ||
child_executor = self.children[0] | ||
for batch in child_executor.exec(): | ||
batch = apply_project(batch, self.target_list) | ||
|
||
if not batch.empty(): | ||
yield batch |
Oops, something went wrong.