Skip to content

Commit 0d71e2c

Browse files
authored
Merge pull request apache#492 from proost/doc-update-utf8-compatibility
2 parents 1a23698 + a9b4275 commit 0d71e2c

9 files changed

Lines changed: 114 additions & 2 deletions

File tree

common/include/serde.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ struct serde<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
132132
/// ItemsSketch<String> with ArrayOfStringsSerDe in Java.
133133
/// The length of each string is stored as a 32-bit integer (historically),
134134
/// which may be too wasteful. Treat this as an example.
135+
///
136+
/// This implementation treats std::string as an arbitrary byte container.
137+
/// It does not check whether string contents are valid UTF-8.
138+
///
139+
/// Use a UTF-8-validating SerDe when cross-language portability is required.
135140
template<>
136141
struct serde<std::string> {
137142
/// @copydoc serde::serialize

fi/include/frequent_items_sketch.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ enum frequent_items_error_type {
4444
* Based on Java implementation here:
4545
* https://github.com/apache/datasketches-java/blob/master/src/main/java/org/apache/datasketches/frequencies/ItemsSketch.java
4646
* @author Alexander Saydakov
47+
*
48+
* Sketch that may retain string values.
49+
* For sketches containing strings, cross-language portability depends on
50+
* using compatible string encodings. This class does not by itself enforce
51+
* UTF-8 validity for all string inputs.
4752
*/
4853
template<
4954
typename T,
@@ -74,6 +79,8 @@ class frequent_items_sketch {
7479

7580
/**
7681
* Update this sketch with an item and a positive weight (frequency count).
82+
* If cross-language portability is required, callers should ensure that
83+
* the input string uses a compatible encoding (valid UTF-8).
7784
* @param item for which the weight should be increased (lvalue)
7885
* @param weight the amount by which the weight of the item should be increased
7986
* A count of zero is a no-op, and a negative count will throw an exception.
@@ -82,6 +89,8 @@ class frequent_items_sketch {
8289

8390
/**
8491
* Update this sketch with an item and a positive weight (frequency count).
92+
* If cross-language portability is required, callers should ensure that
93+
* the input string uses a compatible encoding (valid UTF-8).
8594
* @param item for which the weight should be increased (rvalue)
8695
* @param weight the amount by which the weight of the item should be increased
8796
* A count of zero is a no-op, and a negative count will throw an exception.
@@ -91,13 +100,17 @@ class frequent_items_sketch {
91100
/**
92101
* This function merges the other sketch into this one.
93102
* The other sketch may be of a different size.
103+
* If sketches contain strings, callers are responsible for ensuring that
104+
* both sketches were built using compatible string encodings.
94105
* @param other sketch to be merged into this (lvalue)
95106
*/
96107
void merge(const frequent_items_sketch& other);
97108

98109
/**
99110
* This function merges the other sketch into this one.
100111
* The other sketch may be of a different size.
112+
* If sketches contain strings, callers are responsible for ensuring that
113+
* both sketches were built using compatible string encodings.
101114
* @param other sketch to be merged into this (rvalue)
102115
*/
103116
void merge(frequent_items_sketch&& other);

kll/include/kll_sketch.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ namespace kll_constants {
4646
* and nearly optimal accuracy per retained item.
4747
* See <a href="https://arxiv.org/abs/1603.05346v2">Optimal Quantile Approximation in Streams</a>.
4848
*
49+
* Sketch that may retain string values.
50+
* For sketches containing strings, cross-language portability depends on
51+
* using compatible string encodings. This class does not by itself enforce
52+
* UTF-8 validity for all string inputs.
53+
*
4954
* <p>This is a stochastic streaming sketch that enables near real-time analysis of the
5055
* approximate distribution of items from a very large stream in a single pass, requiring only
5156
* that the items are comparable.
@@ -56,7 +61,7 @@ namespace kll_constants {
5661
* <p>As of May 2020, this implementation produces serialized sketches which are binary-compatible
5762
* with the equivalent Java implementation only when template parameter T = float
5863
* (32-bit single precision values).
59-
*
64+
*
6065
* <p>Given an input stream of <i>N</i> items, the <i>natural rank</i> of any specific
6166
* item is defined as its index <i>(1 to N)</i> in inclusive mode
6267
* or <i>(0 to N-1)</i> in exclusive mode
@@ -225,13 +230,17 @@ class kll_sketch {
225230

226231
/**
227232
* Updates this sketch with the given data item.
233+
* If cross-language portability is required, callers should ensure that
234+
* the input string uses a compatible encoding (valid UTF-8).
228235
* @param item from a stream of items
229236
*/
230237
template<typename FwdT>
231238
void update(FwdT&& item);
232239

233240
/**
234241
* Merges another sketch into this one.
242+
* If sketches contain strings, callers are responsible for ensuring that
243+
* both sketches were built using compatible string encodings.
235244
* @param other sketch to merge into this one
236245
*/
237246
template<typename FwdSk>

quantiles/include/quantiles_sketch.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ namespace quantiles_constants {
4747
* The analysis is obtained using get_rank() and get_quantile() functions,
4848
* the Probability Mass Function from get_PMF() and the Cumulative Distribution Function from get_CDF().
4949
*
50+
* Sketch that may retain string values.
51+
* For sketches containing strings, cross-language portability depends on
52+
* using compatible string encodings. This class does not by itself enforce
53+
* UTF-8 validity for all string inputs.
54+
*
5055
* <p>Consider a large stream of one million values such as packet sizes coming into a network node.
5156
* The natural rank of any specific size value is its index in the hypothetical sorted
5257
* array of values.
@@ -206,13 +211,17 @@ class quantiles_sketch {
206211

207212
/**
208213
* Updates this sketch with the given data item.
214+
* If cross-language portability is required, callers should ensure that
215+
* the input string uses a compatible encoding (valid UTF-8).
209216
* @param item from a stream of items
210217
*/
211218
template<typename FwdT>
212219
void update(FwdT&& item);
213220

214221
/**
215222
* Merges another sketch into this one.
223+
* If sketches contain strings, callers are responsible for ensuring that
224+
* both sketches were built using compatible string encodings.
216225
* @param other sketch to merge into this one
217226
*/
218227
template<typename FwdSk>

req/include/req_sketch.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ namespace datasketches {
3535
* "Relative Error Streaming Quantiles" by Graham Cormode, Zohar Karnin, Edo Liberty,
3636
* Justin Thaler, Pavel Veselý, and loosely derived from a Python prototype written by Pavel Veselý.
3737
*
38+
* Sketch that may retain string values.
39+
* For sketches containing strings, cross-language portability depends on
40+
* using compatible string encodings. This class does not by itself enforce
41+
* UTF-8 validity for all string inputs.
42+
*
3843
* <p>Reference: https://arxiv.org/abs/2004.01668</p>
3944
*
4045
* <p>This implementation differs from the algorithm described in the paper in the following:</p>
@@ -179,13 +184,17 @@ class req_sketch {
179184

180185
/**
181186
* Updates this sketch with the given data item.
187+
* If cross-language portability is required, callers should ensure that
188+
* the input string uses a compatible encoding (valid UTF-8).
182189
* @param item from a stream of items
183190
*/
184191
template<typename FwdT>
185192
void update(FwdT&& item);
186193

187194
/**
188195
* Merges another sketch into this one.
196+
* If sketches contain strings, callers are responsible for ensuring that
197+
* both sketches were built using compatible string encodings.
189198
* @param other sketch to merge into this one
190199
*/
191200
template<typename FwdSk>

sampling/include/ebpps_sketch.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ namespace ebpps_constants {
5050
* The sample may be smaller than k and the resulting size of the sample potentially includes
5151
* a probabilistic component, meaning the resulting sample size is not always constant.
5252
*
53+
* Sketch that may retain string values.
54+
* For sketches containing strings, cross-language portability depends on
55+
* using compatible string encodings. This class does not by itself enforce
56+
* UTF-8 validity for all string inputs.
57+
*
5358
* @author Jon Malkin
5459
*/
5560
template<
@@ -71,6 +76,8 @@ class ebpps_sketch {
7176
/**
7277
* Updates this sketch with the given data item with the given weight.
7378
* This method takes an lvalue.
79+
* If cross-language portability is required, callers should ensure that
80+
* the input string uses a compatible encoding (valid UTF-8).
7481
* @param item an item from a stream of items
7582
* @param weight the weight of the item
7683
*/
@@ -79,6 +86,8 @@ class ebpps_sketch {
7986
/**
8087
* Updates this sketch with the given data item with the given weight.
8188
* This method takes an rvalue.
89+
* If cross-language portability is required, callers should ensure that
90+
* the input string uses a compatible encoding (valid UTF-8).
8291
* @param item an item from a stream of items
8392
* @param weight the weight of the item
8493
*/
@@ -87,13 +96,17 @@ class ebpps_sketch {
8796
/**
8897
* Merges the provided sketch into the current one.
8998
* This method takes an lvalue.
99+
* If sketches contain strings, callers are responsible for ensuring that
100+
* both sketches were built using compatible string encodings.
90101
* @param sketch the sketch to merge into the current object
91102
*/
92103
void merge(const ebpps_sketch<T, A>& sketch);
93104

94105
/**
95106
* Merges the provided sketch into the current one.
96107
* This method takes an rvalue.
108+
* If sketches contain strings, callers are responsible for ensuring that
109+
* both sketches were built using compatible string encodings.
97110
* @param sketch the sketch to merge into the current object
98111
*/
99112
void merge(ebpps_sketch<T, A>&& sketch);

sampling/include/var_opt_sketch.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ namespace var_opt_constants {
5757
* optimal (varopt) sampling is related to reservoir sampling, with improved error bounds for
5858
* subset sum estimation.
5959
*
60+
* Sketch that may retain string values.
61+
* For sketches containing strings, cross-language portability depends on
62+
* using compatible string encodings. This class does not by itself enforce
63+
* UTF-8 validity for all string inputs.
64+
*
6065
* author Kevin Lang
6166
* author Jon Malkin
6267
*/
@@ -111,6 +116,8 @@ class var_opt_sketch {
111116
/**
112117
* Updates this sketch with the given data item with the given weight.
113118
* This method takes an lvalue.
119+
* If cross-language portability is required, callers should ensure that
120+
* the input string uses a compatible encoding (valid UTF-8).
114121
* @param item an item from a stream of items
115122
* @param weight the weight of the item
116123
*/
@@ -119,6 +126,8 @@ class var_opt_sketch {
119126
/**
120127
* Updates this sketch with the given data item with the given weight.
121128
* This method takes an rvalue.
129+
* If cross-language portability is required, callers should ensure that
130+
* the input string uses a compatible encoding (valid UTF-8).
122131
* @param item an item from a stream of items
123132
* @param weight the weight of the item
124133
*/

sampling/include/var_opt_union.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ class var_opt_union {
6565
/**
6666
* Updates this union with the given sketch
6767
* This method takes an lvalue.
68+
* If sketches contain strings, callers are responsible for ensuring that
69+
* both sketches were built using compatible string encodings.
6870
* @param sk a sketch to add to the union
6971
*/
7072
void update(const var_opt_sketch<T, A>& sk);
71-
73+
7274
/**
7375
* Updates this union with the given sketch
7476
* This method takes an rvalue.
77+
* If sketches contain strings, callers are responsible for ensuring that
78+
* both sketches were built using compatible string encodings.
7579
* @param sk a sketch to add to the union
7680
*/
7781
void update(var_opt_sketch<T, A>&& sk);

tuple/include/tuple_sketch.hpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ struct pair_extract_key {
4646
/**
4747
* Base class for Tuple sketch.
4848
* This is an extension of Theta sketch that allows keeping arbitrary Summary associated with each retained key.
49+
*
50+
* Summary that may retain string values.
51+
* For Summary containing strings, cross-language portability depends on
52+
* using compatible string encodings. This class does not by itself enforce
53+
* UTF-8 validity for all string inputs.
4954
*/
5055
template<
5156
typename Summary,
@@ -253,6 +258,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
253258

254259
/**
255260
* Update this sketch with a given string.
261+
* If the summary contains strings and cross-language portability is required,
262+
* callers should ensure that any strings in the summary
263+
* use a compatible encoding (valid UTF-8).
256264
* @param key string to update the sketch with
257265
* @param value to update the sketch with
258266
*/
@@ -261,6 +269,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
261269

262270
/**
263271
* Update this sketch with a given unsigned 64-bit integer.
272+
* If the summary contains strings and cross-language portability is required,
273+
* callers should ensure that any strings in the summary
274+
* use a compatible encoding (valid UTF-8).
264275
* @param key uint64_t to update the sketch with
265276
* @param value to update the sketch with
266277
*/
@@ -269,6 +280,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
269280

270281
/**
271282
* Update this sketch with a given signed 64-bit integer.
283+
* If the summary contains strings and cross-language portability is required,
284+
* callers should ensure that any strings in the summary
285+
* use a compatible encoding (valid UTF-8).
272286
* @param key int64_t to update the sketch with
273287
* @param value to update the sketch with
274288
*/
@@ -277,6 +291,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
277291

278292
/**
279293
* Update this sketch with a given unsigned 32-bit integer.
294+
* If the summary contains strings and cross-language portability is required,
295+
* callers should ensure that any strings in the summary
296+
* use a compatible encoding (valid UTF-8).
280297
* For compatibility with Java implementation.
281298
* @param key uint32_t to update the sketch with
282299
* @param value to update the sketch with
@@ -286,6 +303,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
286303

287304
/**
288305
* Update this sketch with a given signed 32-bit integer.
306+
* If the summary contains strings and cross-language portability is required,
307+
* callers should ensure that any strings in the summary
308+
* use a compatible encoding (valid UTF-8).
289309
* For compatibility with Java implementation.
290310
* @param key int32_t to update the sketch with
291311
* @param value to update the sketch with
@@ -295,6 +315,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
295315

296316
/**
297317
* Update this sketch with a given unsigned 16-bit integer.
318+
* If the summary contains strings and cross-language portability is required,
319+
* callers should ensure that any strings in the summary
320+
* use a compatible encoding (valid UTF-8).
298321
* For compatibility with Java implementation.
299322
* @param key uint16_t to update the sketch with
300323
* @param value to update the sketch with
@@ -304,6 +327,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
304327

305328
/**
306329
* Update this sketch with a given signed 16-bit integer.
330+
* If the summary contains strings and cross-language portability is required,
331+
* callers should ensure that any strings in the summary
332+
* use a compatible encoding (valid UTF-8).
307333
* For compatibility with Java implementation.
308334
* @param key int16_t to update the sketch with
309335
* @param value to update the sketch with
@@ -313,6 +339,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
313339

314340
/**
315341
* Update this sketch with a given unsigned 8-bit integer.
342+
* If the summary contains strings and cross-language portability is required,
343+
* callers should ensure that any strings in the summary
344+
* use a compatible encoding (valid UTF-8).
316345
* For compatibility with Java implementation.
317346
* @param key uint8_t to update the sketch with
318347
* @param value to update the sketch with
@@ -322,6 +351,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
322351

323352
/**
324353
* Update this sketch with a given signed 8-bit integer.
354+
* If the summary contains strings and cross-language portability is required,
355+
* callers should ensure that any strings in the summary
356+
* use a compatible encoding (valid UTF-8).
325357
* For compatibility with Java implementation.
326358
* @param key int8_t to update the sketch with
327359
* @param value to update the sketch with
@@ -331,6 +363,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
331363

332364
/**
333365
* Update this sketch with a given double-precision floating point value.
366+
* If the summary contains strings and cross-language portability is required,
367+
* callers should ensure that any strings in the summary
368+
* use a compatible encoding (valid UTF-8).
334369
* For compatibility with Java implementation.
335370
* @param key double to update the sketch with
336371
* @param value to update the sketch with
@@ -340,6 +375,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
340375

341376
/**
342377
* Update this sketch with a given floating point value.
378+
* If the summary contains strings and cross-language portability is required,
379+
* callers should ensure that any strings in the summary
380+
* use a compatible encoding (valid UTF-8).
343381
* For compatibility with Java implementation.
344382
* @param key float to update the sketch with
345383
* @param value to update the sketch with
@@ -357,6 +395,9 @@ class update_tuple_sketch: public tuple_sketch<Summary, Allocator> {
357395
* Otherwise two sketches that should represent overlapping sets will be disjoint
358396
* For instance, for signed 32-bit values call update(int32_t) method above,
359397
* which does widening conversion to int64_t, if compatibility with Java is expected
398+
* If the summary contains strings and cross-language portability is required,
399+
* callers should ensure that any strings in the summary
400+
* use a compatible encoding (valid UTF-8).
360401
* @param key pointer to the data
361402
* @param length of the data in bytes
362403
* @param value to update the sketch with

0 commit comments

Comments
 (0)