Skip to content

An error is reported when both constants and fields exist in a"casewhen/multiIf" #59101

Closed

Description

@h1k

A link to reproducer in https://fiddle.clickhouse.com/.
https://fiddle.clickhouse.com/2c5918cf-5c0e-4dd1-bf40-4f6c3379ee62

Does it reproduce on recent release?
yes

  • Which ClickHouse server version to use
    23.3.18
  • CREATE TABLE statements for all tables involved
CREATE TABLE users (name String, age Int16) ENGINE=Memory;
INSERT INTO users VALUES ('John', 33);
INSERT INTO users VALUES ('Ksenia', 48);
INSERT INTO users VALUES ('Alice', 50);
  • Queries to run that lead to unexpected result
SELECT
    multiIf((age > 30) or (true), '1', '2') AS a,
    max(name)
FROM users
GROUP BY a

Expected behavior
return "1 Ksenia"

Error message
Exception: Column age is not under aggregate function and not in GROUP BY. Have columns: ['max(name)']: While processing if((age > 30) OR true, '1', '2') AS a, max(name). (NOT_AN_AGGREGATE)

Activity

  1. added
    potential bug
    on Jan 23, 2024
  2. Avogar commented on Jan 23, 2024

    @Avogar
    Member

    This query works with new analyzer:

    :) SELECT If(age > 30 or true, '1', '2') AS a, max(name) FROM users GROUP BY a settings allow_experimental_analyzer=1
    
    ┌─a─┬─max(name)─┐
    │ 1 │ Ksenia    │
    └───┴───────────┘
    

    Not sure if we want to fix it in current infrastracture as we are working on enabling new analyzer by default. Possible workaround:
    Use materialized(true):

    :) SELECT If(age > 30 or materialize(true), '1', '2') AS a, max(name) FROM users GROUP BY a
    
    
    ┌─a─┬─max(name)─┐
    │ 1 │ Ksenia    │
    └───┴───────────┘
    
  3. h1k commented on Jan 23, 2024

    @h1k
    Author

    This query works with new analyzer:

    :) SELECT If(age > 30 or true, '1', '2') AS a, max(name) FROM users GROUP BY a settings allow_experimental_analyzer=1
    
    ┌─a─┬─max(name)─┐
    │ 1 │ Ksenia    │
    └───┴───────────┘
    

    Not sure if we want to fix it in current infrastracture as we are working on enabling new analyzer by default. Possible workaround: Use materialized(true):

    :) SELECT If(age > 30 or materialize(true), '1', '2') AS a, max(name) FROM users GROUP BY a
    
    
    ┌─a─┬─max(name)─┐
    │ 1 │ Ksenia    │
    └───┴───────────┘
    

    Thank you for your answer.
    Are there any side effects of this configuration allow_experimental_analyzer? Can I configure globally and use it in a production environment? Where can I find documentation for these optimization parameters?

  4. Avogar commented on Jan 23, 2024

    @Avogar
    Member

    Are there any side effects of this configuration allow_experimental_analyzer? Can I configure globally and use it in a production environment?

    New analyzer is not ready for production right now, so some queries might not work or work incorrectly, so I don't recommend using it in production. As I said, we are working on making it production ready.

    Where can I find documentation for these optimization parameters?

    What do you mean by optimization parameters? Setting allow_experimental_analyzer is not an optimization, it just enables new infrastructure for query analysis and planning that we will use in future, it's a complitely internal change, so we don't have documentation for it.

  5. h1k commented on Jan 23, 2024

    @h1k
    Author

    Are there any side effects of this configuration allow_experimental_analyzer? Can I configure globally and use it in a production environment?

    New analyzer is not ready for production right now, so some queries might not work or work incorrectly, so I don't recommend using it in production. As I said, we are working on making it production ready.
    I see,Thanks again

    Where can I find documentation for these optimization parameters?

    What do you mean by optimization parameters? Setting allow_experimental_analyzer is not an optimization, it just enables new infrastructure for query analysis and planning that we will use in future, it's a complitely internal change, so we don't have documentation for it.
    I'm not sure if this is a known problem or if there is a workaround, as I've had a lot of unexpected problems in clickhouse, such as # #58500 and #56005 , and it might have been helpful to have a documentation

  6. added a commit that references this issue on Apr 9, 2024
  7. added
    bug
    and removed
    potential bug
    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

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions