Some fixups

This commit is contained in:
Robert Schulze 2023-11-15 15:42:00 +00:00
parent 20cfe91ff9
commit f21dd37d18
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
6 changed files with 23 additions and 19 deletions

View File

@ -429,7 +429,7 @@ SELECT format('{} {}', 'Hello', 'World')
## concat ## concat
Concatenates the strings listed in the arguments without separator. Concatenates the given arguments.
**Syntax** **Syntax**
@ -439,7 +439,9 @@ concat(s1, s2, ...)
**Arguments** **Arguments**
Values of arbitrary types. If an argument is not a String or FixedString, it is converted to the String type using the default serialization. At least two values of arbitrary type.
Arguments which are not of types [String](../../sql-reference/data-types/string.md) or [FixedString](../../sql-reference/data-types/fixedstring.md) are converted to strings using their default serialization. As this decreases performance, it is not recommended to use non-String/FixedString arguments.
**Returned values** **Returned values**
@ -449,6 +451,8 @@ If any of arguments is `NULL`, the function returns `NULL`.
**Example** **Example**
Query:
``` sql ``` sql
SELECT concat('Hello, ', 'World!'); SELECT concat('Hello, ', 'World!');
``` ```
@ -461,7 +465,7 @@ Result:
└─────────────────────────────┘ └─────────────────────────────┘
``` ```
**Example** Query:
```sql ```sql
SELECT concat(42, 144); SELECT concat(42, 144);
@ -540,6 +544,8 @@ Concatenates the given strings with a given separator.
concatWithSeparator(sep, expr1, expr2, expr3...) concatWithSeparator(sep, expr1, expr2, expr3...)
``` ```
Alias: `concat_ws`
**Arguments** **Arguments**
- sep — separator. Const [String](../../sql-reference/data-types/string.md) or [FixedString](../../sql-reference/data-types/fixedstring.md). - sep — separator. Const [String](../../sql-reference/data-types/string.md) or [FixedString](../../sql-reference/data-types/fixedstring.md).

View File

@ -62,7 +62,7 @@ public:
return buffer; return buffer;
} }
inline void rowWritten() void rowWritten()
{ {
if constexpr (std::is_same_v<ColumnType, ColumnFixedString>) if constexpr (std::is_same_v<ColumnType, ColumnFixedString>)
{ {

View File

@ -91,7 +91,6 @@ private:
else else
{ {
/// Fallback: use generic implementation for not very important cases. /// Fallback: use generic implementation for not very important cases.
/// Concat of arbitrary types also goes here.
return executeFormatImpl(arguments, input_rows_count); return executeFormatImpl(arguments, input_rows_count);
} }
@ -108,7 +107,7 @@ private:
std::vector<const ColumnString::Offsets *> offsets(num_arguments); std::vector<const ColumnString::Offsets *> offsets(num_arguments);
std::vector<size_t> fixed_string_sizes(num_arguments); std::vector<size_t> fixed_string_sizes(num_arguments);
std::vector<std::optional<String>> constant_strings(num_arguments); std::vector<std::optional<String>> constant_strings(num_arguments);
std::vector<ColumnPtr> converted_col_ptrs(num_arguments); std::vector<ColumnString::MutablePtr> converted_col_ptrs(num_arguments);
bool has_column_string = false; bool has_column_string = false;
bool has_column_fixed_string = false; bool has_column_fixed_string = false;
for (size_t i = 0; i < num_arguments; ++i) for (size_t i = 0; i < num_arguments; ++i)
@ -132,14 +131,13 @@ private:
} }
else else
{ {
// An arbitrary type argument: converting it to a StringColumn first /// A non-String/non-FixedString-type argument: use the default serialization to convert it to String
const auto full_column = column->convertToFullIfNeeded(); const auto full_column = column->convertToFullIfNeeded();
const auto serialization = arguments[i].type->getDefaultSerialization(); const auto serialization = arguments[i].type->getDefaultSerialization();
ColumnString::MutablePtr converted_col_str = ColumnString::create(); auto converted_col_str = ColumnString::create();
static FormatSettings format_settings;
ColumnStringHelpers::WriteHelper write_helper(*converted_col_str, column->size()); ColumnStringHelpers::WriteHelper write_helper(*converted_col_str, column->size());
auto & write_buffer = write_helper.getWriteBuffer(); auto & write_buffer = write_helper.getWriteBuffer();
FormatSettings format_settings;
for (size_t j = 0; j < column->size(); ++j) for (size_t j = 0; j < column->size(); ++j)
{ {
serialization->serializeText(*full_column, j, write_buffer, format_settings); serialization->serializeText(*full_column, j, write_buffer, format_settings);
@ -147,12 +145,12 @@ private:
} }
write_helper.finalize(); write_helper.finalize();
// Same as the normal `ColumnString` branch /// Same as the normal `ColumnString` branch
has_column_string = true; has_column_string = true;
data[i] = &converted_col_str->getChars(); data[i] = &converted_col_str->getChars();
offsets[i] = &converted_col_str->getOffsets(); offsets[i] = &converted_col_str->getOffsets();
// keep the refcounted-pointer around (to be able to use data/offsets later) /// Keep the refcounted-pointer alive
converted_col_ptrs[i] = std::move(converted_col_str); converted_col_ptrs[i] = std::move(converted_col_str);
} }
} }

View File

@ -1,14 +1,14 @@
#pragma once #pragma once
#include <Columns/ColumnString.h>
#include <Common/format.h>
#include <Common/memcpySmall.h>
#include <base/types.h>
#include <algorithm> #include <algorithm>
#include <optional> #include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
#include <Columns/ColumnString.h>
#include <base/types.h>
#include <Common/format.h>
#include <Common/memcpySmall.h>
namespace DB namespace DB
{ {

View File

@ -5,7 +5,7 @@
-- Tests the output of SHOW COLUMNS when called through the ClickHouse protocol. -- Tests the output of SHOW COLUMNS when called through the ClickHouse protocol.
-- ----------------------------------------------------------------------------------- -- -----------------------------------------------------------------------------------
-- Please keep this test in-sync with 02775_show_columns_called_from_mysql.expect -- Please keep this test in-sync with 02775_show_columns_called_from_clickhouse.expect
-- ----------------------------------------------------------------------------------- -- -----------------------------------------------------------------------------------
DROP TABLE IF EXISTS tab; DROP TABLE IF EXISTS tab;

View File

@ -6,7 +6,7 @@
# Tests the output of SHOW COLUMNS when called through the MySQL protocol. # Tests the output of SHOW COLUMNS when called through the MySQL protocol.
# ----------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------
# Please keep this test in-sync with 02775_show_columns_called_through_clickhouse.sql # Please keep this test in-sync with 02775_show_columns_called_from_clickhouse.sql
# ----------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------
set basedir [file dirname $argv0] set basedir [file dirname $argv0]