Skip to content

Numeric literals and column names which solely consist of digits are not correctly distinguished under a certain circumstance #35608

Closed

Description

@MikageSawatari

Describe what's wrong

Numeric literals and column names which solely consist of digits are
not correctly distinguished under a certain circumstance, and can
yield a type error.

Does it reproduce on recent release?

21.12.2.1 and 22.2.3.1 are known to have this issue.

How to reproduce

Queries like this result in an error:

CREATE TABLE testdata (`1` String) ENGINE=MergeTree ORDER BY tuple();
INSERT INTO testdata VALUES ('testdata');

SELECT *
  FROM (
       SELECT if(isValidUTF8(`1`), NULL, 'error!') AS error_message,
              if(error_message IS NULL, 1, 0) AS valid
         FROM testdata
  )
  WHERE valid
;
Received exception from server (version 21.12.2):
Code: 43. DB::Exception: Received from localhost:9000. DB::Exception: Illegal type UInt8 of argument of function isValidUTF8: While processing SELECT if(isValidUTF8(`1`), NULL, 'error!') AS error_message, if(error_message IS NULL, 1, 0) AS valid FROM testdata WHERE valid. (ILLEGAL_TYPE_OF_ARGUMENT)

This works:

SELECT if(isValidUTF8(`1`), NULL, 'error!') AS error_message,
      if(error_message IS NULL, 1, 0) AS valid
 FROM testdata
;

This works too:

SELECT *
  FROM (
       SELECT if(isValidUTF8(`1`), NULL, 'error!') AS error_message,
              if(error_message IS NULL, 2, 0) AS valid -- Literal 2 as opposed to 1.
         FROM testdata
  )
  WHERE valid
;

It seems the parser fails to interpret column names that look like
integers when they are in nested queries.

Activity

  1. added
    potential bug
    on Mar 25, 2022
  2. Avogar commented on Mar 25, 2022

    @Avogar
    Member
    select * from (select 'str' as `1`) where 1
    Code: 59. DB::Exception: Received from localhost:9000. DB::Exception: Invalid type for filter in WHERE: String. (ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER)
    
  3. added
    bug
    on Mar 25, 2022
  4. Avogar commented on Mar 25, 2022

    @Avogar
    Member
    :) select 'str', 1 as `'str'`
    Code: 352. DB::Exception: Received from localhost:9000. DB::Exception: Block structure mismatch in (columns with identical name must have identical structure) stream: different types:
    'str' String Const(size = 0, String(size = 1))
    'str' UInt8 Const(size = 0, UInt8(size = 1)). (AMBIGUOUS_COLUMN_NAME)
    
  5. Avogar commented on Mar 25, 2022

    @Avogar
    Member

    @kitaisreal is working on refactoring and improvements in identifier and alias analysis in #31796 and maybe his work will fix it

  6. removed
    potential bug
    on Mar 25, 2022
  7. added a commit that references this issue on Apr 3, 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