From df78a1b3fd207a0a3d071d155ed121d427d753d0 Mon Sep 17 00:00:00 2001 From: pingyu Date: Sat, 10 Apr 2021 23:00:34 +0800 Subject: [PATCH] address review comments --- cmake/find/datasketches.cmake | 2 ++ .../AggregateFunctionUniq.cpp | 3 +++ .../AggregateFunctionUniq.h | 7 ++++-- src/AggregateFunctions/ThetaSketchData.h | 22 ++++++++++++------- src/Common/config.h.in | 1 + ...ence => 01798_uniq_theta_sketch.reference} | 0 ...sketch.sql => 01798_uniq_theta_sketch.sql} | 0 7 files changed, 25 insertions(+), 10 deletions(-) rename tests/queries/0_stateless/{01781_uniq_theta_sketch.reference => 01798_uniq_theta_sketch.reference} (100%) rename tests/queries/0_stateless/{01781_uniq_theta_sketch.sql => 01798_uniq_theta_sketch.sql} (100%) diff --git a/cmake/find/datasketches.cmake b/cmake/find/datasketches.cmake index 44ef324a9f2..acd67f0f2bf 100644 --- a/cmake/find/datasketches.cmake +++ b/cmake/find/datasketches.cmake @@ -22,6 +22,8 @@ endif() if (DATASKETCHES_LIBRARY AND DATASKETCHES_INCLUDE_DIR) set(USE_DATASKETCHES 1) +else() + set(USE_DATASKETCHES 0) endif() endif() diff --git a/src/AggregateFunctions/AggregateFunctionUniq.cpp b/src/AggregateFunctions/AggregateFunctionUniq.cpp index e0de9f319f7..e4f6126749b 100644 --- a/src/AggregateFunctions/AggregateFunctionUniq.cpp +++ b/src/AggregateFunctions/AggregateFunctionUniq.cpp @@ -133,8 +133,11 @@ void registerAggregateFunctionsUniq(AggregateFunctionFactory & factory) factory.registerFunction("uniqExact", {createAggregateFunctionUniq>, properties}); +#if USE_DATASKETCHES factory.registerFunction("uniqThetaSketch", {createAggregateFunctionUniq, properties}); +#endif + } } diff --git a/src/AggregateFunctions/AggregateFunctionUniq.h b/src/AggregateFunctions/AggregateFunctionUniq.h index c9264ae4074..18974af3b2a 100644 --- a/src/AggregateFunctions/AggregateFunctionUniq.h +++ b/src/AggregateFunctions/AggregateFunctionUniq.h @@ -126,7 +126,7 @@ struct AggregateFunctionUniqExactData /// uniqThetaSketch - +#if USE_DATASKETCHES struct AggregateFunctionUniqThetaSketchData { using Set = ThetaSketchData; @@ -143,6 +143,7 @@ struct AggregateFunctionUniqThetaSketchDataForVariadic static String getName() { return "uniqThetaSketch"; } }; +#endif namespace detail { @@ -209,10 +210,12 @@ struct OneAdder data.set.insert(key); } } +#if USE_DATASKETCHES else if constexpr (std::is_same_v) { - data.set.insert_original(column.getDataAt(row_num)); + data.set.insertOriginal(column.getDataAt(row_num)); } +#endif } }; diff --git a/src/AggregateFunctions/ThetaSketchData.h b/src/AggregateFunctions/ThetaSketchData.h index 4f26563f75b..5b9c81279fc 100644 --- a/src/AggregateFunctions/ThetaSketchData.h +++ b/src/AggregateFunctions/ThetaSketchData.h @@ -1,10 +1,14 @@ #pragma once +#include + +#if USE_DATASKETCHES + #include +#include #include #include -#include namespace DB { @@ -17,14 +21,14 @@ private: std::unique_ptr sk_update; std::unique_ptr sk_union; - inline datasketches::update_theta_sketch * get_sk_update() + inline datasketches::update_theta_sketch * getSkUpdate() { if (!sk_update) sk_update = std::make_unique(datasketches::update_theta_sketch::builder().build()); return sk_update.get(); } - inline datasketches::theta_union * get_sk_union() + inline datasketches::theta_union * getSkUnion() { if (!sk_union) sk_union = std::make_unique(datasketches::theta_union::builder().build()); @@ -38,15 +42,15 @@ public: ~ThetaSketchData() = default; /// Insert original value without hash, as `datasketches::update_theta_sketch.update` will do the hash internal. - void insert_original(const StringRef & value) + void insertOriginal(const StringRef & value) { - get_sk_update()->update(value.data, value.size); + getSkUpdate()->update(value.data, value.size); } /// Note that `datasketches::update_theta_sketch.update` will do the hash again. void insert(Key value) { - get_sk_update()->update(value); + getSkUpdate()->update(value); } UInt64 size() const @@ -61,7 +65,7 @@ public: void merge(const ThetaSketchData & rhs) { - datasketches::theta_union * u = get_sk_union(); + datasketches::theta_union * u = getSkUnion(); if (sk_update) { @@ -83,7 +87,7 @@ public: if (!bytes.empty()) { auto sk = datasketches::compact_theta_sketch::deserialize(bytes.data(), bytes.size()); - get_sk_union()->update(sk); + getSkUnion()->update(sk); } } @@ -109,3 +113,5 @@ public: } + +#endif diff --git a/src/Common/config.h.in b/src/Common/config.h.in index ee2bfe3df53..28a21ea7764 100644 --- a/src/Common/config.h.in +++ b/src/Common/config.h.in @@ -15,3 +15,4 @@ #cmakedefine01 USE_GRPC #cmakedefine01 USE_STATS #cmakedefine01 CLICKHOUSE_SPLIT_BINARY +#cmakedefine01 USE_DATASKETCHES diff --git a/tests/queries/0_stateless/01781_uniq_theta_sketch.reference b/tests/queries/0_stateless/01798_uniq_theta_sketch.reference similarity index 100% rename from tests/queries/0_stateless/01781_uniq_theta_sketch.reference rename to tests/queries/0_stateless/01798_uniq_theta_sketch.reference diff --git a/tests/queries/0_stateless/01781_uniq_theta_sketch.sql b/tests/queries/0_stateless/01798_uniq_theta_sketch.sql similarity index 100% rename from tests/queries/0_stateless/01781_uniq_theta_sketch.sql rename to tests/queries/0_stateless/01798_uniq_theta_sketch.sql