Skip to content

Table aliases in MATERIALIZED VIEWS #10894

Closed

Description

@simplemagik

Seems there is some trouble with table aliases in creating MATERIALIZED VIEWS (mb somewhere else too)

How to reproduce:

CREATE TABLE event (
    `event_time` DateTime,
    `event_name` String,
    `user_id` String
)
ENGINE = MergeTree()
ORDER BY (event_time, event_name)

CREATE TABLE user (
    `user_id` String,
    `user_type` String
)
ENGINE = MergeTree()
ORDER BY (user_id)

INSERT INTO event VALUES
('2020-05-01 00:00:01', 'install', '1'),
('2020-05-01 00:00:02', 'install', '2')
('2020-05-01 00:00:03', 'install', '3')

INSERT INTO user VALUES
('1', 'type_1'),
('2', 'type_2'),
('3', 'type_3')

CREATE MATERIALIZED VIEW mv
(
    `event_time` DateTime,
    `event_name` String,
    `user_id` String,
    `user_type` String
)
ENGINE = MergeTree()
ORDER BY (event_time, event_name) POPULATE AS
SELECT
    e.event_time,
    e.event_name,
    e.user_id,
    u.user_type
FROM event e
INNER JOIN user u ON u.user_id = e.user_id

Got error DB::Exception: Cannot detect left and right JOIN keys. JOIN ON section is ambiguous..

But next one works fine


DROP TABLE mv
CREATE MATERIALIZED VIEW mv
(
    `event_time` DateTime,
    `event_name` String,
    `user_id` String,
    `user_type` String
)
ENGINE = MergeTree()
ORDER BY (event_time, event_name) POPULATE AS
SELECT
    event.event_time,
    event.event_name,
    event.user_id,
    user.user_type
FROM event
INNER JOIN user ON user.user_id = event.user_id

Activity

  1. added
    bug
    on May 13, 2020
  2. added
    st-accepted
    on May 13, 2020
  3. added
    comp-joins
    on May 14, 2020
  4. self-assigned this
    on May 18, 2020
  5. removed their assignment
    on Oct 16, 2020
  6. Weilor commented on Nov 4, 2020

    @Weilor

    The problem is same with mine. Is there any progress?

  7. nixikanius commented on Oct 14, 2021

    @nixikanius
    select e.id,
           e.name,
           ea1.value  a1_value,
           ea2.value  a2_value,
    from   entities e
    left join entity_attributes ea1 on ea1.entity_id = e.id and ea1.name = 'attribute1'
    left join entity_attributes ea2 on ea2.entity_id = e.id and ea2.name = 'attribute2';
    

    Is there any workaround to create a view for the above query? With double join of the same table.

  8. removed
    comp-joins
    on Mar 21, 2022
  9. added a commit that references this issue on Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugst-accepted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions