Skip to content

Commit a4d33a0

Browse files
committed
fix ci.
1 parent e107d00 commit a4d33a0

File tree

3 files changed

+60
-49
lines changed

3 files changed

+60
-49
lines changed

cpp/src/common/schema.h

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct MeasurementSchema {
4646
common::TSDataType data_type_;
4747
common::TSEncoding encoding_;
4848
common::CompressionType compression_type_;
49-
storage::ChunkWriter *chunk_writer_;
50-
ValueChunkWriter *value_chunk_writer_;
49+
storage::ChunkWriter* chunk_writer_;
50+
ValueChunkWriter* value_chunk_writer_;
5151
std::map<std::string, std::string> props_;
5252

5353
MeasurementSchema()
@@ -58,7 +58,7 @@ struct MeasurementSchema {
5858
chunk_writer_(nullptr),
5959
value_chunk_writer_(nullptr) {}
6060

61-
MeasurementSchema(const std::string &measurement_name,
61+
MeasurementSchema(const std::string& measurement_name,
6262
common::TSDataType data_type)
6363
: measurement_name_(measurement_name),
6464
data_type_(data_type),
@@ -67,7 +67,7 @@ struct MeasurementSchema {
6767
chunk_writer_(nullptr),
6868
value_chunk_writer_(nullptr) {}
6969

70-
MeasurementSchema(const std::string &measurement_name,
70+
MeasurementSchema(const std::string& measurement_name,
7171
common::TSDataType data_type, common::TSEncoding encoding,
7272
common::CompressionType compression_type)
7373
: measurement_name_(measurement_name),
@@ -88,7 +88,7 @@ struct MeasurementSchema {
8888
}
8989
}
9090

91-
int serialize_to(common::ByteStream &out) {
91+
int serialize_to(common::ByteStream& out) {
9292
int ret = common::E_OK;
9393
if (RET_FAIL(
9494
common::SerializationUtil::write_str(measurement_name_, out))) {
@@ -102,7 +102,7 @@ struct MeasurementSchema {
102102
if (ret == common::E_OK) {
103103
if (RET_FAIL(common::SerializationUtil::write_ui32(props_.size(),
104104
out))) {
105-
for (const auto &prop : props_) {
105+
for (const auto& prop : props_) {
106106
if (RET_FAIL(common::SerializationUtil::write_str(
107107
prop.first, out))) {
108108
} else if (RET_FAIL(common::SerializationUtil::write_str(
@@ -115,7 +115,7 @@ struct MeasurementSchema {
115115
return ret;
116116
}
117117

118-
int deserialize_from(common::ByteStream &in) {
118+
int deserialize_from(common::ByteStream& in) {
119119
int ret = common::E_OK;
120120
uint8_t data_type = common::TSDataType::INVALID_DATATYPE,
121121
encoding = common::TSEncoding::INVALID_ENCODING,
@@ -153,8 +153,8 @@ struct MeasurementSchema {
153153
}
154154
};
155155

156-
typedef std::map<std::string, MeasurementSchema *> MeasurementSchemaMap;
157-
typedef std::map<std::string, MeasurementSchema *>::iterator
156+
typedef std::map<std::string, MeasurementSchema*> MeasurementSchemaMap;
157+
typedef std::map<std::string, MeasurementSchema*>::iterator
158158
MeasurementSchemaMapIter;
159159
typedef std::pair<MeasurementSchemaMapIter, bool>
160160
MeasurementSchemaMapInsertResult;
@@ -164,7 +164,7 @@ struct MeasurementSchemaGroup {
164164
// measurement_name -> MeasurementSchema
165165
MeasurementSchemaMap measurement_schema_map_;
166166
bool is_aligned_ = false;
167-
TimeChunkWriter *time_chunk_writer_ = nullptr;
167+
TimeChunkWriter* time_chunk_writer_ = nullptr;
168168

169169
~MeasurementSchemaGroup() {
170170
if (time_chunk_writer_ != nullptr) {
@@ -195,28 +195,28 @@ class TableSchema {
195195
* Each ColumnSchema defines the schema for one column
196196
* in the table.
197197
*/
198-
TableSchema(const std::string &table_name,
199-
const std::vector<common::ColumnSchema> &column_schemas)
198+
TableSchema(const std::string& table_name,
199+
const std::vector<common::ColumnSchema>& column_schemas)
200200
: table_name_(table_name) {
201201
to_lowercase_inplace(table_name_);
202-
for (const common::ColumnSchema &column_schema : column_schemas) {
202+
for (const common::ColumnSchema& column_schema : column_schemas) {
203203
column_schemas_.emplace_back(std::make_shared<MeasurementSchema>(
204204
column_schema.get_column_name(),
205205
column_schema.get_data_type()));
206206
column_categories_.emplace_back(
207207
column_schema.get_column_category());
208208
}
209209
int idx = 0;
210-
for (const auto &measurement_schema : column_schemas_) {
210+
for (const auto& measurement_schema : column_schemas_) {
211211
to_lowercase_inplace(measurement_schema->measurement_name_);
212212
column_pos_index_.insert(
213213
std::make_pair(measurement_schema->measurement_name_, idx++));
214214
}
215215
}
216216

217-
TableSchema(const std::string &table_name,
218-
const std::vector<MeasurementSchema *> &column_schemas,
219-
const std::vector<common::ColumnCategory> &column_categories)
217+
TableSchema(const std::string& table_name,
218+
const std::vector<MeasurementSchema*>& column_schemas,
219+
const std::vector<common::ColumnCategory>& column_categories)
220220
: table_name_(table_name), column_categories_(column_categories) {
221221
to_lowercase_inplace(table_name_);
222222
for (const auto column_schema : column_schemas) {
@@ -226,34 +226,42 @@ class TableSchema {
226226
}
227227
}
228228
int idx = 0;
229-
for (const auto &measurement_schema : column_schemas_) {
229+
for (const auto& measurement_schema : column_schemas_) {
230230
to_lowercase_inplace(measurement_schema->measurement_name_);
231231
column_pos_index_.insert(
232232
std::make_pair(measurement_schema->measurement_name_, idx++));
233233
}
234234
}
235235

236-
TableSchema(TableSchema &&other) noexcept
236+
TableSchema(TableSchema&& other) noexcept
237237
: table_name_(std::move(other.table_name_)),
238238
column_schemas_(std::move(other.column_schemas_)),
239239
column_categories_(std::move(other.column_categories_)) {}
240240

241-
TableSchema(const TableSchema &other) noexcept
241+
TableSchema(const TableSchema& other) noexcept
242242
: table_name_(other.table_name_),
243243
column_categories_(other.column_categories_) {
244-
for (const auto &column_schema : other.column_schemas_) {
244+
for (const auto& column_schema : other.column_schemas_) {
245245
// Just call default construction
246246
column_schemas_.emplace_back(
247247
std::make_shared<MeasurementSchema>(*column_schema));
248248
}
249249
int idx = 0;
250-
for (const auto &measurement_schema : column_schemas_) {
250+
for (const auto& measurement_schema : column_schemas_) {
251251
column_pos_index_.insert(
252252
std::make_pair(measurement_schema->measurement_name_, idx++));
253253
}
254254
}
255255

256-
int serialize_to(common::ByteStream &out) {
256+
// In cases where data is retrieved from a tree to form the table,
257+
// there is no table name in the tree path, so adjustments are needed for
258+
// this scenario. This flag is used specifically for such cases.
259+
// TODO(Colin): remove this.
260+
void set_virtual_table() { is_virtual_table_ = true; }
261+
262+
bool is_virtual_table() { return is_virtual_table_; }
263+
264+
int serialize_to(common::ByteStream& out) {
257265
int ret = common::E_OK;
258266
if (RET_FAIL(common::SerializationUtil::write_var_uint(
259267
column_schemas_.size(), out))) {
@@ -271,7 +279,7 @@ class TableSchema {
271279
return ret;
272280
}
273281

274-
int deserialize(common::ByteStream &in) {
282+
int deserialize(common::ByteStream& in) {
275283
int ret = common::E_OK;
276284
uint32_t num_columns;
277285
if (RET_FAIL(
@@ -294,9 +302,9 @@ class TableSchema {
294302

295303
~TableSchema() { column_schemas_.clear(); }
296304

297-
const std::string &get_table_name() { return table_name_; }
305+
const std::string& get_table_name() { return table_name_; }
298306

299-
void set_table_name(const std::string &table_name) {
307+
void set_table_name(const std::string& table_name) {
300308
table_name_ = table_name;
301309
}
302310

@@ -310,7 +318,7 @@ class TableSchema {
310318

311319
int32_t get_columns_num() const { return column_schemas_.size(); }
312320

313-
int find_column_index(const std::string &column_name) {
321+
int find_column_index(const std::string& column_name) {
314322
std::string lower_case_column_name = to_lower(column_name);
315323
auto it = column_pos_index_.find(lower_case_column_name);
316324
if (it != column_pos_index_.end()) {
@@ -333,10 +341,10 @@ class TableSchema {
333341

334342
size_t get_column_pos_index_num() const { return column_pos_index_.size(); }
335343

336-
void update(ChunkGroupMeta *chunk_group_meta) {
344+
void update(ChunkGroupMeta* chunk_group_meta) {
337345
for (auto iter = chunk_group_meta->chunk_meta_list_.begin();
338346
iter != chunk_group_meta->chunk_meta_list_.end(); iter++) {
339-
auto &chunk_meta = iter.get();
347+
auto& chunk_meta = iter.get();
340348
if (chunk_meta->data_type_ == common::VECTOR) {
341349
continue;
342350
}
@@ -365,7 +373,7 @@ class TableSchema {
365373

366374
std::vector<common::TSDataType> get_data_types() const {
367375
std::vector<common::TSDataType> ret;
368-
for (const auto &measurement_schema : column_schemas_) {
376+
for (const auto& measurement_schema : column_schemas_) {
369377
ret.emplace_back(measurement_schema->data_type_);
370378
}
371379
return ret;
@@ -375,12 +383,12 @@ class TableSchema {
375383
return column_categories_;
376384
}
377385

378-
std::vector<std::shared_ptr<MeasurementSchema> > get_measurement_schemas()
386+
std::vector<std::shared_ptr<MeasurementSchema>> get_measurement_schemas()
379387
const {
380388
return column_schemas_;
381389
}
382390

383-
common::ColumnSchema get_column_schema(const std::string &column_name) {
391+
common::ColumnSchema get_column_schema(const std::string& column_name) {
384392
int column_idx = find_column_index(column_name);
385393
if (column_idx == -1) {
386394
return common::ColumnSchema();
@@ -394,7 +402,7 @@ class TableSchema {
394402
}
395403
}
396404

397-
int32_t find_id_column_order(const std::string &column_name) {
405+
int32_t find_id_column_order(const std::string& column_name) {
398406
std::string lower_case_column_name = to_lower(column_name);
399407

400408
int column_order = 0;
@@ -412,17 +420,18 @@ class TableSchema {
412420

413421
private:
414422
std::string table_name_;
415-
std::vector<std::shared_ptr<MeasurementSchema> > column_schemas_;
423+
std::vector<std::shared_ptr<MeasurementSchema>> column_schemas_;
416424
std::vector<common::ColumnCategory> column_categories_;
417425
std::map<std::string, int> column_pos_index_;
426+
bool is_virtual_table_ = false;
418427
};
419428

420429
struct Schema {
421-
typedef std::unordered_map<std::string, std::shared_ptr<TableSchema> >
430+
typedef std::unordered_map<std::string, std::shared_ptr<TableSchema>>
422431
TableSchemasMap;
423432
TableSchemasMap table_schema_map_;
424433

425-
void update_table_schema(ChunkGroupMeta *chunk_group_meta) {
434+
void update_table_schema(ChunkGroupMeta* chunk_group_meta) {
426435
std::shared_ptr<IDeviceID> device_id = chunk_group_meta->device_id_;
427436
auto table_name = device_id->get_table_name();
428437
if (table_schema_map_.find(table_name) == table_schema_map_.end()) {
@@ -431,7 +440,7 @@ struct Schema {
431440
table_schema_map_[table_name]->update(chunk_group_meta);
432441
}
433442
void register_table_schema(
434-
const std::shared_ptr<TableSchema> &table_schema) {
443+
const std::shared_ptr<TableSchema>& table_schema) {
435444
table_schema_map_[table_schema->get_table_name()] = table_schema;
436445
}
437446
};

cpp/src/reader/block/single_device_tsblock_reader.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ int SingleDeviceTsBlockReader::init(DeviceQueryTask* device_query_task,
8282
device_query_task->get_column_mapping()->get_id_columns()) {
8383
const auto& column_pos_in_result =
8484
device_query_task->get_column_mapping()->get_column_pos(id_column);
85-
int column_pos_in_id =
86-
table_schema->find_id_column_order(id_column) + 1;
85+
int column_pos_in_id = table_schema->find_id_column_order(id_column) +
86+
(!table_schema->is_virtual_table());
8787
id_column_contexts_.insert(std::make_pair(
8888
id_column,
8989
IdColumnContext(column_pos_in_result, column_pos_in_id)));
@@ -218,8 +218,8 @@ int SingleDeviceTsBlockReader::fill_ids() {
218218
device_query_task_->get_device_id()->get_segments();
219219
int32_t pos_in_device_id = id_column_context.pos_in_device_id_;
220220
if (pos_in_device_id >= 0 &&
221-
static_cast<size_t>(pos_in_device_id - 1) < segments.size()) {
222-
device_tag = segments[pos_in_device_id - 1];
221+
static_cast<size_t>(pos_in_device_id) < segments.size()) {
222+
device_tag = segments[pos_in_device_id];
223223
}
224224

225225
if (device_tag == nullptr) {

cpp/src/reader/table_query_executor.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,15 @@ int TableQueryExecutor::query_on_tree(
140140
if (column_types_map.find(measurement_name) ==
141141
column_types_map.end()) {
142142
common::TSDataType type = ts_index->get_data_type();
143-
if (type == common::TSDataType::INT32 ||
144-
type == common::TSDataType::INT64 ||
145-
type == common::TSDataType::TIMESTAMP ||
146-
type == common::TSDataType::DATE) {
147-
type = common::TSDataType::INT64;
148-
} else if (type == common::TSDataType::FLOAT) {
149-
type = common::TSDataType::DOUBLE;
150-
}
143+
// TODO(Colin): Fix type missmatch.
144+
// if (type == common::TSDataType::INT32 ||
145+
// type == common::TSDataType::INT64 ||
146+
// type == common::TSDataType::TIMESTAMP ||
147+
// type == common::TSDataType::DATE) {
148+
// type = common::TSDataType::INT64;
149+
// } else if (type == common::TSDataType::FLOAT) {
150+
// type = common::TSDataType::DOUBLE;
151+
// }
151152
column_types_map[measurement_name] = type;
152153
}
153154
}
@@ -166,6 +167,7 @@ int TableQueryExecutor::query_on_tree(
166167
}
167168

168169
auto schema = std::make_shared<TableSchema>("default", col_schema);
170+
schema->set_virtual_table();
169171
std::shared_ptr<ColumnMapping> column_mapping =
170172
std::make_shared<ColumnMapping>();
171173
for (size_t i = 0; i < col_schema.size(); ++i) {

0 commit comments

Comments
 (0)