Merge pull request #30436 from kitaisreal/executable-udf-clickhouse-example

ExecutableUDF example
This commit is contained in:
Maksim Kita 2021-10-20 12:58:50 +03:00 committed by GitHub
commit b8407e53ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -77,3 +77,6 @@ target_link_libraries (average PRIVATE clickhouse_common_io)
add_executable (shell_command_inout shell_command_inout.cpp)
target_link_libraries (shell_command_inout PRIVATE clickhouse_common_io)
add_executable (executable_udf executable_udf.cpp)
target_link_libraries (executable_udf PRIVATE dbms)

View File

@ -0,0 +1,44 @@
#include <vector>
#include <string>
#include <iomanip>
#include <Common/SipHash.h>
#include <IO/ReadBufferFromFileDescriptor.h>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
#include <Common/Stopwatch.h>
using namespace DB;
int main(int argc, char **argv)
{
(void)(argc);
(void)(argv);
std::string buffer;
ReadBufferFromFileDescriptor read_buffer(0);
WriteBufferFromFileDescriptor write_buffer(1);
size_t rows = 0;
char dummy;
while (!read_buffer.eof()) {
readIntText(rows, read_buffer);
readChar(dummy, read_buffer);
for (size_t i = 0; i < rows; ++i) {
readString(buffer, read_buffer);
readChar(dummy, read_buffer);
writeString("Key ", write_buffer);
writeString(buffer, write_buffer);
writeChar('\n', write_buffer);
}
write_buffer.next();
}
return 0;
}