-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRowSet.cpp
266 lines (238 loc) · 8.37 KB
/
RowSet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
Copyright (c) 2017 TOSHIBA Digital Solutions Corporation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "RowSet.h"
namespace griddb {
/**
* @brief Constructor a new RowSet::RowSet object
* @param *rowSet A pointer manages a set of Rows obtained by a query
* @param *containerInfo A pointer holding the information about a specific GSContainer
* @param *gsRow A pointer holding the information about a row related to a specific GSContainer
*/
RowSet::RowSet(GSRowSet *rowSet, GSContainerInfo *containerInfo, GSRow *gsRow) :
mRowSet(rowSet), mContainerInfo(containerInfo), mRow(gsRow),
timestamp_output_with_float(false), typeList(NULL) {
if (mRowSet != NULL) {
mType = gsGetRowSetType(mRowSet);
} else {
throw GSException(mRowSet, "mRowSet is NULL");
}
}
/**
* @brief Check if RowSet has next row data.
* @return Returns whether a Row set has at least one Row ahead of the current cursor position
*/
bool RowSet::has_next() {
GSRowSetType type;
type = this->type();
switch(type) {
case (GS_ROW_SET_CONTAINER_ROWS):
case (GS_ROW_SET_AGGREGATION_RESULT):
case (GS_ROW_SET_QUERY_ANALYSIS):
return (bool) gsHasNextRow(mRowSet);
default:
return false;
}
}
RowSet::~RowSet() {
close();
if (typeList) {
delete[] typeList;
}
}
/**
* @brief Release RowSet resource
*/
void RowSet::close() {
if (mRowSet != NULL) {
gsCloseRowSet(&mRowSet);
mRowSet = NULL;
}
}
/**
* @brief Update current row from RowSet
* @param *row A Row object representing the content of a Row to be put to database
*/
void RowSet::update(GSRow* row) {
GSResult ret = gsUpdateCurrentRow(mRowSet, mRow);
if (!GS_SUCCEEDED(ret)) {
throw GSException(mRowSet, ret);
}
}
/**
* @brief Get next row data.
* @param *hasNextRow Indicate whether there is any row in RowSet or not
*/
void RowSet::next_row(bool* hasNextRow) {
*hasNextRow = this->has_next();
if (*hasNextRow) {
GSResult ret = gsGetNextRow(mRowSet, mRow);
if (!GS_SUCCEEDED(ret)) {
throw GSException(mRowSet, ret);
}
}
}
/**
* @brief Get next row or queryAnalysis or aggResult corresponding query command
* @param *type The type of content that can be extracted from GSRowSet.
* @param *hasNextRow Indicate whether there is any row in RowSet or not
* @param **queryAnalysis Represents one of information entries composing a query plan and the results of analyzing a query operation.
* @param **aggResult Stores the result of an aggregation operation.
*/
void RowSet::next(GSRowSetType* type, bool* hasNextRow,
QueryAnalysisEntry** queryAnalysis, AggregationResult** aggResult){
assert(type != NULL);
assert(hasNextRow != NULL);
assert(queryAnalysis != NULL);
assert(aggResult != NULL);
*type = this->type();
switch(*type) {
case (GS_ROW_SET_CONTAINER_ROWS):
this->next_row(hasNextRow);
break;
case (GS_ROW_SET_AGGREGATION_RESULT):
*hasNextRow = this->has_next();
*aggResult = this->get_next_aggregation();
break;
case (GS_ROW_SET_QUERY_ANALYSIS):
*queryAnalysis = this->get_next_query_analysis();
*hasNextRow = true;
break;
default:
throw GSException(mRowSet, "type for rowset is not correct");
}
}
/**
* @brief Get size of this rowset
* @return Size of this rowset
*/
int32_t RowSet::size() {
return gsGetRowSetSize(mRowSet);
}
/**
* @brief Delete current row data.
*/
void RowSet::remove() {
GSResult ret = gsDeleteCurrentRow(mRowSet);
if (!GS_SUCCEEDED(ret)) {
throw GSException(mRowSet, ret);
}
}
/**
* @brief Moves to the next Row in a Row set and returns the aggregation result at the moved position.
* @return A pointer Stores the result of an aggregation operation.
*/
AggregationResult* RowSet::get_next_aggregation() {
GSAggregationResult* pAggResult;
GSResult ret = gsGetNextAggregation(mRowSet, &pAggResult);
if (!GS_SUCCEEDED(ret)) {
throw GSException(mRowSet, ret);
}
try {
AggregationResult* aggResult = new AggregationResult(pAggResult);
return aggResult;
} catch (bad_alloc& ba) {
gsCloseAggregationResult(&pAggResult);
throw GSException(mRowSet, "Memory allocation error");
}
}
/**
* @brief Get current row type.
* @return The type of content that can be extracted from GSRowSet.
*/
GSRowSetType RowSet::type(){
return mType;
}
/**
* @brief Get next query analysis
* @return Represents one of information entries composing a query plan and the results of analyzing a query operation.
*/
QueryAnalysisEntry* RowSet::get_next_query_analysis(){
GSQueryAnalysisEntry gsQueryAnalysis = GS_QUERY_ANALYSIS_ENTRY_INITIALIZER;
GSResult ret;
ret = gsGetNextQueryAnalysis(mRowSet, &gsQueryAnalysis);
if (!GS_SUCCEEDED(ret)) {
throw GSException(mRowSet, ret);
}
try {
QueryAnalysisEntry* queryAnalysis = new QueryAnalysisEntry(&gsQueryAnalysis);
return queryAnalysis;
} catch (bad_alloc& ba) {
throw GSException(mRowSet, "Memory allocation error");
}
}
/**
* @brief Get column name from RowSet. Use in python only.
* @param ***listName List name of column
* @param *num Number of column
*/
void RowSet::get_column_names(char*** listName, int* num){
assert(listName != NULL);
assert(num != NULL);
if (!mContainerInfo){
return;
}
//Memory will be free from typemap
try {
(*listName) = new char*[mContainerInfo->columnCount]();
*num = mContainerInfo->columnCount;
for (int i = 0; i < mContainerInfo->columnCount; i++){
if (mContainerInfo->columnInfoList[i].name) {
Util::strdup((const GSChar**)(&((*listName)[i])), mContainerInfo->columnInfoList[i].name);
} else {
(*listName)[i] = NULL;
}
}
} catch (bad_alloc& ba) {
for (int i = 0; i < mContainerInfo->columnCount; i++){
if ((*listName)[i]) {
delete[] (*listName)[i];
}
}
if ((*listName)) {
delete[] (*listName);
}
throw GSException(mRowSet, "Memory allocation error");
}
}
/**
* @brief Get list type of column in row
* @return A list type of column in row
*/
GSType* RowSet::getGSTypeList(){
if (typeList == NULL) {
try {
typeList = new GSType[mContainerInfo->columnCount]();
} catch (bad_alloc& ba) {
throw GSException(mRowSet, "Memory allocation error");
}
for (int i = 0; i < mContainerInfo->columnCount; i++){
typeList[i] = mContainerInfo->columnInfoList[i].type;
}
}
return typeList;
}
/**
* @brief Get number of column in row
* @return Number of column in row
*/
int RowSet::getColumnCount(){
return mContainerInfo->columnCount;
}
/**
* @brief Get row data in RowSet object
* @return A pointer stores row data in RowSet object
*/
GSRow* RowSet::getGSRowPtr(){
return mRow;
}
}