Skip to content

Commit 31dc138

Browse files
committed
Merge 'master' into ncb/fix-cov-by-broken-exists
2 parents 6cc2e97 + 9d83d9f commit 31dc138

File tree

76 files changed

+1850
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1850
-537
lines changed

docs/en/engines/table-engines/mergetree-family/invertedindexes.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ ENGINE = MergeTree
6060
ORDER BY key
6161
```
6262

63-
:::note
64-
In earlier versions of ClickHouse, the corresponding index type name was `inverted`.
65-
:::
66-
6763
where `N` specifies the tokenizer:
6864

6965
- `gin(0)` (or shorter: `gin()`) set the tokenizer to "tokens", i.e. split strings along spaces,
Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
---
2-
description: 'Documentation for ALTER TABLE ... MODIFY COMMENT'
3-
sidebar_label: 'COMMENT'
2+
description: 'Documentation for ALTER TABLE ... MODIFY COMMENT which allow
3+
adding, modifying, or removing table comments'
4+
sidebar_label: 'ALTER TABLE ... MODIFY COMMENT'
45
sidebar_position: 51
56
slug: /sql-reference/statements/alter/comment
67
title: 'ALTER TABLE ... MODIFY COMMENT'
8+
keywords: ['ALTER TABLE', 'MODIFY COMMENT']
79
---
810

911
# ALTER TABLE ... MODIFY COMMENT
1012

11-
Adds, modifies, or removes comment to the table, regardless if it was set before or not. Comment change is reflected in both [system.tables](../../../operations/system-tables/tables.md) and `SHOW CREATE TABLE` query.
13+
Adds, modifies, or removes a table comment, regardless of whether it was set
14+
before or not. The comment change is reflected in both [`system.tables`](../../../operations/system-tables/tables.md)
15+
and in the `SHOW CREATE TABLE` query.
1216

13-
**Syntax**
17+
## Syntax {#syntax}
1418

1519
```sql
1620
ALTER TABLE [db].name [ON CLUSTER cluster] MODIFY COMMENT 'Comment'
1721
```
1822

19-
**Examples**
23+
## Examples {#examples}
2024

21-
Creating a table with comment (for more information, see the [COMMENT](/sql-reference/statements/create/table#comment-clause) clause):
25+
To create a table with a comment:
2226

2327
```sql
2428
CREATE TABLE table_with_comment
@@ -30,38 +34,56 @@ ENGINE = Memory()
3034
COMMENT 'The temporary table';
3135
```
3236

33-
Modifying the table comment:
37+
To modify the table comment:
3438

3539
```sql
36-
ALTER TABLE table_with_comment MODIFY COMMENT 'new comment on a table';
37-
SELECT comment FROM system.tables WHERE database = currentDatabase() AND name = 'table_with_comment';
40+
ALTER TABLE table_with_comment
41+
MODIFY COMMENT 'new comment on a table';
3842
```
3943

40-
Output of a new comment:
44+
To view the modified comment:
4145

42-
```text
46+
```sql title="Query"
47+
SELECT comment
48+
FROM system.tables
49+
WHERE database = currentDatabase() AND name = 'table_with_comment';
50+
```
51+
52+
```text title="Response"
4353
┌─comment────────────────┐
4454
│ new comment on a table │
4555
└────────────────────────┘
4656
```
4757

48-
Removing the table comment:
58+
To remove the table comment:
4959

5060
```sql
5161
ALTER TABLE table_with_comment MODIFY COMMENT '';
52-
SELECT comment FROM system.tables WHERE database = currentDatabase() AND name = 'table_with_comment';
5362
```
5463

55-
Output of a removed comment:
64+
To verify that the comment was removed:
65+
66+
```sql title="Query"
67+
SELECT comment
68+
FROM system.tables
69+
WHERE database = currentDatabase() AND name = 'table_with_comment';
70+
```
5671

