Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MikageSawatari opened this issue Mar 25, 2022 · 3 comments · Fixed by #62185
Labels
bug Confirmed user-visible misbehaviour in official release st-hold We've paused the work on issue for some reason

Comments

@MikageSawatari
Copy link

MikageSawatari commented Mar 25, 2022

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.

@MikageSawatari MikageSawatari added the potential bug To be reviewed by developers and confirmed/rejected. label Mar 25, 2022
@Avogar
Copy link
Member

Avogar commented Mar 25, 2022

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)

@Avogar Avogar added the bug Confirmed user-visible misbehaviour in official release label Mar 25, 2022
@Avogar
Copy link
Member

Avogar commented Mar 25, 2022

:) 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)

@Avogar
Copy link
Member

Avogar commented Mar 25, 2022

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

@den-crane den-crane removed the potential bug To be reviewed by developers and confirmed/rejected. label Mar 25, 2022
@alexey-milovidov alexey-milovidov added the st-hold We've paused the work on issue for some reason label Aug 13, 2022
fm4v added a commit that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release st-hold We've paused the work on issue for some reason
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants