-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CPP]. add readme for cpp and some examples.
- Loading branch information
Showing
6 changed files
with
187 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include "common/path.h" | ||
#include "reader/filter/filter.h" | ||
#include "reader/expression.h" | ||
#include "reader/tsfile_reader.h" | ||
#include "reader/qds_with_timegenerator.h" | ||
#include "reader/qds_without_timegenerator.h" | ||
#include "common/row_record.h" | ||
|
||
std::string field_to_string(storage::Field *value) | ||
{ | ||
if (value->type_ == common::TEXT) { | ||
return std::string(value->value_.sval_); | ||
} else { | ||
std::stringstream ss; | ||
switch (value->type_) { | ||
case common::BOOLEAN: | ||
ss << (value->value_.bval_ ? "true" : "false"); | ||
break; | ||
case common::INT32: | ||
ss << value->value_.ival_; | ||
break; | ||
case common::INT64: | ||
ss << value->value_.lval_; | ||
break; | ||
case common::FLOAT: | ||
ss << value->value_.fval_; | ||
break; | ||
case common::DOUBLE: | ||
ss << value->value_.dval_; | ||
break; | ||
case common::NULL_TYPE: | ||
ss << "NULL"; | ||
break; | ||
default: | ||
ASSERT(false); | ||
break; | ||
} | ||
return ss.str(); | ||
} | ||
} | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
std::cout<<"begin to read tsfile from /tmp/t1" << std::endl; | ||
std::string device_name = "root.db001.dev001"; | ||
std::string measurement_name = "m001"; | ||
storage::Path p1(device_name, measurement_name); | ||
std::vector<storage::Path> select_list; | ||
select_list.push_back(p1); | ||
storage::QueryExpression *query_expr = | ||
storage::QueryExpression::create(select_list, nullptr); | ||
|
||
common::init_config_value(); | ||
storage::TsFileReader reader; | ||
int ret = reader.open("/tmp/t1"); | ||
|
||
std::cout << "begin to query expr" << std::endl; | ||
ASSERT(ret == 0); | ||
storage::QueryDataSet *qds = nullptr; | ||
ret = reader.query(query_expr, qds); | ||
|
||
|
||
storage::RowRecord *record; | ||
std::cout << "begin to dump data from tsfile ---" << std::endl; | ||
int row_cout = 0; | ||
do { | ||
record = qds->get_next(); | ||
if (record) { | ||
std::cout<< "dump QDS : " << record->get_timestamp() << ","; | ||
if (record) { | ||
int size = record->get_fields()->size(); | ||
for (int i = 0; i < size; ++i) { | ||
std::cout << field_to_string(record->get_field(i)) << ","; | ||
} | ||
std::cout<< std::endl; | ||
row_cout++; | ||
} | ||
} else { | ||
break; | ||
} | ||
} while (true); | ||
|
||
return (0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 <iostream> | ||
#include <string> | ||
#include <time.h> | ||
#include "writer/tsfile_writer.h" | ||
#include "common/record.h" | ||
#include "common/db_common.h" | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
std::cout<<"get in."<<std::endl; | ||
storage::TsFileWriter tsfile_writer; | ||
std::string device_name = "root.db001.dev001"; | ||
std::string measurement_name = "m001"; | ||
storage::libtsfile_init(); | ||
tsfile_writer.open("/tmp/t1",O_CREAT | O_RDWR, 0644); | ||
int ret = tsfile_writer.register_timeseries(device_name, measurement_name, common::INT32, common::PLAIN, common::UNCOMPRESSED); | ||
std::cout<<"register finish" << device_name<< std::endl; | ||
|
||
int row_count = 100; | ||
for (int i = 1; i < row_count; ++i) { | ||
storage::DataPoint point(measurement_name, 10000 + i); | ||
storage::TsRecord record(i, device_name,1); | ||
record.points_.push_back(point); | ||
ret = tsfile_writer.write_record(record); | ||
std::cout<< "write point:" << measurement_name << " " << 10000 + i << std::endl; | ||
ASSERT(ret == 0); | ||
} | ||
|
||
tsfile_writer.flush(); | ||
std::cout<<"finish flush"<<std::endl; | ||
tsfile_writer.close(); | ||
std::cout<<"tsfile closed."<<std::endl; | ||
storage::libtsfile_destroy(); | ||
std::cout<< "tsfile to destory."<<std::endl; | ||
std::cout<<"finish writing" << std::endl; | ||
std::cout<<"will close our files"<<std::endl; | ||
|
||
|
||
|
||
return ret; | ||
} |