fix comments: rname randomSampleFromArray --> arrayRandomSample

This commit is contained in:
Itay Israelov 2023-09-12 15:22:44 +03:00
parent 52c997b026
commit 69ba32940e
5 changed files with 19 additions and 17 deletions

View File

@ -2119,14 +2119,14 @@ Result:
```
## randomSampleFromArray
## arrayRandomSample
Returns a random sample from an input array. The number of elements in the sample is determined by the `sampleSize` argument. The function ensures that each element in the input array has an equal chance of being included in the sample.
**Syntax**
```sql
randomSampleFromArray(arr, sampleSize)
arrayRandomSample(arr, sampleSize)
```
**Arguments**
@ -2143,7 +2143,7 @@ randomSampleFromArray(arr, sampleSize)
Query:
```sql
SELECT randomSampleFromArray([1, 2, 3, 4, 5, 6], 3) as res;
SELECT arrayRandomSample([1, 2, 3, 4, 5, 6], 3) as res;
```
Result:
@ -2160,7 +2160,7 @@ or
Query:
```sql
SELECT randomSampleFromArray(['apple', 'banana', 'cherry', 'date'], 2) as res;
SELECT arrayRandomSample(['apple', 'banana', 'cherry', 'date'], 2) as res;
```
Result:
@ -2181,7 +2181,7 @@ or
Query:
```sql
SELECT randomSampleFromArray([[1, 2], [3, 4], [5, 6]], 2) as res;
SELECT arrayRandomSample([[1, 2], [3, 4], [5, 6]], 2) as res;
```
Result:
@ -2198,7 +2198,7 @@ or
Query:
```sql
SELECT randomSampleFromArray([1, 2, 3, 4, 5], 0) as res;
SELECT arrayRandomSample([1, 2, 3, 4, 5], 0) as res;
```
Result:
@ -2209,7 +2209,7 @@ TODO: FIX ME
Query:
```sql
SELECT randomSampleFromArray([1, 2, 3], 5) as res;
SELECT arrayRandomSample([1, 2, 3], 5) as res;
```
Result:
@ -2223,7 +2223,7 @@ or
└─────────┘
```
The `randomSampleFromArray` function randomly selects elements from the input array, ensuring that the specified number of elements is included in the sample. If `sampleSize` exceeds the size of the input array, it will be limited to the size of the array. It can handle both flat arrays and arrays containing nested arrays, providing flexibility in sampling from complex data structures.
The `arrayRandomSample` function randomly selects elements from the input array, ensuring that the specified number of elements is included in the sample. If `sampleSize` exceeds the size of the input array, it will be limited to the size of the array. It can handle both flat arrays and arrays containing nested arrays, providing flexibility in sampling from complex data structures.
## Distance functions

View File

@ -16,13 +16,13 @@ namespace ErrorCodes
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
/// randomSampleFromArray(arr, k) - Returns k random elements from the input array
class FunctionRandomSampleFromArray : public IFunction
/// arrayRandomSample(arr, k) - Returns k random elements from the input array
class FunctionArrayRandomSample : public IFunction
{
public:
static constexpr auto name = "randomSampleFromArray";
static constexpr auto name = "arrayRandomSample";
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionRandomSampleFromArray>(); }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionArrayRandomSample>(); }
String getName() const override { return name; }
@ -120,7 +120,7 @@ public:
REGISTER_FUNCTION(RandomSampleFromArray)
{
factory.registerFunction<FunctionRandomSampleFromArray>();
factory.registerFunction<FunctionArrayRandomSample>();
}
}

View File

@ -125,6 +125,7 @@ arrayPopFront
arrayProduct
arrayPushBack
arrayPushFront
arrayRandomSample
arrayReduce
arrayReduceInRanges
arrayResize

View File

@ -11,7 +11,7 @@ passed_tests=0
# Test Function for Integer Arrays
run_integer_test() {
query_result=$(clickhouse-client -q "SELECT randomSampleFromArray([1,2,3], 2)")
query_result=$(clickhouse-client -q "SELECT arrayRandomSample([1,2,3], 2)")
mapfile -t sorted_result < <(echo "$query_result" | tr -d '[]' | tr ',' '\n' | sort -n)
declare -A expected_outcomes
expected_outcomes["1 2"]=1
@ -34,7 +34,7 @@ run_integer_test() {
# Test Function for String Arrays
run_string_test() {
query_result=$(clickhouse-client -q "SELECT randomSampleFromArray(['a','b','c'], 2)")
query_result=$(clickhouse-client -q "SELECT arrayRandomSample(['a','b','c'], 2)")
mapfile -t sorted_result < <(echo "$query_result" | tr -d "[]'" | tr ',' '\n' | sort)
declare -A expected_outcomes
expected_outcomes["a b"]=1
@ -57,7 +57,7 @@ run_string_test() {
# Test Function for Nested Arrays
run_nested_array_test() {
query_result=$(clickhouse-client -q "SELECT randomSampleFromArray([[7,2],[3,4],[7,6]], 2)")
query_result=$(clickhouse-client -q "SELECT arrayRandomSample([[7,2],[3,4],[7,6]], 2)")
# Convert to a space-separated string for easy sorting.
converted_result=$(echo "$query_result" | tr -d '[]' | tr ',' ' ')
@ -87,7 +87,7 @@ run_nested_array_test() {
# Test Function for K > array.size
run_higher_k_test() {
query_result=$(clickhouse-client -q "SELECT randomSampleFromArray([1,2,3], 5)")
query_result=$(clickhouse-client -q "SELECT arrayRandomSample([1,2,3], 5)")
mapfile -t sorted_result < <(echo "$query_result" | tr -d '[]' | tr ',' '\n' | sort -n)
sorted_original=("1" "2" "3")

View File

@ -1059,6 +1059,7 @@ arrayPopFront
arrayProduct
arrayPushBack
arrayPushFront
arrayRandomSample
arrayReduce
arrayReduceInRanges
arrayResize