This is an automated email from the ASF dual-hosted git repository.

caogaofei pushed a commit to branch beyyes/fix_example
in repository https://gitbox.apache.org/repos/asf/tsfile.git

commit 0935a0f2f12172e0519ff1e7798148e1433dd8e6
Author: Beyyes <[email protected]>
AuthorDate: Thu Mar 6 22:38:39 2025 +0800

    fix README and demo write of cpp
---
 cpp/README.md                            | 32 +++++++++++++++---------------
 cpp/examples/CMakeLists.txt              |  2 +-
 cpp/examples/README.md                   | 34 ++++++++++++++++----------------
 cpp/examples/c_examples/demo_write.c     |  2 +-
 cpp/examples/cpp_examples/demo_read.cpp  |  3 +--
 cpp/examples/cpp_examples/demo_write.cpp | 17 +++++-----------
 cpp/examples/examples.cc                 |  4 ++--
 7 files changed, 43 insertions(+), 51 deletions(-)

diff --git a/cpp/README.md b/cpp/README.md
index abd737a3..b742c4d8 100644
--- a/cpp/README.md
+++ b/cpp/README.md
@@ -1,21 +1,21 @@
 <!--
 
-​    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.
+    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.
 
 -->
 
diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt
index 75b92692..d288467b 100644
--- a/cpp/examples/CMakeLists.txt
+++ b/cpp/examples/CMakeLists.txt
@@ -34,7 +34,7 @@ set(SDK_LIB_DIR_DEBUG 
${PROJECT_SOURCE_DIR}/../build/Debug/lib)
 message("SDK_LIB_DIR_DEBUG: ${SDK_LIB_DIR_DEBUG}")
 
include_directories(${PROJECT_SOURCE_DIR}/../third_party/antlr4-cpp-runtime-4/runtime/src)
 
-set(BUILD_TYPE "Debug")
+set(BUILD_TYPE "Release")
 include_directories(${SDK_INCLUDE_DIR})
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
diff --git a/cpp/examples/README.md b/cpp/examples/README.md
index 7b20d5f4..5f5af186 100644
--- a/cpp/examples/README.md
+++ b/cpp/examples/README.md
@@ -1,21 +1,21 @@
 <!--
 
-​    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.
+    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.
 
 -->
 
@@ -29,7 +29,7 @@ Build Methods (Choose either approach)
 Execute from the project root directory:
 
 ```BASH
-mvn package -P with-cpp clean verify
+mvn clean package verify -P with-cpp
 ```
 Output location: cpp/target/build/lib
 
diff --git a/cpp/examples/c_examples/demo_write.c 
b/cpp/examples/c_examples/demo_write.c
index fffe3f18..69a5c554 100644
--- a/cpp/examples/c_examples/demo_write.c
+++ b/cpp/examples/c_examples/demo_write.c
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/cpp/examples/cpp_examples/demo_read.cpp 
b/cpp/examples/cpp_examples/demo_read.cpp
index 4951e8ca..bfc1b8d4 100644
--- a/cpp/examples/cpp_examples/demo_read.cpp
+++ b/cpp/examples/cpp_examples/demo_read.cpp
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 #include <iostream>
 #include <string>
 #include <vector>
@@ -23,8 +24,6 @@
 #include "../c_examples/c_examples.h"
 #include "cpp_examples.h"
 
-using namespace storage;
-
 int demo_read() {
 
     int code = 0;
diff --git a/cpp/examples/cpp_examples/demo_write.cpp 
b/cpp/examples/cpp_examples/demo_write.cpp
index 594309b7..a9403666 100644
--- a/cpp/examples/cpp_examples/demo_write.cpp
+++ b/cpp/examples/cpp_examples/demo_write.cpp
@@ -17,21 +17,15 @@
  * under the License.
  */
 
-#include <cwrapper/tsfile_cwrapper.h>
-#include <time.h>
 #include <writer/tsfile_table_writer.h>
 
-#include <iostream>
-#include <random>
 #include <string>
 
 #include "cpp_examples.h"
 
-using namespace storage;
-
 int demo_write() {
-    int code = 0;
-    libtsfile_init();
+
+    storage::libtsfile_init();
 
     std::string table_name = "table1";
 
@@ -56,13 +50,11 @@ int demo_write() {
                                  common::PLAIN, common::ColumnCategory::FIELD),
         });
 
-
-
     // Create a file with specify path to write tsfile.
-    auto* writer = new TsFileTableWriter(&file, schema);
+    auto* writer = new storage::TsFileTableWriter(&file, schema);
 
     // Create tablet to insert data.
-    storage::Tablet tablet = storage::Tablet(
+    storage::Tablet tablet(
         table_name, {"id1", "id2", "s1"},
         {common::STRING, common::STRING, common::INT64},
         {common::ColumnCategory::TAG, common::ColumnCategory::TAG,
@@ -88,6 +80,7 @@ int demo_write() {
     HANDLE_ERROR(writer->close());
 
     delete writer;
+    delete schema;
 
     return 0;
 }
diff --git a/cpp/examples/examples.cc b/cpp/examples/examples.cc
index edbd819a..1b4f4d65 100644
--- a/cpp/examples/examples.cc
+++ b/cpp/examples/examples.cc
@@ -27,7 +27,7 @@ int main() {
     demo_read();
     std::cout << "begin write and read tsfile by c" << std::endl;
     // C examples
-    write_tsfile();
-    read_tsfile();
+    // write_tsfile();
+    // read_tsfile();
     return 0;
 }
\ No newline at end of file

Reply via email to