Skip to content

Commit fdc9f69

Browse files
gengdy1545whzrucAntiO2
authored
[Issue pixelsdb#802] implement cpp version of writer (pixelsdb#803)
Co-authored-by: whzruc <whzsxdt@126.com> Co-authored-by: AntiO2 <antio2@qq.com>
1 parent 70866b9 commit fdc9f69

File tree

90 files changed

+5008
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5008
-45
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "cpp/pixels-duckdb"]
55
path = cpp/pixels-duckdb
66
url = git@github.com:pixelsdb/duckdb.git
7+
[submodule "writer_cpp_test/third-party/protobuf"]
8+
path = writer_cpp_test/third-party/protobuf
9+
url = https://github.com/protocolbuffers/protobuf
10+
[submodule "cpp/third-party/googletest"]
11+
path = cpp/third-party/googletest
12+
url = git@github.com:google/googletest.git

cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
2020

2121
add_subdirectory(pixels-common)
2222
add_subdirectory(pixels-core)
23+
add_subdirectory(pixels-cli)
24+
add_subdirectory(third-party/googletest)
2325
add_subdirectory(tests)
2426

2527
include_directories(pixels-common/include)

cpp/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ clean:
4949

5050
# Main build
5151
debug: deps
52-
mkdir -p build/debug && \
5352
cmake $(GENERATOR) $(FORCE_COLOR) $(EXTENSION_FLAGS) ${CLIENT_FLAGS} -DEXTENSION_STATIC_BUILD=1 -DCMAKE_BUILD_TYPE=Debug ${BUILD_FLAGS} -S pixels-duckdb/ -B build/debug && \
5453
cmake --build build/debug --config Debug
5554

5655
release: deps
57-
mkdir -p build/release && \
5856
cmake $(GENERATOR) $(FORCE_COLOR) $(EXTENSION_FLAGS) ${CLIENT_FLAGS} -DEXTENSION_STATIC_BUILD=1 -DCMAKE_BUILD_TYPE=Release ${BUILD_FLAGS} -S pixels-duckdb/ -B build/release && \
5957
cmake --build build/release --config Release

cpp/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,37 @@ def clean_page_cache():
246246

