/Users/deen/code/yugabyte-db/src/yb/common/ql_resultset.h
Line | Count | Source (jump to first uncovered line) |
1 | | //-------------------------------------------------------------------------------------------------- |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // This module defines the ResultSet that QL database returns to a query request. |
5 | | // QLResultSet is a set of rows of data that is returned by a query request. |
6 | | // - Within our code, we call it "rsrow" instead of row to distinguish between selected-rows and |
7 | | // rows of a table in the database. |
8 | | // - Similarly, we use "rscol" in place of "column". |
9 | | // - To end users, at a high level interface, we would call them all as rows & columns. |
10 | | // |
11 | | // NOTE: |
12 | | // - This should be merged or shared a super class with ql_rowblock.cc. |
13 | | // - This will be done in the next diff. We don't do this now to avoid large code modifications. |
14 | | // - For optimization, columns and rows are serialized (in CQL wire format) directly for return to |
15 | | // call. If there is a need to manipulate the rows before return, QLResultSet should be changed to |
16 | | // an interface with multiple implementations for different use-cases. |
17 | | //-------------------------------------------------------------------------------------------------- |
18 | | |
19 | | #ifndef YB_COMMON_QL_RESULTSET_H_ |
20 | | #define YB_COMMON_QL_RESULTSET_H_ |
21 | | |
22 | | #include "yb/common/common_fwd.h" |
23 | | #include "yb/common/ql_type.h" |
24 | | |
25 | | namespace yb { |
26 | | |
27 | | class faststring; |
28 | | |
29 | | //-------------------------------------------------------------------------------------------------- |
30 | | // A rsrow descriptor represents the metadata of a row in the resultset. |
31 | | class QLRSRowDesc { |
32 | | public: |
33 | | class RSColDesc { |
34 | | public: |
35 | | explicit RSColDesc(const QLRSColDescPB& desc_pb); |
36 | | |
37 | 0 | const std::string& name() const { |
38 | 0 | return name_; |
39 | 0 | } |
40 | 45.3M | const QLType::SharedPtr& ql_type() const { |
41 | 45.3M | return ql_type_; |
42 | 45.3M | } |
43 | | private: |
44 | | std::string name_; |
45 | | QLType::SharedPtr ql_type_; |
46 | | }; |
47 | | |
48 | | explicit QLRSRowDesc(const QLRSRowDescPB& desc_pb); |
49 | | virtual ~QLRSRowDesc(); |
50 | | |
51 | 0 | size_t rscol_count() const { |
52 | 0 | return rscol_descs_.size(); |
53 | 0 | } |
54 | | |
55 | 45.3M | const std::vector<RSColDesc>& rscol_descs() const { |
56 | 45.3M | return rscol_descs_; |
57 | 45.3M | } |
58 | | |
59 | | private: |
60 | | std::vector<RSColDesc> rscol_descs_; |
61 | | }; |
62 | | |
63 | | //-------------------------------------------------------------------------------------------------- |
64 | | // A set of rows. |
65 | | class QLResultSet { |
66 | | public: |
67 | | typedef std::shared_ptr<QLResultSet> SharedPtr; |
68 | | |
69 | | // Constructor and destructor. |
70 | | QLResultSet(const QLRSRowDesc* rsrow_desc, faststring* rows_data); |
71 | | virtual ~QLResultSet(); |
72 | | |
73 | | // Allocate a new row at the end of result set. |
74 | | void AllocateRow(); |
75 | | |
76 | | // Append a column to the last row in the result set. |
77 | | void AppendColumn(size_t index, const QLValue& value); |
78 | | void AppendColumn(size_t index, const QLValuePB& value); |
79 | | |
80 | | // Row count |
81 | | size_t rsrow_count() const; |
82 | | |
83 | | private: |
84 | | const QLRSRowDesc* rsrow_desc_ = nullptr; |
85 | | faststring* rows_data_ = nullptr; |
86 | | }; |
87 | | |
88 | | } // namespace yb |
89 | | |
90 | | #endif // YB_COMMON_QL_RESULTSET_H_ |