Skip to content

Commit 83d2eb0

Browse files
authored
Merge pull request #1003 from Altinity/backport/24.8.14/79491
24.8.14 Backport of 79491: Weaken check for sparse columns in Block
2 parents 85205cf + 4b8dc07 commit 83d2eb0

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

src/Core/Block.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,27 @@ static ReturnType checkColumnStructure(const ColumnWithTypeAndName & actual, con
5656
return ReturnType(true);
5757

5858
const IColumn * actual_column = actual.column.get();
59+
const IColumn * expected_column = expected.column.get();
5960

60-
/// If we allow to materialize, and expected column is not const or sparse, then unwrap actual column.
61+
/// If we allow to materialize columns, omit Const and Sparse columns.
6162
if (allow_materialize)
6263
{
63-
if (!isColumnConst(*expected.column))
64-
if (const auto * column_const = typeid_cast<const ColumnConst *>(actual_column))
65-
actual_column = &column_const->getDataColumn();
64+
if (const auto * column_const = typeid_cast<const ColumnConst *>(actual_column))
65+
actual_column = &column_const->getDataColumn();
6666

67-
if (!expected.column->isSparse())
68-
if (const auto * column_sparse = typeid_cast<const ColumnSparse *>(actual_column))
69-
actual_column = &column_sparse->getValuesColumn();
67+
if (const auto * column_const = typeid_cast<const ColumnConst *>(expected_column))
68+
expected_column = &column_const->getDataColumn();
69+
70+
if (const auto * column_sparse = typeid_cast<const ColumnSparse *>(actual_column))
71+
actual_column = &column_sparse->getValuesColumn();
72+
73+
if (const auto * column_sparse = typeid_cast<const ColumnSparse *>(expected_column))
74+
expected_column = &column_sparse->getValuesColumn();
7075
}
7176

7277
const auto * actual_column_maybe_agg = typeid_cast<const ColumnAggregateFunction *>(actual_column);
73-
const auto * expected_column_maybe_agg = typeid_cast<const ColumnAggregateFunction *>(expected.column.get());
78+
const auto * expected_column_maybe_agg = typeid_cast<const ColumnAggregateFunction *>(expected_column);
79+
7480
if (actual_column_maybe_agg && expected_column_maybe_agg)
7581
{
7682
if (!actual_column_maybe_agg->getAggregateFunction()->haveSameStateRepresentation(*expected_column_maybe_agg->getAggregateFunction()))
@@ -80,13 +86,16 @@ static ReturnType checkColumnStructure(const ColumnWithTypeAndName & actual, con
8086
actual.dumpStructure(),
8187
expected.dumpStructure());
8288
}
83-
else if (actual_column->getName() != expected.column->getName())
89+
else if (actual_column->getName() != expected_column->getName())
90+
{
8491
return onError<ReturnType>(code,
8592
"Block structure mismatch in {} stream: different columns:\n{}\n{}",
8693
context_description,
8794
actual.dumpStructure(),
8895
expected.dumpStructure());
8996

97+
}
98+
9099
if (isColumnConst(*actual.column) && isColumnConst(*expected.column)
91100
&& !actual.column->empty() && !expected.column->empty()) /// don't check values in empty columns
92101
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
redefined
22
redefined
3+
redefined

tests/queries/0_stateless/03121_analyzer_filed_redefenition_in_subquery.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ FROM
2828
);
2929

3030
-- query 3
31-
-- it works with old analyzer
3231
SELECT my_field
3332
FROM
3433
(
3534
SELECT
3635
*,
3736
'redefined' AS my_field
3837
from (select * from test_subquery)
39-
); -- {serverError AMBIGUOUS_COLUMN_NAME}
38+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
DROP TABLE IF EXISTS t_projection_sparse;
3+
CREATE TABLE t_projection_sparse
4+
(
5+
`id` String,
6+
`val` AggregateFunction(sum, UInt64),
7+
PROJECTION projection_traces_by_id
8+
(
9+
SELECT
10+
id,
11+
finalizeAggregation(val)
12+
ORDER BY finalizeAggregation(val)
13+
)
14+
)
15+
ENGINE = AggregatingMergeTree
16+
ORDER BY id
17+
SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 1;
18+
19+
INSERT INTO t_projection_sparse VALUES ('aa', initializeAggregation('sumState', 0::UInt64));
20+
INSERT INTO t_projection_sparse VALUES ('aa', initializeAggregation('sumState', 0::UInt64));
21+
INSERT INTO t_projection_sparse VALUES ('bb', initializeAggregation('sumState', 0::UInt64));
22+
23+
OPTIMIZE TABLE t_projection_sparse FINAL;
24+
OPTIMIZE TABLE t_projection_sparse FINAL;
25+
26+
SELECT count() FROM t_projection_sparse WHERE finalizeAggregation(val) = 0;
27+
28+
DROP TABLE t_projection_sparse;

0 commit comments

Comments
 (0)