Skip to content

Commit eb3cc2d

Browse files
pedroerpfacebook-github-bot
authored andcommitted
feat(python): Support printPlanWithStats API (#12428)
Summary: Pull Request resolved: #12428 Add Python API to print the plan executed along with task stats. Reviewed By: kostasxmeta Differential Revision: D70029859 fbshipit-source-id: 0d30a19be42d732f5bb5ac7b15ffd716c2137e7b
1 parent d6e23e0 commit eb3cc2d

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

velox/py/runner/PyLocalRunner.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "velox/core/PlanNode.h"
2222
#include "velox/dwio/common/Options.h"
2323
#include "velox/dwio/dwrf/writer/Writer.h"
24+
#include "velox/exec/PlanNodeStats.h"
2425
#include "velox/py/vector/PyVector.h"
2526

2627
namespace facebook::velox::py {
@@ -111,6 +112,11 @@ py::iterator PyLocalRunner::execute() {
111112
return py::make_iterator(pyIterator_->begin(), pyIterator_->end());
112113
}
113114

115+
std::string PyLocalRunner::printPlanWithStats() const {
116+
return exec::printPlanWithStats(
117+
*planNode_, cursor_->task()->taskStats(), true);
118+
}
119+
114120
void drainAllTasks() {
115121
auto& executor = folly::QueuedImmediateExecutor::instance();
116122
std::lock_guard<std::mutex> guard(taskRegistryLock());

velox/py/runner/PyLocalRunner.h

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class PyLocalRunner {
5454
/// Execute the task and returns an iterable to the output vectors.
5555
pybind11::iterator execute();
5656

57+
/// Prints a descriptive debug message containing plan and execution stats.
58+
/// If the task hasn't finished, will print the plan with the current stats.
59+
std::string printPlanWithStats() const;
60+
5761
private:
5862
friend class PyTaskIterator;
5963

velox/py/runner/runner.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ PYBIND11_MODULE(runner, m) {
4343
return velox::py::PyLocalRunner{planNode, rootPool, executor};
4444
}))
4545
.def("execute", &velox::py::PyLocalRunner::execute)
46+
.def(
47+
"print_plan_with_stats",
48+
&velox::py::PyLocalRunner::printPlanWithStats,
49+
py::doc(R"(
50+
Prints a descriptive debug message containing plan and execution
51+
stats. Needs to called after the task has finished.
52+
)"))
4653
.def(
4754
"add_file_split",
4855
&velox::py::PyLocalRunner::addFileSplit,

velox/py/runner/runner.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class LocalRunner:
2525
def __init__(self, PlanNode) -> None: ...
2626
def execute(self) -> Iterator[Vector]: ...
2727
def add_file_split(self, plan_id: str, file_path: str) -> None: ...
28+
def print_plan_with_stats(self) -> str: ...
2829

2930
def register_hive(str) -> None: ...
3031
def register_tpch(str) -> None: ...

velox/py/tests/test_runner.py

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def test_write_read_file(self):
145145
iterator = runner.execute()
146146
output = next(iterator)
147147
self.assertRaises(StopIteration, next, iterator)
148+
self.assertNotEqual(runner.print_plan_with_stats(), "")
148149

149150
output_file_from_table_writer = self.extract_file(output)
150151
self.assertEqual(output_file, output_file_from_table_writer)

0 commit comments

Comments
 (0)