Skip to content

Commit 0df919d

Browse files
committed
Support query on tree and modify clang-format.
1 parent be7bd7e commit 0df919d

16 files changed

+612
-310
lines changed

cpp/.clang-format

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ ConstructorInitializerIndentWidth: 4
6565
ContinuationIndentWidth: 4
6666
Cpp11BracedListStyle: true
6767
DeriveLineEnding: true
68-
DerivePointerAlignment: true
6968
DisableFormat: false
7069
EmptyLineAfterAccessModifier: Never
7170
EmptyLineBeforeAccessModifier: LogicalBlock
@@ -207,7 +206,7 @@ SpacesInParentheses: false
207206
SpacesInSquareBrackets: false
208207
SpaceBeforeSquareBrackets: false
209208
BitFieldColonSpacing: Both
210-
Standard: Auto
209+
Standard: Cpp11
211210
StatementAttributeLikeMacros:
212211
- Q_EMIT
213212
StatementMacros:

cpp/src/common/tsblock/tsblock.h

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TsBlock {
4444
* information, such as insert scenarios, etc. Then we will use the given
4545
* number of rows
4646
*/
47-
explicit TsBlock(TupleDesc *tupledesc, uint32_t max_row_count = 0)
47+
explicit TsBlock(TupleDesc* tupledesc, uint32_t max_row_count = 0)
4848
: capacity_(g_config_value_.tsblock_max_memory_),
4949
row_count_(0),
5050
max_row_count_(max_row_count),
@@ -60,9 +60,9 @@ class TsBlock {
6060

6161
FORCE_INLINE uint32_t get_row_count() const { return row_count_; }
6262

63-
FORCE_INLINE TupleDesc *get_tuple_desc() const { return tuple_desc_; }
63+
FORCE_INLINE TupleDesc* get_tuple_desc() const { return tuple_desc_; }
6464

65-
FORCE_INLINE Vector *get_vector(uint32_t index) { return vectors_[index]; }
65+
FORCE_INLINE Vector* get_vector(uint32_t index) { return vectors_[index]; }
6666

6767
FORCE_INLINE uint32_t get_column_count() const {
6868
return tuple_desc_->get_column_count();
@@ -104,8 +104,8 @@ class TsBlock {
104104
row_count_ = 0;
105105
}
106106

107-
FORCE_INLINE static int create_tsblock(TupleDesc *tupledesc,
108-
TsBlock *&ret_tsblock,
107+
FORCE_INLINE static int create_tsblock(TupleDesc* tupledesc,
108+
TsBlock*& ret_tsblock,
109109
uint32_t max_row_count = 0) {
110110
int ret = common::E_OK;
111111
if (ret_tsblock == nullptr) {
@@ -119,13 +119,13 @@ class TsBlock {
119119
}
120120

121121
int init();
122-
void tsblock_to_json(ByteStream *byte_stream);
122+
void tsblock_to_json(ByteStream* byte_stream);
123123

124124
std::string debug_string();
125125

126126
private:
127127
int build_vector(common::TSDataType type, uint32_t row_count);
128-
void write_data(ByteStream *__restrict byte_stream, char *__restrict val,
128+
void write_data(ByteStream* __restrict byte_stream, char* __restrict val,
129129
uint32_t len, bool has_null, TSDataType type);
130130

131131
private:
@@ -134,13 +134,13 @@ class TsBlock {
134134
uint32_t max_row_count_;
135135

136136
common::BitMap select_list_;
137-
TupleDesc *tuple_desc_;
138-
std::vector<Vector *> vectors_;
137+
TupleDesc* tuple_desc_;
138+
std::vector<Vector*> vectors_;
139139
};
140140

141141
class RowAppender {
142142
public:
143-
explicit RowAppender(TsBlock *tsblock) : tsblock_(tsblock) {}
143+
explicit RowAppender(TsBlock* tsblock) : tsblock_(tsblock) {}
144144
~RowAppender() {}
145145

146146
// todo:(yanghao) maybe need to consider select-list
@@ -157,25 +157,37 @@ class RowAppender {
157157
tsblock_->row_count_--;
158158
}
159159

160-
FORCE_INLINE void append(uint32_t slot_index, const char *value,
160+
FORCE_INLINE void append(uint32_t slot_index, const char* value,
161161
uint32_t len) {
162162
ASSERT(slot_index < tsblock_->tuple_desc_->get_column_count());
163-
Vector *vec = tsblock_->vectors_[slot_index];
164-
vec->append(value, len);
163+
Vector* vec = tsblock_->vectors_[slot_index];
164+
// TODO(Colin): Refine this.
165+
TSDataType datatype = vec->get_vector_type();
166+
if (len == 4 && datatype == INT64) {
167+
int32_t int32_val = *reinterpret_cast<const int32_t*>(value);
168+
int64_t int64_val = static_cast<int64_t>(int32_val);
169+
vec->append(reinterpret_cast<const char*>(&int64_val), 8);
170+
} else if (len == 4 && datatype == DOUBLE) {
171+
float float_val = *reinterpret_cast<const float*>(value);
172+
double double_val = static_cast<double>(float_val);
173+
vec->append(reinterpret_cast<const char*>(&double_val), 8);
174+
} else {
175+
vec->append(value, len);
176+
}
165177
}
166178

167179
FORCE_INLINE void append_null(uint32_t slot_index) {
168-
Vector *vec = tsblock_->vectors_[slot_index];
180+
Vector* vec = tsblock_->vectors_[slot_index];
169181
vec->set_null(tsblock_->row_count_ - 1);
170182
}
171183

172184
private:
173-
TsBlock *tsblock_;
185+
TsBlock* tsblock_;
174186
};
175187

176188
class ColAppender {
177189
public:
178-
ColAppender(uint32_t column_index, TsBlock *tsblock)
190+
ColAppender(uint32_t column_index, TsBlock* tsblock)
179191
: column_index_(column_index), column_row_count_(0), tsblock_(tsblock) {
180192
ASSERT(column_index < tsblock_->tuple_desc_->get_column_count());
181193
vec_ = tsblock_->vectors_[column_index];
@@ -194,7 +206,7 @@ class ColAppender {
194206
}
195207
}
196208

197-
FORCE_INLINE void append(const char *value, uint32_t len) {
209+
FORCE_INLINE void append(const char* value, uint32_t len) {
198210
vec_->append(value, len);
199211
}
200212

@@ -211,7 +223,7 @@ class ColAppender {
211223
}
212224
return E_OK;
213225
}
214-
FORCE_INLINE int fill(const char *value, uint32_t len, uint32_t end_index) {
226+
FORCE_INLINE int fill(const char* value, uint32_t len, uint32_t end_index) {
215227
while (column_row_count_ < end_index) {
216228
if (!add_row()) {
217229
return E_INVALID_ARG;
@@ -225,14 +237,14 @@ class ColAppender {
225237
private:
226238
uint32_t column_index_;
227239
uint32_t column_row_count_;
228-
TsBlock *tsblock_;
229-
Vector *vec_;
240+
TsBlock* tsblock_;
241+
Vector* vec_;
230242
};
231243

232244
// todo:(yanghao) need to deal with select-list
233245
class RowIterator {
234246
public:
235-
explicit RowIterator(TsBlock *tsblock) : tsblock_(tsblock), row_id_(0) {
247+
explicit RowIterator(TsBlock* tsblock) : tsblock_(tsblock), row_id_(0) {
236248
column_count_ = tsblock_->tuple_desc_->get_column_count();
237249
}
238250

@@ -264,25 +276,25 @@ class RowIterator {
264276

265277
FORCE_INLINE void update_row_id() { row_id_++; }
266278

267-
FORCE_INLINE char *read(uint32_t column_index, uint32_t *__restrict len,
268-
bool *__restrict null) {
279+
FORCE_INLINE char* read(uint32_t column_index, uint32_t* __restrict len,
280+
bool* __restrict null) {
269281
ASSERT(column_index < column_count_);
270-
Vector *vec = tsblock_->vectors_[column_index];
282+
Vector* vec = tsblock_->vectors_[column_index];
271283
return vec->read(len, null, row_id_);
272284
}
273285

274286
std::string debug_string(); // for debug
275287

276288
private:
277-
TsBlock *tsblock_;
289+
TsBlock* tsblock_;
278290
uint32_t row_id_; // The line number currently being reader
279291
uint32_t column_count_;
280292
};
281293

282294
// todo:(yanghao) need to deal with select-list
283295
class ColIterator {
284296
public:
285-
ColIterator(uint32_t column_index, const TsBlock *tsblock)
297+
ColIterator(uint32_t column_index, const TsBlock* tsblock)
286298
: column_index_(column_index), row_id_(0), tsblock_(tsblock) {
287299
ASSERT(column_index < tsblock_->tuple_desc_->get_column_count());
288300
vec_ = tsblock_->vectors_[column_index];
@@ -303,22 +315,22 @@ class ColIterator {
303315

304316
FORCE_INLINE TSDataType get_data_type() { return vec_->get_vector_type(); }
305317

306-
FORCE_INLINE char *read(uint32_t *__restrict len, bool *__restrict null) {
318+
FORCE_INLINE char* read(uint32_t* __restrict len, bool* __restrict null) {
307319
return vec_->read(len, null, row_id_);
308320
}
309321

310-
FORCE_INLINE char *read(uint32_t *len) { return vec_->read(len); }
322+
FORCE_INLINE char* read(uint32_t* len) { return vec_->read(len); }
311323

312324
FORCE_INLINE uint32_t get_column_index() { return column_index_; }
313325

314326
private:
315327
uint32_t column_index_;
316328
uint32_t row_id_;
317-
const TsBlock *tsblock_;
318-
Vector *vec_;
329+
const TsBlock* tsblock_;
330+
Vector* vec_;
319331
};
320332

321-
int merge_tsblock_by_row(TsBlock *sea, TsBlock *river);
333+
int merge_tsblock_by_row(TsBlock* sea, TsBlock* river);
322334

323335
} // end namespace common
324336
#endif // COMMON_TSBLOCK_TSBLOCK_H

0 commit comments

Comments
 (0)