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

Commit 1176e24

Browse files
committed
Add ResultSetTableToken::row.
Signed-off-by: ienkovich <[email protected]>
1 parent 4acf3bf commit 1176e24

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

omniscidb/ResultSetRegistry/ResultSetTableToken.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ std::shared_ptr<arrow::Table> ResultSetTableToken::toArrow() const {
6767
return res;
6868
}
6969

70+
std::vector<TargetValue> ResultSetTableToken::row(size_t row_idx,
71+
bool translate_strings,
72+
bool decimal_to_double) const {
73+
for (size_t rs_idx = 0; rs_idx < resultSetCount(); ++rs_idx) {
74+
auto rs = resultSet(rs_idx);
75+
if (rs->rowCount() > row_idx) {
76+
return rs->getRowAt(row_idx, translate_strings, decimal_to_double);
77+
}
78+
row_idx -= rs->rowCount();
79+
}
80+
throw std::runtime_error("Out-of-bound row index.");
81+
}
82+
7083
std::string ResultSetTableToken::description() const {
7184
auto first_rs = resultSet(0);
7285
auto last_rs = resultSet(resultSetCount() - 1);

omniscidb/ResultSetRegistry/ResultSetTableToken.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class ResultSetTableToken : public std::enable_shared_from_this<ResultSetTableTo
5959

6060
std::shared_ptr<arrow::Table> toArrow() const;
6161

62+
std::vector<TargetValue> row(size_t row_idx,
63+
bool translate_strings,
64+
bool decimal_to_double) const;
65+
6266
std::string toString() const {
6367
return "ResultSetTableToken(" + std::to_string(dbId()) + ":" +
6468
std::to_string(tableId()) + ")";

python/pyhdk/_sql.pxd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from pyarrow.lib cimport CTable as CArrowTable
1212

1313
from pyhdk._common cimport CConfig, CType
1414
from pyhdk._storage cimport CSchemaProvider, CSchemaProviderPtr, CDataProvider, CDataMgr, CBufferProvider
15-
from pyhdk._execute cimport CExecutor, CResultSetPtr, CCompilationOptions, CExecutionOptions, CTargetMetaInfo
15+
from pyhdk._execute cimport CExecutor, CResultSetPtr, CCompilationOptions, CExecutionOptions, CTargetMetaInfo, CTargetValue
1616

1717
cdef extern from "omniscidb/QueryEngine/ExtensionFunctionsWhitelist.h":
1818
cdef cppclass CExtensionFunction "ExtensionFunction":
@@ -60,6 +60,8 @@ cdef extern from "omniscidb/ResultSetRegistry/ResultSetTableToken.h":
6060
string memoryDescription()
6161
string contentToString(bool)
6262

63+
vector[CTargetValue] row(size_t, bool, bool) except +
64+
6365
ctypedef shared_ptr[const CResultSetTableToken] CResultSetTableTokenPtr
6466

6567
cdef extern from "omniscidb/QueryEngine/Descriptors/RelAlgExecutionDescriptor.h":
@@ -68,7 +70,6 @@ cdef extern from "omniscidb/QueryEngine/Descriptors/RelAlgExecutionDescriptor.h"
6870
CExecutionResult(const CExecutionResult&)
6971
CExecutionResult(CExecutionResult&&)
7072

71-
const CResultSetPtr& getRows()
7273
const vector[CTargetMetaInfo]& getTargetsMeta()
7374
string getExplanation()
7475
const string& tableName()

python/pyhdk/_sql.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ cdef class ExecutionResult:
109109

110110
def row(self, row_id):
111111
res = []
112-
cdef vector[CTargetValue] vals = self.c_result.getRows().get().getRowAt(row_id, True, True)
112+
cdef vector[CTargetValue] vals = self.c_result.getToken().get().row(row_id, True, True)
113113
cdef vector[CTargetValue].const_iterator it = vals.const_begin()
114114
cdef const CScalarTargetValue *scalar
115115
cdef const CArrayTargetValue *array

0 commit comments

Comments
 (0)