57-
```text
72+
```text title="Response"
5873
┌─comment─┐
5974
│ │
6075
└─────────┘
6176
```
6277

63-
**Caveats**
78+
## Caveats {#caveats}
79+
80+
For Replicated tables, the comment can be different on different replicas.
81+
Modifying the comment applies to a single replica.
82+
83+
The feature is available since version 23.9. It does not work in previous
84+
ClickHouse versions.
6485

65-
For Replicated tables, the comment can be different on different replicas. Modifying the comment applies to a single replica.
86+
## Related content {#related-content}
6687

67-
The feature is available since version 23.9. It does not work in previous ClickHouse versions.
88+
- [`COMMENT`](/sql-reference/statements/create/table#comment-clause) clause
89+
- [`ALTER DATABASE ... MODIFY COMMENT`](./database-comment.md)
Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,76 @@
11
---
2-
description: 'Documentation for ALTER DATABASE ... MODIFY COMMENT Statements'
2+
description: 'Documentation for ALTER DATABASE ... MODIFY COMMENT statements
3+
which allow adding, modifying, or removing database comments.'
34
slug: /sql-reference/statements/alter/database-comment
45
sidebar_position: 51
5-
sidebar_label: 'UPDATE'
6+
sidebar_label: 'ALTER DATABASE ... MODIFY COMMENT'
67
title: 'ALTER DATABASE ... MODIFY COMMENT Statements'
8+
keywords: ['ALTER DATABASE', 'MODIFY COMMENT']
79
---
810

911
# ALTER DATABASE ... MODIFY COMMENT
1012

11-
Adds, modifies, or removes comment to the database, regardless of whether it was set before. Comment change is reflected in both [system.databases](/operations/system-tables/databases.md) and `SHOW CREATE DATABASE` query.
13+
Adds, modifies, or removes a database comment, regardless of whether it was set
14+
before or not. The comment change is reflected in both [`system.databases`](/operations/system-tables/databases.md)
15+
and the `SHOW CREATE DATABASE` query.
1216

13-
**Syntax**
17+
## Syntax {#syntax}
1418

1519
``` sql
1620
ALTER DATABASE [db].name [ON CLUSTER cluster] MODIFY COMMENT 'Comment'
1721
```
1822

19-
**Examples**
23+
## Examples {#examples}
2024

21-
Creating a DATABASE with comment (for more information, see the [COMMENT](/sql-reference/statements/create/table#comment-clause) clause):
25+
To create a `DATABASE` with a comment:
2226

2327
``` sql
2428
CREATE DATABASE database_with_comment ENGINE = Memory COMMENT 'The temporary database';
2529
```
2630

27-
Modifying the table comment:
31+
To modify the comment:
2832

2933
``` sql
30-
ALTER DATABASE database_with_comment MODIFY COMMENT 'new comment on a database';
31-
SELECT comment FROM system.databases WHERE name = 'database_with_comment';
34+
ALTER DATABASE database_with_comment
35+
MODIFY COMMENT 'new comment on a database';
3236
```
3337

34-
Output of a new comment:
38+
To view the modified comment:
39+
40+
```sql
41+
SELECT comment
42+
FROM system.databases
43+
WHERE name = 'database_with_comment';
44+
```
3545

3646
```text
3747
┌─comment─────────────────┐
3848
│ new comment on database │
3949
└─────────────────────────┘
4050
```
4151

42-
Removing the database comment:
52+
To remove the database comment:
4353

4454
``` sql
45-
ALTER DATABASE database_with_comment MODIFY COMMENT '';
46-
SELECT comment FROM system.databases WHERE name = 'database_with_comment';
55+
ALTER DATABASE database_with_comment
56+
MODIFY COMMENT '';
4757
```
4858

49-
Output of a removed comment:
59+
To verify that the comment was removed:
5060

51-
```text
61+
```sql title="Query"
62+
SELECT comment
63+
FROM system.databases
64+
WHERE name = 'database_with_comment';
65+
```
66+
67+
```text title="Response"
5268
┌─comment─┐
5369
│ │
5470
└─────────┘
5571
```
72+
73+
## Related content {#related-content}
74+
75+
- [`COMMENT`](/sql-reference/statements/create/table#comment-clause) clause
76+
- [`ALTER TABLE ... MODIFY COMMENT`](./comment.md)

src/Client/ClientBase.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
#include <Access/AccessControl.h>
7373
#include <Storages/ColumnsDescription.h>
74+
#include <TableFunctions/ITableFunction.h>
7475

7576
#include <filesystem>
7677
#include <iostream>
@@ -1706,13 +1707,21 @@ bool ClientBase::receiveSampleBlock(Block & out, ColumnsDescription & columns_de
17061707

17071708
void ClientBase::setInsertionTable(const ASTInsertQuery & insert_query)
17081709
{
1709-
if (!client_context->hasInsertionTable() && insert_query.table)
1710+
if (!client_context->hasInsertionTable())
17101711
{
1711-
String table = insert_query.table->as<ASTIdentifier &>().shortName();
1712-
if (!table.empty())
1712+
if (insert_query.table)
17131713
{
1714-
String database = insert_query.database ? insert_query.database->as<ASTIdentifier &>().shortName() : "";
1715-
client_context->setInsertionTable(StorageID(database, table));
1714+
String table = insert_query.table->as<ASTIdentifier &>().shortName();
1715+
if (!table.empty())
1716+
{
1717+
String database = insert_query.database ? insert_query.database->as<ASTIdentifier &>().shortName() : "";
1718+
client_context->setInsertionTable(StorageID(database, table));
1719+
}
1720+
}
1721+
else if (insert_query.table_function)
1722+
{
1723+
String table_function = insert_query.table_function->as<ASTFunction &>().name;
1724+
client_context->setInsertionTable(StorageID(ITableFunction::getDatabaseName(), table_function));
17161725
}
17171726
}
17181727
}
@@ -2160,6 +2169,7 @@ void ClientBase::processParsedSingleQuery(
21602169
cancelled_printed = false;
21612170
client_exception.reset();
21622171
server_exception.reset();
2172+
client_context->setInsertionTable(StorageID::createEmpty());
21632173

21642174
if (is_interactive)
21652175
{

src/Functions/abs.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ template <> struct FunctionUnaryArithmeticMonotonicity<NameAbs>
5151

5252
REGISTER_FUNCTION(Abs)
5353
{
54-
factory.registerFunction<FunctionAbs>({}, FunctionFactory::Case::Insensitive);
54+
FunctionDocumentation::Description description = "Calculates the absolute value of `x`. Has no effect if `x` is of an unsigned type. If `x` is of a signed type, it returns an unsigned number.";
55+
FunctionDocumentation::Syntax syntax = "abs(x)";
56+
FunctionDocumentation::Arguments argument = {{"x", "Value to get the absolute value of"}};
57+
FunctionDocumentation::ReturnedValue returned_value = "The absolute value of `x`";
58+
FunctionDocumentation::Examples examples = {{"", "SELECT abs(-0.5)", "0.5"}};
59+
FunctionDocumentation::Category categories = FunctionDocumentation::Category::Arithmetic;
60+
FunctionDocumentation documentation = {description, syntax, argument, returned_value, examples, categories};
61+
62+
factory.registerFunction<FunctionAbs>(documentation, FunctionFactory::Case::Insensitive);
5563
}
5664

5765
}

src/Functions/byteSwap.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,46 +62,35 @@ struct FunctionUnaryArithmeticMonotonicity<NameByteSwap>
6262

6363
REGISTER_FUNCTION(ByteSwap)
6464
{
65-
factory.registerFunction<FunctionByteSwap>(
66-
FunctionDocumentation{
67-
.description = R"(
65+
FunctionDocumentation::Description description = R"(
6866
Reverses the bytes of an integer, i.e. changes its [endianness](https://en.wikipedia.org/wiki/Endianness).
6967
70-
**Example**
68+
The below example can be worked out in the following manner:
7169
72-
```sql
73-
byteSwap(3351772109)
74-
```
75-
76-
Result:
77-
78-
```result
79-
┌─byteSwap(3351772109)─┐
80-
│ 3455829959 │
81-
└──────────────────────┘
82-
```
83-
84-
The above example can be worked out in the following manner:
8570
1. Convert the base-10 integer to its equivalent hexadecimal format in big-endian format, i.e. 3351772109 -> C7 C7 FB CD (4 bytes)
8671
2. Reverse the bytes, i.e. C7 C7 FB CD -> CD FB C7 C7
87-
3. Convert the result back to an integer assuming big-endian, i.e. CD FB C7 C7 -> 3455829959
88-
89-
One use-case of this function is reversing IPv4s:
72+
3. Convert the result back to an integer assuming big-endian, i.e. CD FB C7 C7 -> 3455829959
73+
One use case of this function is reversing IPv4s:
9074
9175
```result
9276
┌─toIPv4(byteSwap(toUInt32(toIPv4('205.251.199.199'))))─┐
9377
│ 199.199.251.205 │
9478
└───────────────────────────────────────────────────────┘
9579
```
96-
)",
97-
.examples{
98-
{"8-bit", "SELECT byteSwap(54)", "54"},
99-
{"16-bit", "SELECT byteSwap(4135)", "10000"},
100-
{"32-bit", "SELECT byteSwap(3351772109)", "3455829959"},
101-
{"64-bit", "SELECT byteSwap(123294967295)", "18439412204227788800"},
102-
},
103-
.category = FunctionDocumentation::Category::Arithmetic},
104-
FunctionFactory::Case::Insensitive);
80+
)";
81+
FunctionDocumentation::Syntax syntax = "byteSwap(x)";
82+
FunctionDocumentation::Argument argument1 = {"x", "An integer value."};
83+
FunctionDocumentation::Arguments arguments = {argument1};
84+
FunctionDocumentation::ReturnedValue returned_value = "x with bytes reversed";
85+
FunctionDocumentation::Example example1 = {"", "SELECT byteSwap(3351772109)", "3455829959"};
86+
FunctionDocumentation::Example example2 = {"8-bit", "SELECT byteSwap(54)", "54"};
87+
FunctionDocumentation::Example example3 = {"16-bit", "SELECT byteSwap(4135)", "10000"};
88+
FunctionDocumentation::Example example4 = {"32-bit", "SELECT byteSwap(3351772109)", "3455829959"};
89+
FunctionDocumentation::Example example5 = {"64-bit", "SELECT byteSwap(123294967295)", "18439412204227788800"};
90+
FunctionDocumentation::Examples examples = {example1, example2, example3, example4, example5};
91+
FunctionDocumentation::Category categories = FunctionDocumentation::Category::Arithmetic;
92+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, categories};
93+
factory.registerFunction<FunctionByteSwap>(documentation,FunctionFactory::Case::Insensitive);
10594
}
10695

10796
}

