approx_distinct_count.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
9 #include <cudf/types.hpp>
11 #include <cudf/utilities/export.hpp>
13 
14 #include <cuda/std/span>
15 #include <cuda/stream>
16 
17 #include <cstddef>
18 #include <cstdint>
19 #include <memory>
20 
26 namespace CUDF_EXPORT cudf {
27 
33 // Forward declarations
34 namespace hashing::detail {
35 template <typename Key>
36 struct XXHash_64;
37 }
38 
39 namespace detail {
40 template <template <typename> class Hasher>
42 }
43 
91  public:
92  using impl_type =
94 
108  double value;
109 
114  explicit constexpr desired_standard_error(double v) : value{v} {}
115  };
116 
129  std::int32_t precision = 12,
130  null_policy null_handling = null_policy::EXCLUDE,
131  nan_policy nan_handling = nan_policy::NAN_IS_NULL,
132  cuda::stream_ref stream = cudf::get_default_stream(),
133  cuda::mr::any_resource<cuda::mr::device_accessible> mr =
135 
159  null_policy null_handling = null_policy::EXCLUDE,
160  nan_policy nan_handling = nan_policy::NAN_IS_NULL,
161  cuda::stream_ref stream = cudf::get_default_stream(),
162  cuda::mr::any_resource<cuda::mr::device_accessible> mr =
164 
180  approx_distinct_count(cuda::std::span<cuda::std::byte> sketch_span,
181  std::int32_t precision,
182  null_policy null_handling = null_policy::EXCLUDE,
183  nan_policy nan_handling = nan_policy::NAN_IS_NULL);
184 
186 
188  approx_distinct_count& operator=(approx_distinct_count const&) = delete;
196 
203  void add(table_view const& input, cuda::stream_ref stream = cudf::get_default_stream());
204 
217  void merge(approx_distinct_count const& other,
218  cuda::stream_ref stream = cudf::get_default_stream());
219 
233  void merge(cuda::std::span<cuda::std::byte const> sketch_span,
234  cuda::stream_ref stream = cudf::get_default_stream());
235 
242  [[nodiscard]] std::size_t estimate(cuda::stream_ref stream = cudf::get_default_stream()) const;
243 
253  [[nodiscard]] cuda::std::span<cuda::std::byte> sketch() noexcept;
254 
264  [[nodiscard]] cuda::std::span<cuda::std::byte const> sketch() const noexcept;
265 
271  [[nodiscard]] null_policy null_handling() const noexcept;
272 
278  [[nodiscard]] nan_policy nan_handling() const noexcept;
279 
285  [[nodiscard]] std::int32_t precision() const noexcept;
286 
295  [[nodiscard]] double standard_error() const noexcept;
296 
303  [[nodiscard]] static std::size_t sketch_bytes(std::int32_t precision);
304 
310  [[nodiscard]] static std::size_t sketch_alignment();
311 
312  private:
313  std::unique_ptr<impl_type> _impl;
314 };
315 
318 } // namespace CUDF_EXPORT cudf
Object-oriented HyperLogLog sketch for approximate distinct counting.
approx_distinct_count(table_view const &input, std::int32_t precision=12, null_policy null_handling=null_policy::EXCLUDE, nan_policy nan_handling=nan_policy::NAN_IS_NULL, cuda::stream_ref stream=cudf::get_default_stream(), cuda::mr::any_resource< cuda::mr::device_accessible > mr=cudf::get_current_device_resource_ref())
Constructs an approximate distinct count sketch from a table with specified precision.
void add(table_view const &input, cuda::stream_ref stream=cudf::get_default_stream())
Adds rows from a table to the sketch.
void merge(approx_distinct_count const &other, cuda::stream_ref stream=cudf::get_default_stream())
Merges another sketch into this sketch.
std::size_t estimate(cuda::stream_ref stream=cudf::get_default_stream()) const
Estimates the approximate number of distinct rows in the sketch.
approx_distinct_count(approx_distinct_count &&)=default
Default move constructor.
approx_distinct_count & operator=(approx_distinct_count &&)=default
Move assignment operator.
approx_distinct_count(cuda::std::span< cuda::std::byte > sketch_span, std::int32_t precision, null_policy null_handling=null_policy::EXCLUDE, nan_policy nan_handling=nan_policy::NAN_IS_NULL)
Constructs a non-owning sketch that operates on user-allocated storage.
void merge(cuda::std::span< cuda::std::byte const > sketch_span, cuda::stream_ref stream=cudf::get_default_stream())
Merges a sketch from raw bytes into this sketch.
approx_distinct_count(table_view const &input, desired_standard_error error, null_policy null_handling=null_policy::EXCLUDE, nan_policy nan_handling=nan_policy::NAN_IS_NULL, cuda::stream_ref stream=cudf::get_default_stream(), cuda::mr::any_resource< cuda::mr::device_accessible > mr=cudf::get_current_device_resource_ref())
Constructs an approximate distinct count sketch from a table with specified standard error.
cuda::std::span< cuda::std::byte > sketch() noexcept
Gets the raw sketch bytes for serialization or external merging.
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
APIs for querying the default CUDA stream and per-thread default stream status.
cuda::stream_ref const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
null_policy
Enum to specify whether to include nulls or exclude nulls.
Definition: types.hpp:107
nan_policy
Enum to treat NaN floating point value as null or non-null element.
Definition: types.hpp:115
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
Strong type wrapper for the desired standard error constructor parameter.
double value
The requested standard error value (must be positive)
constexpr desired_standard_error(double v)
Constructs a desired_standard_error with the given value.
Class definitions for (mutable)_table_view
Type declarations for libcudf.