Skip to content

Commit

Permalink
Make PlanExecutor more Pythonic
Browse files Browse the repository at this point in the history
  • Loading branch information
LordDarkula committed Sep 12, 2023
1 parent 0f1bcf6 commit 45b42f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion evadb/executor/plan_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _build_execution_tree(

return executor_node

def execute_plan(
def __call__(
self,
do_not_raise_exceptions: bool = False,
do_not_print_exceptions: bool = False,
Expand Down
7 changes: 4 additions & 3 deletions evadb/interfaces/relational/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def sql_predicate_to_expresssion_tree(expr: str) -> AbstractExpression:

def execute_statement(evadb: EvaDBDatabase, statement: AbstractStatement) -> Batch:
StatementBinder(StatementBinderContext(evadb.catalog)).bind(statement)
l_plan = StatementToPlanConverter().visit(statement)
p_plan = PlanGenerator(evadb).build(l_plan)
output = PlanExecutor(evadb, p_plan).execute_plan()
logical_plan = StatementToPlanConverter().visit(statement)
physical_plan = PlanGenerator(evadb).build(logical_plan)
plan_executor = PlanExecutor(evadb, physical_plan)
output = plan_executor()
if output:
batch_list = list(output)
return Batch.concat(batch_list, copy=False)
Expand Down
11 changes: 5 additions & 6 deletions evadb/server/command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ def execute_query(
# executor.
if not isinstance(stmt, SKIP_BINDER_AND_OPTIMIZER_STATEMENTS):
StatementBinder(StatementBinderContext(evadb.catalog)).bind(stmt)
l_plan = StatementToPlanConverter().visit(stmt)
p_plan = plan_generator.build(l_plan)
logical_plan = StatementToPlanConverter().visit(stmt)
physical_plan = plan_generator.build(logical_plan)
else:
p_plan = stmt
output = PlanExecutor(evadb, p_plan).execute_plan(
do_not_raise_exceptions, do_not_print_exceptions
)
physical_plan = stmt
plan_executor = PlanExecutor(evadb, physical_plan)
output = plan_executor(do_not_raise_exceptions, do_not_print_exceptions)

if report_time is True:
query_compile_time.log_elapsed_time("Query Compile Time")
Expand Down
18 changes: 9 additions & 9 deletions test/executor/test_plan_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_execute_plan_for_seq_scan_plan(self, mock_build):
tree.exec.return_value = batch_list
mock_build.return_value = tree

actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
mock_build.assert_called_once_with(None)

tree.exec.assert_called_once()
Expand All @@ -150,7 +150,7 @@ def test_execute_plan_for_pp_scan_plan(self, mock_build):
tree.exec.return_value = batch_list
mock_build.return_value = tree

actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
mock_build.assert_called_once_with(None)

tree.exec.assert_called_once()
Expand All @@ -161,7 +161,7 @@ def test_execute_plan_for_create_insert_load_upload_plans(self, mock_build):
# CreateExecutor
tree = MagicMock(node=CreatePlan(None, [], False))
mock_build.return_value = tree
actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
tree.exec.assert_called_once()
mock_build.assert_called_once_with(None)

Expand All @@ -172,7 +172,7 @@ def test_execute_plan_for_create_insert_load_upload_plans(self, mock_build):

tree = MagicMock(node=InsertPlan(0, [], []))
mock_build.return_value = tree
actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
tree.exec.assert_called_once()
mock_build.assert_called_once_with(None)

Expand All @@ -183,7 +183,7 @@ def test_execute_plan_for_create_insert_load_upload_plans(self, mock_build):

tree = MagicMock(node=CreateUDFPlan(None, False, [], [], None))
mock_build.return_value = tree
actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
tree.exec.assert_called_once()
mock_build.assert_called_once_with(None)

Expand All @@ -194,7 +194,7 @@ def test_execute_plan_for_create_insert_load_upload_plans(self, mock_build):

tree = MagicMock(node=LoadDataPlan(None, None, None, None, None))
mock_build.return_value = tree
actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
tree.exec.assert_called_once()
mock_build.assert_called_once_with(None)

Expand All @@ -205,7 +205,7 @@ def test_execute_plan_for_rename_plans(self, mock_build):
# RenameExecutor
tree = MagicMock(node=RenamePlan(None, None))
mock_build.return_value = tree
actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
tree.exec.assert_called_once()
mock_build.assert_called_once_with(None)

Expand All @@ -216,7 +216,7 @@ def test_execute_plan_for_drop_plans(self, mock_build):
# DropExecutor
tree = MagicMock(node=DropObjectPlan(None, None, None))
mock_build.return_value = tree
actual = list(PlanExecutor(MagicMock(), None).execute_plan())
actual = list(PlanExecutor(MagicMock(), None)())
tree.exec.assert_called_once()
mock_build.assert_called_once_with(None)

Expand All @@ -243,7 +243,7 @@ def test_should_return_the_new_path_after_execution(self, mock_class):

# Execute the plan
executor = PlanExecutor(seq_scan)
actual = executor.execute_plan()
actual = executor()
expected = batch_1[::2] + batch_2[::2]

mock_class.assert_called_once()
Expand Down

0 comments on commit 45b42f8

Please sign in to comment.