src/Functions/caseWithExpression.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace DB
1111
namespace ErrorCodes
1212
{
1313
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
14+
extern const int BAD_ARGUMENTS;
1415
}
1516

1617
namespace
@@ -38,6 +39,11 @@ class FunctionCaseWithExpression : public IFunction
3839
if (args.empty())
3940
throw Exception(ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION, "Function {} expects at least 1 arguments", getName());
4041

42+
/// We expect an even number of arguments, with the first argument being the expression,
43+
/// and the last argument being the ELSE branch, with the rest being pairs of WHEN and THEN branches.
44+
if (args.size() < 4 || args.size() % 2 != 0)
45+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Function {} expects an even number of arguments: (expr, when1, then1, ..., else)", getName());
46+
4147
/// See the comments in executeImpl() to understand why we actually have to
4248
/// get the return type of a transform function.
4349

src/Functions/divide.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,26 @@ using FunctionDivide = BinaryArithmeticOverloadResolver<DivideFloatingImpl, Name
4141

4242
REGISTER_FUNCTION(Divide)
4343
{
44-
factory.registerFunction<FunctionDivide>();
44+
FunctionDocumentation::Description description = R"(
45+
Calculates the quotient of two values `a` and `b`. The result type is always [Float64](/sql-reference/data-types/float).
46+
Integer division is provided by the `intDiv` function.
47+
48+
:::note
49+
Division by `0` returns `inf`, `-inf`, or `nan`.
50+
:::
51+
)";
52+
FunctionDocumentation::Syntax syntax = "divide(x, y)";
53+
FunctionDocumentation::Argument argument1 = {"x", "Dividend"};
54+
FunctionDocumentation::Argument argument2 = {"y", "Divisor"};
55+
FunctionDocumentation::Arguments arguments = {argument1, argument2};
56+
FunctionDocumentation::ReturnedValue returned_value = "The quotient of x and y";
57+
FunctionDocumentation::Example example1 = {"Dividing two numbers", "SELECT divide(25,5) AS quotient, toTypeName(quotient)", "5 Float64"};
58+
FunctionDocumentation::Example example2 = {"Dividing by zero", "SELECT divide(25,0)", "inf"};
59+
FunctionDocumentation::Examples examples = {example1, example2};
60+
FunctionDocumentation::Category categories = FunctionDocumentation::Category::Arithmetic;
61+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, categories};
62+
63+
factory.registerFunction<FunctionDivide>(documentation);
4564
}
4665

4766
struct NameDivideOrNull { static constexpr auto name = "divideOrNull"; };

0 commit comments

Comments
 (0)