247247
### 5. The protobuf version issue
248248
I use protobuf [v3.21.6](https://github.com/protocolbuffers/protobuf/releases/tag/v3.21.6). The latest protobuf version doesn't work for pixels c++ reader.
249+
250+
### 6. Install Boost C++ Libraries
251+
We need the Boost C++ Libraries in pixels-cli, which can be installed with the following command.
252+
253+
```
254+
sudo apt-get install libboost-all-dev
255+
```
256+
257+
For every Boost release this information is added by the CMake maintainers and it gets part of the next CMake release. So you have to make sure, that your CMake version was released after the Boost version you try to find.
258+
259+
```
260+
Boost 1.63 requires CMake 3.7 or newer.
261+
Boost 1.64 requires CMake 3.8 or newer.
262+
Boost 1.65 and 1.65.1 require CMake 3.9.3 or newer.
263+
Boost 1.66 requires CMake 3.11 or newer.
264+
Boost 1.67 requires CMake 3.12 or newer.
265+
Boost 1.68, 1.69 require CMake 3.13 or newer.
266+
Boost 1.70 requires CMake 3.14 or newer.
267+
Boost 1.71 requires CMake 3.15.3 or newer.
268+
Boost 1.72 requires CMake 3.16.2 or newer.
269+
Boost 1.73 requires CMake 3.17.2 or newer.
270+
Boost 1.74 requires CMake 3.19 or newer.
271+
Boost 1.75 requires CMake 3.19.5 or newer.
272+
Boost 1.76 requires CMake 3.20.3 or newer.
273+
Boost 1.77 requires CMake 3.21.3 or newer.
274+
Boost 1.78 requires CMake 3.22.2 or newer.
275+
Boost 1.79 requires CMake 3.23.2 or newer.
276+
Boost 1.80 requires CMake 3.24.2 or newer.
277+
Boost 1.81 requires CMake 3.25.2 or newer.
278+
Boost 1.82 requires CMake 3.27.0 or newer.
279+
Boost 1.83 requires CMake 3.27.4 or newer.
280+
Boost 1.84 requires CMake 3.28.2 or newer.
281+
Boost 1.85 requires CMake 3.29.3 or newer.
282+
```

cpp/pixels-cli/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
project(pixels-cli)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(Boost_USE_STATIC_LIBS ON)
6+
set(Boost_USE_MULTITHREADED ON)
7+
8+
if(POLICY CMP0057)
9+
cmake_policy(SET CMP0057 NEW)
10+
endif()
11+
12+
if(POLICY CMP0167)
13+
cmake_policy(SET CMP0167 NEW)
14+
endif()
15+
16+
find_package(Boost REQUIRED COMPONENTS program_options regex)
17+
if(Boost_FOUND)
18+
include_directories(${Boost_INCLUDE_DIRS})
19+
else()
20+
message(FATAL_ERROR "Could not find Boost")
21+
endif()
22+
23+
set(pixels_cli_cxx
24+
main.cpp
25+
lib/executor/LoadExecutor.cpp
26+
lib/load/Parameters.cpp
27+
lib/load/PixelsConsumer.cpp)
28+
add_executable(pixels-cli ${pixels_cli_cxx})
29+
include_directories(include)
30+
include_directories(../pixels-core/include)
31+
include_directories(../pixels-common/include)
32+
target_link_libraries(pixels-cli Boost::program_options Boost::regex pixels-core pixels-common duckdb)

cpp/pixels-cli/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY: all clean
2+
3+
all:
4+
cmake -B build
5+
cmake --build build
6+
7+
clean:
8+
rm -rf build
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 PixelsDB.
3+
*
4+
* This file is part of Pixels.
5+
*
6+
* Pixels is free software: you can redistribute it and/or modify
7+
* it under the terms of the Affero GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* Pixels is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* Affero GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the Affero GNU General Public
17+
* License along with Pixels. If not, see
18+
* <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
//
22+
// Created by gengdy on 24-11-17.
23+
//
24+
25+
#ifndef PIXELS_COMMANDEXECUTOR_H
26+
#define PIXELS_COMMANDEXECUTOR_H
27+
28+
#include <boost/program_options.hpp>
29+
#include <string>
30+
31+
namespace bpo = boost::program_options;
32+
33+
class CommandExecutor {
34+
public:
35+
virtual ~CommandExecutor() = default;
36+
virtual void execute(const bpo::variables_map& ns, const std::string& command) = 0;
37+
};
38+
#endif //PIXELS_COMMANDEXECUTOR_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2024 PixelsDB.
3+
*
4+
* This file is part of Pixels.
5+
*
6+
* Pixels is free software: you can redistribute it and/or modify
7+
* it under the terms of the Affero GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* Pixels is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* Affero GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the Affero GNU General Public
17+
* License along with Pixels. If not, see
18+
* <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
//
22+
// Created by gengdy on 24-11-17.
23+
//
24+
25+
#ifndef PIXELS_LOADEXECUTOR_H
26+
#define PIXELS_LOADEXECUTOR_H
27+
28+
#include <executor/CommandExecutor.h>
29+
#include <vector>
30+
#include <load/Parameters.h>
31+
32+
class LoadExecutor : public CommandExecutor {
33+
public:
34+
void execute(const bpo::variables_map& ns, const std::string& command) override;
35+
private:
36+
bool startConsumers(const std::vector<std::string> &inputFiles, Parameters parameters,
37+
const std::vector<std::string> &loadedFiles);
38+
};
39+
#endif //PIXELS_LOADEXECUTOR_H
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2024 PixelsDB.
3+
*
4+
* This file is part of Pixels.
5+
*
6+
* Pixels is free software: you can redistribute it and/or modify
7+
* it under the terms of the Affero GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* Pixels is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* Affero GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the Affero GNU General Public
17+
* License along with Pixels. If not, see
18+
* <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
//
22+
// Created by gengdy on 24-11-19.
23+
//
24+
25+
#ifndef PIXELS_PARAMETERS_H
26+
#define PIXELS_PARAMETERS_H
27+
28+
#include <string>
29+
#include <encoding/EncodingLevel.h>
30+
31+
class Parameters {
32+
public:
33+
Parameters(const std::string &schema, int maxRowNum, const std::string &regex,
34+
const std::string &loadingPath, EncodingLevel encodingLevel, bool nullsPadding);
35+
std::string getLoadingPath() const;
36+
std::string getSchema() const;
37+
int getMaxRowNum() const;
38+
std::string getRegex() const;
39+
EncodingLevel getEncodingLevel() const;
40+
bool isNullsPadding() const;
41+
42+
private:
43+
std::string schema;
44+
int maxRowNum;
45+
std::string regex;
46+
std::string loadingPath;
47+
EncodingLevel encodingLevel;
48+
bool nullsPadding;
49+
};
50+
#endif //PIXELS_PARAMETERS_H
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2024 PixelsDB.
3+
*
4+
* This file is part of Pixels.
5+
*
6+
* Pixels is free software: you can redistribute it and/or modify
7+
* it under the terms of the Affero GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* Pixels is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* Affero GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the Affero GNU General Public
17+
* License along with Pixels. If not, see
18+
* <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
//
22+
// Created by gengdy on 24-11-22.
23+
//
24+
25+
#ifndef PIXELS_PIXELSCONSUMER_H
26+
#define PIXELS_PIXELSCONSUMER_H
27+
28+
#include <vector>
29+
#include <string>
30+
#include <load/Parameters.h>
31+
32+
class PixelsConsumer {
33+
public:
34+
PixelsConsumer(const std::vector<std::string> &queue, const Parameters &parameters, const std::vector<std::string> &loadedFiles);
35+
void run();
36+
private:
37+
static int GlobalTargetPathId;
38+
std::vector<std::string> queue;
39+
Parameters parameters;
40+
std::vector<std::string> loadedFiles;
41+
};
42+
#endif //PIXELS_PIXELSCONSUMER_H

0 commit comments

Comments
 (0)