ColinLeeo commented on code in PR #418:
URL: https://github.com/apache/tsfile/pull/418#discussion_r1973068875


##########
cpp/examples/cpp_examples/demo_read.cpp:
##########
@@ -20,78 +20,63 @@
 #include <string>
 #include <vector>
 
+#include "../c_examples/c_examples.h"
 #include "cpp_examples.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();
-    }
-}
-
+using namespace storage;
 int demo_read() {
-    std::cout << "begin to read tsfile from demo_ts.tsfile" << 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();
+    ERRNO code = 0;
+    libtsfile_init();
+    std::string table_name = "table1";
     storage::TsFileReader reader;
-    int ret = reader.open("cpp_rw.tsfile");
-
-    std::cout << "begin to query expr" << std::endl;
-    ASSERT(ret == 0);
-    storage::ResultSet *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 {
-        if (qds->next()) {
-            std::cout << "dump QDS :  " << record->get_timestamp() << ",";
-            record = qds->get_row_record();
-            if (record) {
-                int size = record->get_fields()->size();
-                for (int i = 0; i < size; ++i) {
-                    std::cout << field_to_string(record->get_field(i)) << ",";
+    reader.open("test_cpp.tsfile");
+    storage::ResultSet* temp_ret = nullptr;
+    std::vector<std::string> columns;
+    columns.emplace_back("id1");
+    columns.emplace_back("id2");
+    columns.emplace_back("s1");
+    code = reader.query(table_name, columns, 0, 100, temp_ret);
+    auto ret = static_cast<storage::TableResultSet*>(temp_ret);
+    auto metadata = ret->get_metadata();
+    int column_num = metadata->get_column_count();
+    for (int i = 0; i < column_num; i++) {
+        std::cout << "column name: " << metadata->get_column_name(i)
+                  << std::endl;
+        std::cout << "column type: " << metadata->get_column_type(i)
+                  << std::endl;
+    }
+    bool has_next = false;
+    while (ret->next(has_next) == common::E_OK && has_next) {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@tsfile.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to