Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit 14e20f1

Browse files
committed
Add python support for explain, which returns LLVM IR for the query
1 parent 4c98519 commit 14e20f1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

python/pyhdk/_sql.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ cdef extern from "omniscidb/QueryEngine/Descriptors/RelAlgExecutionDescriptor.h"
7373

7474
const CResultSetPtr& getRows()
7575
const vector[CTargetMetaInfo]& getTargetsMeta()
76+
string getExplanation()
7677

7778
cdef extern from "omniscidb/QueryEngine/RelAlgExecutor.h":
7879
cdef cppclass CRelAlgExecutor "RelAlgExecutor":

python/pyhdk/_sql.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ cdef class ExecutionResult:
7474
cdef shared_ptr[CArrowTable] at = converter.get().convertToArrowTable()
7575
return pyarrow_wrap_table(at)
7676

77+
def to_explain_str(self):
78+
return self.c_result.getExplanation()
79+
7780
cdef class RelAlgExecutor:
7881
cdef shared_ptr[CRelAlgExecutor] c_rel_alg_executor
7982
# DataMgr is used only to pass it to each produced ExecutionResult
@@ -108,6 +111,7 @@ cdef class RelAlgExecutor:
108111
c_eo.output_columnar_hint = kwargs.get("enable_columnar_output", g_enable_columnar_output)
109112
c_eo.with_watchdog = kwargs.get("enable_watchdog", g_enable_watchdog)
110113
c_eo.with_dynamic_watchdog = kwargs.get("enable_dynamic_watchdog", g_enable_dynamic_watchdog)
114+
c_eo.just_explain = kwargs.get("just_explain", False)
111115
cdef CExecutionResult c_res = self.c_rel_alg_executor.get().executeRelAlgQuery(c_co, c_eo, False)
112116
cdef ExecutionResult res = ExecutionResult()
113117
res.c_result = move(c_res)

python/tests/test_pyhdk_sql.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ def teardown_class(cls):
2929
del cls.storage
3030

3131
@classmethod
32-
def execute_sql(cls, sql):
32+
def execute_sql(cls, sql, **kwargs):
3333
ra = cls.calcite.process(sql)
3434
rel_alg_executor = pyhdk.sql.RelAlgExecutor(
3535
cls.executor, cls.storage, cls.data_mgr, ra
3636
)
37-
return rel_alg_executor.execute()
37+
return rel_alg_executor.execute(**kwargs)
3838

3939
def test_simple_projection(self):
4040
res = self.execute_sql("SELECT * FROM test;")
4141
df = res.to_arrow().to_pandas()
4242
assert df.shape == (3, 2)
4343
assert df["a"].tolist() == [1, 2, 3]
4444
assert df["b"].tolist() == [10, 20, 30]
45+
46+
def test_explain(self):
47+
res = self.execute_sql("SELECT * FROM test;", just_explain = True)
48+
explain_str = res.to_explain_str()
49+
assert (explain_str[:15] == "IR for the CPU:")

0 commit comments

Comments
 (0)