Add docs and proper aliasing to WIDTH_BUCKET

This commit is contained in:
avoiderboi 2023-02-24 12:31:05 +01:00
parent baad4448dd
commit 3c61afb1ca
2 changed files with 48 additions and 7 deletions

View File

@ -580,24 +580,32 @@ Result:
└───────────────┘
```
## width_bucket(operand, low, high, integer)
## width_bucket(operand, low, high, count)
Returns the number of the bucket in which `operand` falls in a histogram having `count` equal-width buckets spanning the range `low` to `high`. Returns `0` if `operand < low`, and returns `count+1` if `operand >= high`.
`operand`, `low`, `high` can be any native number type. `count` can only be unsigned native integer and its value cannot be zero.
**Syntax**
```sql
widthBucket(operand, low, high, count)
```
There is also a case insensitive alias called `WIDTH_BUCKET` to provide compatibility with other databases.
**Example**
Query:
``` sql
SELECT WIDTH_BUCKET(10.15, -8.6, 23, 18);
SELECT widthBucket(10.15, -8.6, 23, 18);
```
Result:
``` text
┌─width_bucket(10.15, -8.6, 23, 18)─┐
11 │
└──────────────────────────────────
┌─widthBucket(10.15, -8.6, 23, 18)─┐
│ 11 │
└──────────────────────────────────┘
```

View File

@ -132,7 +132,7 @@ class FunctionWidthBucket : public IFunction
}
public:
static inline const char * name = "width_bucket";
static inline const char * name = "widthBucket";
explicit FunctionWidthBucket() = default;
@ -207,7 +207,40 @@ public:
REGISTER_FUNCTION(WidthBucket)
{
factory.registerFunction<FunctionWidthBucket>({}, FunctionFactory::CaseInsensitive);
factory.registerFunction<FunctionWidthBucket>({
R"(
Returns the number of the bucket in which `operand` falls in a histogram having `count` equal-width buckets spanning the range `low` to `high`. Returns `0` if `operand < low`, and returns `count+1` if `operand >= high`.
`operand`, `low`, `high` can be any native number type. `count` can only be unsigned native integer and its value cannot be zero.
**Syntax**
```sql
widthBucket(operand, low, high, count)
```
There is also a case insensitive alias called `WIDTH_BUCKET` to provide compatibility with other databases.
**Example**
Query:
[example:simple]
Result:
``` text
widthBucket(10.15, -8.6, 23, 18)
11
```
)",
Documentation::Examples{
{"simple", "SELECT widthBucket(10.15, -8.6, 23, 18)"},
},
Documentation::Categories{"Mathematical"},
});
factory.registerAlias("width_bucket", "widthBucket", FunctionFactory::CaseInsensitive);
}
}