Merge pull request #66163 from Blargian/docs_partitionID

Add alias `partitionID` for function `partitionId` and add documentation
This commit is contained in:
Robert Schulze 2024-07-15 06:58:24 +00:00 committed by GitHub
commit 7276ad2888
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 67 additions and 4 deletions

View File

@ -2984,6 +2984,66 @@ Result:
└─────────┘
```
## partitionID
Computes the [partition ID](../../engines/table-engines/mergetree-family/custom-partitioning-key.md).
:::note
This function is slow and should not be called for large amount of rows.
:::
**Syntax**
```sql
partitionID(x[, y, ...]);
```
**Arguments**
- `x` — Column for which to return the partition ID.
- `y, ...` — Remaining N columns for which to return the partition ID (optional).
**Returned Value**
- Partition ID that the row would belong to. [String](../data-types/string.md).
**Example**
Query:
```sql
DROP TABLE IF EXISTS tab;
CREATE TABLE tab
(
i int,
j int
)
ENGINE = MergeTree
PARTITION BY i
ORDER BY tuple();
INSERT INTO tab VALUES (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (2, 6);
SELECT i, j, partitionID(i), _partition_id FROM tab ORDER BY i, j;
```
Result:
```response
┌─i─┬─j─┬─partitionID(i)─┬─_partition_id─┐
│ 1 │ 1 │ 1 │ 1 │
│ 1 │ 2 │ 1 │ 1 │
│ 1 │ 3 │ 1 │ 1 │
└───┴───┴────────────────┴───────────────┘
┌─i─┬─j─┬─partitionID(i)─┬─_partition_id─┐
│ 2 │ 4 │ 2 │ 2 │
│ 2 │ 5 │ 2 │ 2 │
│ 2 │ 6 │ 2 │ 2 │
└───┴───┴────────────────┴───────────────┘
```
## shardNum
Returns the index of a shard which processes a part of data in a distributed query. Indices are started from `1`.

View File

@ -66,6 +66,7 @@ public:
REGISTER_FUNCTION(PartitionId)
{
factory.registerFunction<FunctionPartitionId>();
factory.registerAlias("partitionID", "partitionId");
}
}

View File

@ -266,7 +266,7 @@ def test_lost_last_part(start_cluster):
"ALTER TABLE mt3 UPDATE id = 777 WHERE 1", settings={"mutations_sync": "0"}
)
partition_id = node1.query("select partitionId('x')").strip()
partition_id = node1.query("select partitionID('x')").strip()
remove_part_from_disk(node1, "mt3", f"{partition_id}_0_0_0")
# other way to detect broken parts

View File

@ -8,17 +8,17 @@ insert into x values (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (2, 6);
set max_rows_to_read = 3;
select * from x where _partition_id = partitionId(1);
select * from x where _partition_id = partitionID(1);
set max_rows_to_read = 5; -- one row for subquery + subquery
select * from x where _partition_id in (select partitionId(number + 1) from numbers(1));
select * from x where _partition_id in (select partitionID(number + 1) from numbers(1));
-- trivial count optimization test
set max_rows_to_read = 2; -- one row for subquery + subquery itself
-- TODO: Relax the limits because we might build prepared set twice with _minmax_count_projection
set max_rows_to_read = 3;
select count() from x where _partition_id in (select partitionId(number + 1) from numbers(1));
select count() from x where _partition_id in (select partitionID(number + 1) from numbers(1));
drop table x;

View File

@ -2200,6 +2200,8 @@ parseReadableSizeOrZero
parseTimeDelta
parseable
parsers
partitionId
partitionID
pathFull
pclmulqdq
pcre