forked from griddb/python_client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRowSet.cpp
More file actions
194 lines (176 loc) · 5.49 KB
/
RowSet.cpp
File metadata and controls
194 lines (176 loc) · 5.49 KB
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
/*
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"
#include "GSException.h"
#include "QueryAnalysisEntry.h"
namespace griddb {
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");
}
}
/**
* Check if RowSet has next row data. Convert from gsHasNextRow.
*/
bool RowSet::has_next() {
GSRowSetType type;
bool hasNextRow = false;
type = this->type();
switch(type) {
case (GS_ROW_SET_CONTAINER_ROWS):
case (GS_ROW_SET_AGGREGATION_RESULT):
return (bool) gsHasNextRow(mRowSet);
break;
default:
return true;
break;
}
}
RowSet::~RowSet() {
close();
if (typeList) {
free(typeList);
}
}
/**
* Close rowset.
*/
void RowSet::close() {
if (mRowSet != NULL) {
gsCloseRowSet(&mRowSet);
mRowSet = NULL;
}
}
/**
* Update current row from RowSet
*/
void RowSet::update(Row* row) {
row->set_for_row(mRow);
GSResult ret = gsUpdateCurrentRow(mRowSet, mRow);
if (ret != GS_RESULT_OK) {
throw GSException(mRowSet, ret);
}
}
/**
* Get next row data. Convert from gsGetNextRow.
*/
void RowSet::next_row(Row* rowdata, bool* hasNextRow) {
*hasNextRow = this->has_next();
if (*hasNextRow) {
GSResult ret = gsGetNextRow(mRowSet, mRow);
if (ret != GS_RESULT_OK) {
throw GSException(mRowSet, ret);
}
rowdata->set_from_row(mRow);
}
}
/**
* Get next row
*/
void RowSet::next(GSRowSetType* type, Row* row, bool* hasNextRow,
QueryAnalysisEntry** queryAnalysis, AggregationResult** aggResult){
*type = this->type();
switch(*type) {
case (GS_ROW_SET_CONTAINER_ROWS):
this->next_row(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;
}
}
/**
* Return size of this rowset
*/
int32_t RowSet::size() {
return gsGetRowSetSize(mRowSet);
}
/**
* Delete current row data. Convert from C-API: gsDeleteCurrentRow.
*/
void RowSet::remove() {
GSResult ret = gsDeleteCurrentRow(mRowSet);
if (ret != GS_RESULT_OK) {
throw GSException(mRowSet, ret);
}
}
/**
* Moves to the next Row in a Row set and returns the aggregation result at the moved position.
*/
AggregationResult* RowSet::get_next_aggregation() {
GSAggregationResult* pAggResult;
GSResult ret = gsGetNextAggregation(mRowSet, &pAggResult);
if (ret != GS_RESULT_OK) {
throw GSException(mRowSet, ret);
}
return new AggregationResult(pAggResult);
}
/**
* Get current row type. Convert from C-API: gsGetRowSetType.
*/
GSRowSetType RowSet::type(){
return mType;
}
/**
* Get next query analysis
*/
QueryAnalysisEntry* RowSet::get_next_query_analysis(){
GSQueryAnalysisEntry queryAnalysis;
GSResult ret;
ret = gsGetNextQueryAnalysis(mRowSet, &queryAnalysis);
if (ret != GS_RESULT_OK) {
throw GSException(mRowSet, ret);
}
return new QueryAnalysisEntry(&queryAnalysis);
}
/**
* Get column name from RowSet. Use in python only.
*/
void RowSet::get_column_names(char*** listName, int* num){
if (mContainerInfo){
//Memory will be free from typemap
(*listName) = (char **) malloc(mContainerInfo->columnCount * sizeof(char*));
*num = mContainerInfo->columnCount;
for(int i = 0; i < mContainerInfo->columnCount; i++){
(*listName)[i] = (char*) mContainerInfo->columnInfoList[i].name;
}
}
}
/**
* Support put row
*/
GSType* RowSet::getGSTypeList(){
if (typeList == NULL){
typeList = (GSType*) malloc(sizeof(GSType) * mContainerInfo->columnCount);
for (int i = 0; i < mContainerInfo->columnCount; i++){
typeList[i] = mContainerInfo->columnInfoList[i].type;
}
}
return typeList;
}
/**
* Support put row
*/
int RowSet::getColumnCount(){
return mContainerInfo->columnCount;
}
}