Skip to content

Exception: Cannot convert column xxx because it is non constant in source stream but must be constant in result #36300

Closed

Description

@yingsun
  • Prepare test data
CREATE database IF NOT EXISTS test ON cluster cluster_single_shard;

-- create local table
CREATE TABLE test.user_local ON cluster cluster_single_shard (
   id Int64,
   name String,
   age Int32
) ENGINE = MergeTree
ORDER BY name
SETTINGS index_granularity = 8192;

-- create distributed table
CREATE TABLE test.user_all ON cluster cluster_single_shard
AS test.user_local
ENGINE = Distributed('cluster_single_shard', 'test', 'user_local', rand());

CREATE TABLE test.event ON cluster cluster_single_shard (
   id Int64,
   user_id Int64,
   content String,
   created_time DateTime
) ENGINE = MergeTree
ORDER BY user_id
SETTINGS index_granularity = 8192;

INSERT INTO test.user_local
(id, name, age) VALUES (1, 'aaa', 21);

INSERT INTO test.event
(id, user_id, content, created_time)
VALUES(1, 1, 'hello', '2022-01-05 12:00:00');
  • Test case
-- Error: 
SELECT  
  u.name user_name,
  20 AS age_group
FROM test.user_all u 
LEFT JOIN test.event e ON u.id = e.user_id
WHERE (u.age >= 20 AND u.age < 30)
AND e.created_time > '2022-01-01';

Received exception from server (version 22.3.3):
Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: Cannot convert column `age_group` because it is non constant in source stream but must be constant in result. (ILLEGAL_COLUMN)

-- OK: use local table [user_local] to replace distritubed table [user_all]
SELECT  
  u.name user_name,
  20 AS age_group
FROM test.user_local u 
LEFT JOIN test.event e ON u.id = e.user_id
WHERE (u.age >= 20 AND u.age < 30)
AND e.created_time > '2022-01-01';

-- OK: the 20 in SELECT  is not in WHERE condition.
SELECT  
  u.name user_name,
  20 AS age_group
FROM test.user_all u 
LEFT JOIN test.event e ON u.id = e.user_id
WHERE (u.age >= 21 AND u.age < 30)
AND e.created_time > '2022-01-01';

-- OK: without join, with distributed table
SELECT  
  u.name user_name,
  20 AS age_group
FROM test.user_all u 
WHERE (u.age >= 20 AND u.age < 30);

Activity

  1. added
    potential bug
    on Apr 15, 2022
  2. tavplubix commented on May 2, 2022

    @tavplubix
    Member

    Reproduced on 22.5.1.1

  3. added
    bug
    and removed
    potential bug
    on May 2, 2022
  4. vdimir commented on May 2, 2022

    @vdimir
    Member

    Maybe related #36279

  5. self-assigned this
    on May 2, 2022
  6. vdimir commented on May 6, 2022

    @vdimir
    Member

    Closed via #36542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugduplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions