Skip to content

Commit 407e23f

Browse files
author
Do Huu Chien
committed
[Cutting Row]
Remove redundant Row class, Replace with GSRow struct
1 parent aba03c3 commit 407e23f

13 files changed

Lines changed: 802 additions & 940 deletions

Makefile

100644100755
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ SOURCES = src/TimeSeriesProperties.cpp \
2222
src/StoreFactory.cpp \
2323
src/PartitionController.cpp \
2424
src/Query.cpp \
25-
src/Row.cpp \
2625
src/QueryAnalysisEntry.cpp \
2726
src/RowKeyPredicate.cpp \
2827
src/RowSet.cpp \

src/AggregationResult.h

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define _AGGREGATIONRESULT_H_
1919

2020
#include "GSException.h"
21-
#include "Row.h"
21+
#include "Field.h"
2222
#include "gridstore.h"
2323

2424
using namespace std;

src/Container.cpp

100644100755
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,12 @@ namespace griddb {
135135
/**
136136
* Put row to database.
137137
*/
138-
bool Container::put(Row *rowContainer) {
138+
bool Container::put(GSRow *rowContainer) {
139139
GSBool bExists;
140-
rowContainer->set_for_row(mRow, mContainerInfo);
141140
GSResult ret = gsPutRow(mContainer, NULL, mRow, &bExists);
142141
if (ret != GS_RESULT_OK) {
143142
throw GSException(mContainer, ret);
144143
}
145-
146144
return bExists;
147145
}
148146

@@ -210,7 +208,7 @@ namespace griddb {
210208
/**
211209
* Returns the content of a Row.
212210
*/
213-
GSBool Container::get(Field* keyFields, Row *rowdata) {
211+
GSBool Container::get(Field* keyFields, GSRow *rowdata) {
214212
GSBool exists;
215213
GSResult ret;
216214
void *key = NULL;
@@ -253,10 +251,6 @@ namespace griddb {
253251
throw GSException(mContainer, ret);
254252
}
255253

256-
if(exists) {
257-
rowdata->set_from_row(mRow);
258-
}
259-
260254
return exists;
261255
}
262256

@@ -318,29 +312,12 @@ namespace griddb {
318312
/**
319313
* Multiput data
320314
*/
321-
void Container::multi_put(Row** listRowdata, int rowCount) {
315+
void Container::multi_put(GSRow** listRowdata, int rowCount) {
322316
GSResult ret;
323317
GSBool bExists;
324-
GSRow** rowObjs = (GSRow**) malloc(rowCount * sizeof(GSRow *));
325-
326-
for (int i = 0; i < rowCount; i++) {
327-
GSRow *gsrow;
328-
gsCreateRowByContainer(mContainer, &gsrow);
329-
Row* tmpRow = listRowdata[i];
330-
tmpRow->set_for_row(gsrow, NULL);
331-
rowObjs[i] = gsrow;
332-
}
333-
334318
//data for each container
335-
ret = gsPutMultipleRows(mContainer, (const void * const *) rowObjs,
319+
ret = gsPutMultipleRows(mContainer, (const void * const *) listRowdata,
336320
rowCount, &bExists);
337-
338-
for (int rowNum = 0; rowNum < rowCount; rowNum++) {
339-
GSRow* gsRow = (GSRow *) rowObjs[rowNum];
340-
gsCloseRow(&gsRow);
341-
}
342-
343-
free((void*) rowObjs);
344321
if (ret != GS_RESULT_OK) {
345322
throw GSException(mContainer, ret);
346323
}
@@ -379,6 +356,10 @@ namespace griddb {
379356
return typeList;
380357
}
381358

359+
GSRow* Container::getGSRowPtr(){
360+
return mRow;
361+
}
362+
382363
/**
383364
* Support put row
384365
*/

src/Container.h

100644100755
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef _CONTAINER_H_
1818
#define _CONTAINER_H_
1919

20-
#include "Row.h"
20+
#include "Field.h"
2121
#include "Query.h"
2222

2323
using namespace std;
@@ -41,18 +41,19 @@ class Container {
4141
GSContainerType get_type();
4242
void create_index(const char* column_name, GSIndexTypeFlags index_type = GS_INDEX_FLAG_DEFAULT, const char* name=NULL);
4343
void drop_index(const char* column_name, GSIndexTypeFlags index_type = GS_INDEX_FLAG_DEFAULT, const char* name=NULL);
44-
bool put(Row *rowContainer);
44+
bool put(GSRow *rowContainer);
4545
Query* query(const char *query);
4646
void abort();
4747
void flush();
4848
void set_auto_commit(bool enabled);
4949
void commit();
50-
GSBool get(Field* keyFields, Row *rowdata);
50+
GSBool get(Field* keyFields, GSRow *rowdata);
5151
bool remove(Field* keyFields);
52-
void multi_put(Row** listRowdata, int rowCount);
52+
void multi_put(GSRow** listRowdata, int rowCount);
5353
GSContainer* getGSContainerPtr();
5454
GSType* getGSTypeList();
5555
int getColumnCount();
56+
GSRow* getGSRowPtr();
5657

5758
private:
5859
Container(GSContainer *container, GSContainerInfo* containerInfo);

src/Field.h

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
Copyright (c) 2017 TOSHIBA Digital Solutions Corporation.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef _FIELD_H_
18+
#define _FIELD_H_
19+
20+
#include "gridstore.h"
21+
#include <iostream>
22+
#include <string.h>
23+
24+
using namespace std;
25+
26+
namespace griddb {
27+
28+
struct Field {
29+
GSChar *name;
30+
GSType type;
31+
GSValue value;
32+
Field() : name(NULL), type(GS_TYPE_STRING) {
33+
memset(&value, 0, sizeof(GSValue));
34+
};
35+
36+
~Field() {
37+
switch (type){
38+
case GS_TYPE_STRING:
39+
if (value.asString) {
40+
free(const_cast<GSChar*>(value.asString));
41+
value.asString = NULL;
42+
}
43+
break;
44+
case GS_TYPE_BLOB:
45+
if (value.asBlob.data) {
46+
free(const_cast<void*>(value.asBlob.data));
47+
value.asBlob.data = NULL;
48+
}
49+
break;
50+
case GS_TYPE_INTEGER_ARRAY:
51+
#if GS_COMPATIBILITY_VALUE_1_1_106
52+
if (value.asIntegerArray.elements) {
53+
free(const_cast<int32_t*> (value.asIntegerArray.elements));
54+
}
55+
#else
56+
if (value.asArray.elements.asInteger) {
57+
free(const_cast<int32_t*> (value.asArray.elements.asInteger));
58+
}
59+
#endif
60+
break;
61+
case GS_TYPE_STRING_ARRAY:
62+
#if GS_COMPATIBILITY_VALUE_1_1_106
63+
if (value.asStringArray.elements) {
64+
for (int j = 0; j < value.asStringArray.size; j++) {
65+
if (value.asStringArray.elements[j]) {
66+
free(const_cast<GSChar*> (value.asStringArray.elements[j]));
67+
}
68+
}
69+
free(const_cast<GSChar**> (value.asStringArray.elements));
70+
}
71+
#else
72+
if (value.asArray.elements.asString) {
73+
for (int j = 0; j < value.asArray.length; j++) {
74+
if (value.asArray.elements.asString[j]) {
75+
free(const_cast<GSChar*> (value.asArray.elements.asString[j]));
76+
}
77+
}
78+
free(const_cast<GSChar**> (value.asArray.elements.asString));
79+
}
80+
#endif
81+
break;
82+
case GS_TYPE_BOOL_ARRAY:
83+
#if GS_COMPATIBILITY_VALUE_1_1_106
84+
if (value.asBoolArray.elements) {
85+
free(const_cast<GSBool*> (value.asBoolArray.elements));
86+
}
87+
#else
88+
if (value.asArray.elements.asBool) {
89+
free(const_cast<GSBool*> (value.asArray.elements.asBool));
90+
}
91+
#endif
92+
break;
93+
case GS_TYPE_BYTE_ARRAY:
94+
#if GS_COMPATIBILITY_VALUE_1_1_106
95+
if (value.asByteArray.elements) {
96+
free(const_cast<int8_t*> (value.asByteArray.elements));
97+
value.asByteArray.elements = NULL;
98+
}
99+
#else
100+
if (value.asArray.elements.asByte) {
101+
free(const_cast<int8_t*> (value.asArray.elements.asByte));
102+
value.asArray.elements.asByte = NULL;
103+
}
104+
#endif
105+
break;
106+
case GS_TYPE_SHORT_ARRAY:
107+
#if GS_COMPATIBILITY_VALUE_1_1_106
108+
if (value.asShortArray.elements) {
109+
free(const_cast<int16_t*> (value.asShortArray.elements));
110+
}
111+
#else
112+
if (value.asArray.elements.asShort) {
113+
free(const_cast<int16_t*> (value.asArray.elements.asShort));
114+
}
115+
#endif
116+
break;
117+
case GS_TYPE_LONG_ARRAY:
118+
#if GS_COMPATIBILITY_VALUE_1_1_106
119+
if (value.asLongArray.elements) {
120+
free(const_cast<int64_t*> (value.asLongArray.elements));
121+
}
122+
#else
123+
if (value.asArray.elements.asLong) {
124+
free(const_cast<int64_t*> (value.asArray.elements.asLong));
125+
}
126+
#endif
127+
break;
128+
case GS_TYPE_FLOAT_ARRAY:
129+
#if GS_COMPATIBILITY_VALUE_1_1_106
130+
if (value.asFloatArray.elements) {
131+
free(const_cast<float*> (value.asFloatArray.elements));
132+
}
133+
#else
134+
if (value.asArray.elements.asFloat) {
135+
free(const_cast<float*> (value.asArray.elements.asFloat));
136+
}
137+
#endif
138+
break;
139+
case GS_TYPE_DOUBLE_ARRAY:
140+
#if GS_COMPATIBILITY_VALUE_1_1_106
141+
if (value.asDoubleArray.elements) {
142+
free(const_cast<double*> (value.asDoubleArray.elements));
143+
}
144+
#else
145+
if (value.asArray.elements.asDouble) {
146+
free(const_cast<double*> (value.asArray.elements.asDouble));
147+
}
148+
#endif
149+
break;
150+
case GS_TYPE_TIMESTAMP_ARRAY:
151+
#if GS_COMPATIBILITY_VALUE_1_1_106
152+
if (value.asTimestampArray.elements) {
153+
free(const_cast<GSTimestamp*> (value.asTimestampArray.elements));
154+
}
155+
#else
156+
if (value.asArray.elements.asTimestamp) {
157+
free(const_cast<GSTimestamp*> (value.asArray.elements.asTimestamp));
158+
}
159+
#endif
160+
break;
161+
}
162+
}
163+
};
164+
165+
}
166+
167+
#endif /* _FIELD_H_ */

src/RowKeyPredicate.cpp

100644100755
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace griddb {
3838
mPredicate = NULL;
3939
}
4040
}
41+
4142
/**
4243
* Get key type. Convert from C-API: gsGetPredicateKeyType
4344
*/
@@ -56,13 +57,18 @@ namespace griddb {
5657
if (ret != GS_RESULT_OK) {
5758
throw GSException(mPredicate, ret);
5859
}
59-
startField->value = *startKey;
6060
const GSValue *endKey;
6161
ret = gsGetPredicateFinishKeyGeneral(mPredicate, &endKey);
6262
if (ret != GS_RESULT_OK) {
6363
throw GSException(mPredicate, ret);
6464
}
65-
finishField->value = *endKey;
65+
if (startField->type == GS_TYPE_STRING) {
66+
startField->value.asString = strdup(startKey->asString);
67+
finishField->value.asString = strdup(endKey->asString);
68+
} else {
69+
startField->value = *startKey;
70+
finishField->value = *endKey;
71+
}
6672
}
6773
/*
6874
* Sets the value of Row key as the start and end position of the range conditions
@@ -257,11 +263,17 @@ namespace griddb {
257263
GSResult ret = gsGetPredicateDistinctKeysGeneral(mPredicate, (const GSValue **)&keyList, &size);
258264
*keyCount = size;
259265

260-
Field* keyFields = (Field *) malloc(size * sizeof (Field));
261-
memset(keyFields, 0, size * sizeof (Field));
266+
Field* keyFields = new Field[size];
262267
for(int i =0;i< size; i++) {
263268
keyFields[i].type = key_type;
264-
keyFields[i].value = keyList[i];
269+
switch(key_type) {
270+
case GS_TYPE_STRING:
271+
keyFields[i].value.asString = strdup(keyList[i].asString);
272+
break;
273+
default:
274+
keyFields[i].value = keyList[i];
275+
break;
276+
}
265277
}
266278

267279
*keys = keyFields;

src/RowKeyPredicate.h

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include <string>
2121
#include <vector>
2222
#include "gridstore.h"
23-
#include "Row.h"
23+
#include "Field.h"
24+
#include <string.h>
2425

2526

2627
using namespace std;

0 commit comments

Comments
 (0)