Skip to content

Hybrid engine generates duplicate ALIAS expressions when ALIAS type is manually misspecified #1335

@alsugiliazova

Description

@alsugiliazova

Describe the bug

CREATE TABLE left
(
    `id` Int32,
    `value` Int32,
    `date_col` Date,
    `value_minus` ALIAS value - 1
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(date_col)
ORDER BY (date_col, id);

CREATE TABLE right
(
    `id` Int32,
    `value` Int32,
    `date_col` Date,
    `value_minus` ALIAS value - 1
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(date_col)
ORDER BY (date_col, id);

insert into left values (1, 100, toDate('1970-01-01')), (2, 200, toDate('1970-01-01')), (3, 300, toDate('1970-01-01'));

insert into right values (4, 400, toDate('1970-01-01')), (5, 500, toDate('1970-01-01')),(6, 600, toDate('1970-01-01'));

Here I create hybrid table with a small mistake (Int32 instead of Int64):

SET allow_experimental_hybrid_table = 1;
CREATE TABLE hybrid_with_col_def
(
    `id` Int32,
    `value` Int32,
    `date_col` Date,
    `value_minus` Int32
)
ENGINE = Hybrid(remote('localhost', currentDatabase(), 'left'), id < 4, remote('localhost', currentDatabase(), 'right'), id >= 4);
SELECT *
FROM hybrid_with_col_def
Query id: 55034679-a315-45d3-965c-f3b674859224


Elapsed: 0.009 sec. 

Received exception from server (version 25.8.14):
Code: 179. DB::Exception: Received from localhost:9000. DB::Exception: Multiple expressions __aliasMarker(__table1.value - 1, '__table1.value_minus') AS value_minus and _CAST(__aliasMarker(__table1.value - 1, '__table1.value_minus') AS value_minus, 'Int32') AS value_minus for alias value_minus. In scope SELECT __table1.id AS id, __table1.value AS value, __table1.date_col AS date_col, _CAST(__aliasMarker(__table1.value - 1, '__table1.value_minus') AS value_minus, 'Int32') AS value_minus FROM remote('localhost', 'default', 'right') AS __table1 WHERE __table1.id >= 4. (MULTIPLE_EXPRESSIONS_FOR_ALIAS)

No problems if I create it without a column definition because correct datatype automatically be used:

CREATE TABLE hybrid_without_col_def
ENGINE = Hybrid(remote('localhost', currentDatabase(), 'left'), id < 4, remote('localhost', currentDatabase(), 'right'), id >= 4);
SELECT
    *,
    value_minus
FROM hybrid_without_col_def
Query id: f7a1625a-d73f-4f97-8763-f30cdf6990eb

   ┌─id─┬─value─┬───date_col─┬─value_minus─┐
1. │  1 │   100 │ 1970-01-01 │          99 │
2. │  3 │   300 │ 1970-01-01 │         299 │
3. │  4 │   400 │ 1970-01-01 │         399 │
4. │  5 │   500 │ 1970-01-01 │         499 │
5. │  6 │   600 │ 1970-01-01 │         599 │
6. │  2 │   200 │ 1970-01-01 │         199 │
   └────┴───────┴────────────┴─────────────┘

6 rows in set. Elapsed: 0.010 sec. 
SHOW CREATE TABLE hybrid_without_col_def
Query id: 2e9128dc-f528-4cdd-af92-0698e1350460

   ┌─statement─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
1. │ CREATE TABLE default.hybrid_without_col_def                                                                              ↴│
   │↳(                                                                                                                        ↴│
   │↳    `id` Int32,                                                                                                          ↴│
   │↳    `value` Int32,                                                                                                       ↴│
   │↳    `date_col` Date,                                                                                                     ↴│
   │↳    `value_minus` Int64 ALIAS value - 1                                                                                  ↴│
   │↳)                                                                                                                        ↴│
   │↳ENGINE = Hybrid(remote('localhost', 'default', 'left'), id < 4, remote('localhost', currentDatabase(), 'right'), id >= 4) │
   └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

1 row in set. Elapsed: 0.004 sec. 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions