Syntax
ZIPF(<s> , <N> , <gen>)
Purpose
This function returns an integer that follows the Zipf distribution in the range [0, N), where s is the characteristic exponent of the partition.
sis the characteristic exponent. A largersvalue results in a more skewed sequence. When plotted as a curve, the curve becomes steeper.sandNmust be scalar values that do not change with row iteration. For example, they can be integer or floating-point constants, scalar functions, or expressions like@v1or1+@v3in PL. The value ofsranges from [1, +∞), and the value ofNranges from [1, 16777215].- The storage and computational resources consumed by the
zipfalgorithm are related to the value ofN. The space complexity of the algorithm isO(N), and the time complexity for generating each integer isO(logN). Therefore, the value ofNis limited to the range [1, 16777215]. genis a numerical generation function, typically using theRANDOM()function. If the input value is a constant, thezipf()function returns a fixed value.
Examples
The following example demonstrates how to use the ZIPF() function to return an integer that follows the Zipf distribution.
obclient> SELECT ZIPF(1, 10, RANDOM()) FROM TABLE(GENERATOR(6));
+-----------------------+
| ZIPF(1,10,RANDOM()) |
+-----------------------+
| 2 |
| 0 |
| 0 |
| 0 |
| 3 |
| 3 |
+-----------------------+
6 rows in set
obclient> SELECT ZIPF(1, 10, 0415) FROM TABLE(GENERATOR(6));
+-------------------+
| ZIPF(1, 10, 0415) |
+-------------------+
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
+-------------------+
6 rows in set
obclient> SELECT ZIPF(ABS(-1), 23, RANDOM()) FROM DUAL;
+-----------------------------+
| ZIPF(ABS(-1),23,RANDOM()) |
+-----------------------------+
| 9 |
+-----------------------------+
1 row in set
