/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/util/statement_result.h
Line | Count | Source (jump to first uncovered line) |
1 | | //-------------------------------------------------------------------------------------------------- |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | // Different results of processing a statement. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #ifndef YB_YQL_CQL_QL_UTIL_STATEMENT_RESULT_H_ |
19 | | #define YB_YQL_CQL_QL_UTIL_STATEMENT_RESULT_H_ |
20 | | |
21 | | #include "yb/client/client_fwd.h" |
22 | | #include "yb/client/yb_table_name.h" |
23 | | |
24 | | #include "yb/common/common_fwd.h" |
25 | | #include "yb/common/value.pb.h" |
26 | | |
27 | | #include "yb/gutil/callback_forward.h" |
28 | | |
29 | | namespace yb { |
30 | | namespace ql { |
31 | | |
32 | | // This module is included by a few outside classes, so we cannot include ptree header files here. |
33 | | // Use forward declaration. |
34 | | class PTDmlStmt; |
35 | | class PTListNode; |
36 | | |
37 | | //------------------------------------------------------------------------------------------------ |
38 | | // Result of preparing a statement. Only DML statement will return a prepared result that describes |
39 | | // the schemas of the bind variables used and, for SELECT statement, the schemas of the columns |
40 | | // selected. |
41 | | class PreparedResult { |
42 | | public: |
43 | | // Public types. |
44 | | typedef std::unique_ptr<PreparedResult> UniPtr; |
45 | | typedef std::unique_ptr<const PreparedResult> UniPtrConst; |
46 | | |
47 | | // Constructors. |
48 | | explicit PreparedResult(const PTDmlStmt& stmt); |
49 | | explicit PreparedResult(const PTListNode& stmt); |
50 | | virtual ~PreparedResult(); |
51 | | |
52 | | // Accessors. |
53 | 4.86k | const client::YBTableName& table_name() const { return table_name_; } |
54 | 4.51k | const std::vector<client::YBTableName>& bind_table_names() const { return bind_table_names_; } |
55 | 4.51k | const std::vector<ColumnSchema>& bind_variable_schemas() const { return bind_variable_schemas_; } |
56 | 4.52k | const std::vector<int64_t>& hash_col_indices() const { return hash_col_indices_; } |
57 | 4.86k | const std::vector<ColumnSchema>& column_schemas() const { return *column_schemas_; } |
58 | | |
59 | | private: |
60 | | const client::YBTableName table_name_; |
61 | | std::vector<client::YBTableName> bind_table_names_; |
62 | | std::vector<ColumnSchema> bind_variable_schemas_; |
63 | | std::vector<int64_t> hash_col_indices_; |
64 | | std::shared_ptr<std::vector<ColumnSchema>> column_schemas_; |
65 | | }; |
66 | | |
67 | | //------------------------------------------------------------------------------------------------ |
68 | | // Result of executing a statement. Different possible types of results are listed below. |
69 | | class ExecutedResult { |
70 | | public: |
71 | | // Public types. |
72 | | typedef std::shared_ptr<ExecutedResult> SharedPtr; |
73 | | typedef std::shared_ptr<const ExecutedResult> SharedPtrConst; |
74 | | |
75 | | // Constructors. |
76 | 3.95M | ExecutedResult() { } |
77 | 3.91M | virtual ~ExecutedResult() { } |
78 | | |
79 | | // Execution result types. |
80 | | enum class Type { |
81 | | SET_KEYSPACE = 1, |
82 | | ROWS = 2, |
83 | | SCHEMA_CHANGE = 3 |
84 | | }; |
85 | | |
86 | | virtual Type type() const = 0; |
87 | | }; |
88 | | |
89 | | // Callback to be called after a statement is executed. When execution fails, a not-ok status is |
90 | | // passed. When it succeeds, an ok status and the execution result are passed. When there is no |
91 | | // result (i.e. void), a nullptr is passed. |
92 | | typedef Callback<void(const Status&, const ExecutedResult::SharedPtr&)> StatementExecutedCallback; |
93 | | |
94 | | //------------------------------------------------------------------------------------------------ |
95 | | // Result of "USE <keyspace>" statement. |
96 | | class SetKeyspaceResult : public ExecutedResult { |
97 | | public: |
98 | | // Public types. |
99 | | typedef std::shared_ptr<SetKeyspaceResult> SharedPtr; |
100 | | typedef std::shared_ptr<const SetKeyspaceResult> SharedPtrConst; |
101 | | |
102 | | // Constructors. |
103 | 4.18k | explicit SetKeyspaceResult(const std::string& keyspace) : keyspace_(keyspace) { } |
104 | 4.18k | virtual ~SetKeyspaceResult() override { }; |
105 | | |
106 | | // Result type. |
107 | 4.18k | Type type() const override { return Type::SET_KEYSPACE; } |
108 | | |
109 | | // Accessor function for keyspace. |
110 | 4.18k | const std::string& keyspace() const { return keyspace_; } |
111 | | |
112 | | private: |
113 | | const std::string keyspace_; |
114 | | }; |
115 | | |
116 | | //------------------------------------------------------------------------------------------------ |
117 | | // Result of rows returned from executing a DML statement. |
118 | | class RowsResult : public ExecutedResult { |
119 | | public: |
120 | | // Public types. |
121 | | typedef std::shared_ptr<RowsResult> SharedPtr; |
122 | | typedef std::shared_ptr<const RowsResult> SharedPtrConst; |
123 | | |
124 | | // Constructors. |
125 | | explicit RowsResult(const PTDmlStmt *tnode); // construct empty rows result for the statement. |
126 | | explicit RowsResult(client::YBqlOp *op, const PTDmlStmt *tnode = nullptr); |
127 | | RowsResult(const client::YBTableName& table_name, |
128 | | const std::shared_ptr<std::vector<ColumnSchema>>& column_schemas, |
129 | | const std::string& rows_data); |
130 | | virtual ~RowsResult() override; |
131 | | |
132 | | // Result type. |
133 | 3.72M | Type type() const override { return Type::ROWS; } |
134 | | |
135 | | // Accessor functions. |
136 | 3.72M | const client::YBTableName& table_name() const { return table_name_; } |
137 | 3.72M | const std::vector<ColumnSchema>& column_schemas() const { return *column_schemas_; } |
138 | | void set_column_schema(int col_index, const std::shared_ptr<QLType>& type); |
139 | 0 | const std::string& rows_data() const { return rows_data_; } |
140 | 15.0M | std::string& rows_data() { return rows_data_; } |
141 | 64 | void set_rows_data(const char *str, size_t size) { rows_data_.assign(str, size); } |
142 | 7.95M | const std::string& paging_state() const { return paging_state_; } |
143 | 213 | QLClient client() const { return client_; } |
144 | | |
145 | | CHECKED_STATUS Append(RowsResult&& other); |
146 | | |
147 | | void SetPagingState(client::YBqlOp *op); |
148 | | void SetPagingState(const QLPagingStatePB& paging_state); |
149 | | void SetPagingState(RowsResult&& other); |
150 | | void ClearPagingState(); |
151 | 648 | bool has_paging_state() { return !paging_state_.empty(); } |
152 | | |
153 | | // Parse the rows data and return it as a row block. It is the caller's responsibility to free |
154 | | // the row block after use. |
155 | | std::unique_ptr<QLRowBlock> GetRowBlock() const; |
156 | | |
157 | | private: |
158 | | const client::YBTableName table_name_; |
159 | | std::shared_ptr<std::vector<ColumnSchema>> column_schemas_; |
160 | | const QLClient client_; |
161 | | std::string rows_data_; |
162 | | std::string paging_state_; |
163 | | }; |
164 | | |
165 | | //------------------------------------------------------------------------------------------------ |
166 | | // Result of a schema object being changed as a result of executing a DDL statement. |
167 | | class SchemaChangeResult : public ExecutedResult { |
168 | | public: |
169 | | // Public types. |
170 | | typedef std::shared_ptr<SchemaChangeResult> SharedPtr; |
171 | | typedef std::shared_ptr<const SchemaChangeResult> SharedPtrConst; |
172 | | |
173 | | // Constructors. |
174 | | SchemaChangeResult( |
175 | | const std::string& change_type, const std::string& object_type, |
176 | | const std::string& keyspace_name, const std::string& object_name = ""); |
177 | | virtual ~SchemaChangeResult() override; |
178 | | |
179 | | // Result type. |
180 | 6.05k | Type type() const override { return Type::SCHEMA_CHANGE; } |
181 | | |
182 | | // Accessor functions. |
183 | 6.05k | const std::string& change_type() const { return change_type_; } |
184 | 6.05k | const std::string& object_type() const { return object_type_; } |
185 | 6.05k | const std::string& keyspace_name() const { return keyspace_name_; } |
186 | 6.05k | const std::string& object_name() const { return object_name_; } |
187 | | |
188 | | private: |
189 | | const std::string change_type_; |
190 | | const std::string object_type_; |
191 | | const std::string keyspace_name_; |
192 | | const std::string object_name_; |
193 | | }; |
194 | | |
195 | | } // namespace ql |
196 | | } // namespace yb |
197 | | |
198 | | #endif // YB_YQL_CQL_QL_UTIL_STATEMENT_RESULT_H_ |