New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
randomASCII function #8401
randomASCII function #8401
Conversation
…e/randomASKII-function
…e/randomASKII-function
…ckHouse into feature/randomASKII-function
…ckHouse into feature/randomASKII-function
…ckHouse into feature/randomASKII-function
…ckHouse into feature/randomASKII-function
…e/randomASKII-function
WriteBufferFromVector<ColumnString::Chars> buf_to(data_to); | ||
|
||
std::default_random_engine generator; | ||
std::uniform_int_distribution<int> distribution(32, 127); //Printable ASCII symbols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
127 is not printable
str_length = static_cast<size_t>(vec_from[i]); | ||
} | ||
|
||
generator.seed( rd() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is slow.
You can also add performance test. Look at dbms/tests/performance
.
|
||
generator.seed( rd() ); | ||
|
||
if (str_length > 0){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is redundant, it will be checked in a loop also before first loop iteration.
return name; | ||
} | ||
|
||
size_t getNumberOfArguments() const override { return 1; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also support additional "disambiguation" arguments, similar to rand
function.
|
||
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override | ||
{ | ||
if (!(executeType<UInt8>(block, arguments, result, input_rows_count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, the cost of virtual call is Ok here, we can use IColumn::getUInt method and avoid manual dispatching.
"Ideal" solution (if you will not propose better) would be:
|
Demo:
|
|
||
Принимает на вход имя и аргументы модели. Возвращает Float64. | ||
```sql | ||
randomASKII(length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
**Syntax** | ||
|
||
```sql | ||
randomASKII(length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
class FunctionRandomASCII : public IFunction | ||
{ | ||
public: | ||
static constexpr auto name = "randomASCII"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name it randomPrintableASCII
to avoid confusion.
1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create reference files simply by
clickhouse-client -n --testmode < query.sql > query.reference
…function Merging #8401
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (up to few sentences, required except for Non-significant/Documentation categories):
Added the
randomASCII(length)
function, generating a string with a random set of ASCII printable characters.Detailed description:
Documentation inside the PR.