Skip to content

Commit

Permalink
Add Column Sketches to Bliss (#55)
Browse files Browse the repository at this point in the history
We added Column Sketches as an optional, we can use: cmake .. -DCOMPILE_COLUMNSKETCHES=ON to turn on building Column Sketches

Note that Column Sketches is a private repo, and by default the option is turned off.
  • Loading branch information
altramarine authored Feb 21, 2025
1 parent ba43e8c commit 4281f2c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ add_subdirectory(tests)
# HEADER bliss
# Bliss lib files
# =============================================================================

option(COMPILE_COLUMNSKETCHES "compile_column_sketches" OFF)

add_library(bliss OBJECT
${CMAKE_SOURCE_DIR}/src/bliss/util/timer.h
${CMAKE_SOURCE_DIR}/src/bliss/util/reader.h
Expand All @@ -55,6 +58,7 @@ add_library(bliss OBJECT
${CMAKE_SOURCE_DIR}/src/bliss/bench_lipp.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_alex.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_btree.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_columnsketches.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_skiplist.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_pgm.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_art.h
Expand All @@ -76,6 +80,12 @@ target_link_libraries(bliss PUBLIC
art
)

if(COMPILE_COLUMNSKETCHES)
target_link_libraries(bliss PUBLIC
columnsketches
)
endif()

target_include_directories(bliss PUBLIC
${CMAKE_SOURCE_DIR}/src
)
Expand Down
29 changes: 28 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ endif()
add_library(tlx INTERFACE)
target_include_directories(tlx INTERFACE ${tlx_SOURCE_DIR}/)

FetchContent_Declare(
columnsketches
GIT_REPOSITORY https://github.com/altramarine/ColumnSketches-cpp.git
GIT_TAG main
)

if(COMPILE_COLUMNSKETCHES)
FetchContent_GetProperties(columnsketches)
if (NOT columnsketches_POPULATED)
FetchContent_Populate(columnsketches)
endif()
file(GLOB_RECURSE columnsketches_SOURCES
"${columnsketches_SOURCE_DIR}/src/*.cpp"
)
add_library(columnsketches STATIC ${columnsketches_SOURCES})
target_include_directories(columnsketches PUBLIC ${columnsketches_SOURCE_DIR}/include)
target_link_libraries(columnsketches PUBLIC pthread)
target_compile_options(columnsketches PUBLIC
"-pthread"
"-mavx"
"-mavx2"
"-msse"
"-msse2"
"-O3"
"-DCOMPILE_COLUMNSKETCHES=1"
)
endif()

FetchContent_Declare(
skiplist
Expand Down Expand Up @@ -114,4 +141,4 @@ if (NOT pgm_POPULATED)
endif()

add_library(pgm INTERFACE)
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})
56 changes: 56 additions & 0 deletions src/bliss/bench_columnsketches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef BLISS_BENCH_COLUMNSKETCHES
#define BLISS_BENCH_COLUMNSKETCHES
#ifdef COMPILE_COLUMNSKETCHES
#include <vector>

#include "bliss/bliss_index.h"
#include "column_sketches.h"

namespace bliss {

template <typename KEY_TYPE, typename VALUE_TYPE>
class BlissColumnSketchesIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
public:
BlissColumnSketchesIndex() {
columnsketches_ = new ColumnSketchesInteger();
};

~BlissColumnSketchesIndex() {
delete columnsketches_;
}

void bulkload(
std::vector<std::pair<KEY_TYPE, VALUE_TYPE>> values) override {
std::vector<int32_t> vals;
for(auto x: values) {
vals.push_back(x.second);
}
columnsketches_->create(&vals[0], vals.size(), vals.size());
}

bool get(VALUE_TYPE start, VALUE_TYPE end) {
uint32_t *res = columnsketches_->query_ge_lt(start, end);
bool succeed = res != nullptr;
if(succeed) delete res;
return succeed;
}

bool get(KEY_TYPE key) override {
std::runtime_error("Column Imprints does not support get(key, value).");
return false;
}

void put(KEY_TYPE key, VALUE_TYPE value) {
std::runtime_error("Column Imprints does not support put(key, value).");
return;
}

void end_routine() override {}
private:

ColumnSketchesInteger *columnsketches_;
};

} // namespace bliss
#endif
#endif // !BLISS_BENCH_BTREE
2 changes: 1 addition & 1 deletion src/bliss/bliss_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class BlissIndex {

} // namespace bliss

#endif // !BLISS_INDEX
#endif // !BLISS_INDEX
8 changes: 8 additions & 0 deletions src/bliss_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "bliss/bench_btree.h"
#include "bliss/bench_leveldb.h"
#include "bliss/bench_lipp.h"
#include "bliss/bench_columnsketches.h"
#include "bliss/bench_pgm.h"
#include "bliss/bench_skiplist.h"
#include "bliss/bliss_index.h"
Expand Down Expand Up @@ -174,6 +175,13 @@ int main(int argc, char *argv[]) {
index.reset(new bliss::BlissLippIndex<key_type, value_type>());
} else if (config.index == "btree") {
index.reset(new bliss::BlissBTreeIndex<key_type, value_type>());
} else if (config.index == "columnskteches") {
#ifdef COMPILE_COLUMNSKETCHES
index.reset(new bliss::BlissColumnSketchesIndex<key_type, value_type>());
#else
std::runtime_error("Column Sketches is not Imported");
exit(0);
#endif
} else if (config.index == "skiplist") {
index.reset(new bliss::BlissSkipListIndex<key_type, value_type>());
} else if (config.index == "art") {
Expand Down

0 comments on commit 4281f2c

Please sign in to comment.