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

fix(sql): allow selecting aliased column followed by wildcard #3034

Merged
merged 7 commits into from
Mar 12, 2023

Conversation

puzpuzpuz
Copy link
Contributor

Fixes #2870

@puzpuzpuz puzpuzpuz added Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution labels Mar 1, 2023
@puzpuzpuz puzpuzpuz self-assigned this Mar 1, 2023
eugenels
eugenels previously approved these changes Mar 3, 2023
@bziobrowski
Copy link
Contributor

bziobrowski commented Mar 7, 2023

Similar error still occurs if there's a join :

create table xo1 as 
(
  select
  rnd_double(0)*100 a,
  rnd_long() l,
  timestamp_sequence(0, 10000) k
  from long_sequence(3)
) timestamp(k);

create table xo2 as 
(
  select
  rnd_double(0)*100 a,
  rnd_long() l,
  timestamp_sequence(0, 10000) k
  from long_sequence(3)
) timestamp(k);


select cast(xo1.k as long), cast(xo2.k as long), *
from xo1  
join xo2 on xo1.k = xo2.k;

--or

select rnd_int()*k as zz, * 
from xo1  
join xo2 on xo1.k = xo2.k;

--Duplicate column [name=k]

@puzpuzpuz
Copy link
Contributor Author

@bziobrowski good catch. Let me take a look at joins.

@bluestreak01 bluestreak01 dismissed eugenels’s stale review March 8, 2023 17:46

there is an issue to fix

@puzpuzpuz
Copy link
Contributor Author

puzpuzpuz commented Mar 9, 2023

Similar error still occurs if there's a join

Addressed in 0087879

Note:

select rnd_int()*k as zz, *
from xo1  
join xo2 on xo1.k = xo2.k;**

This query is incorrect: should be rnd_int()*xo1.k or rnd_int()*xo2.k instead of rnd_int()*k.

@eugenels
Copy link
Contributor

Similar error still occurs if there's a join :

create table xo1 as 
(
  select
  rnd_double(0)*100 a,
  rnd_long() l,
  timestamp_sequence(0, 10000) k
  from long_sequence(3)
) timestamp(k);

create table xo2 as 
(
  select
  rnd_double(0)*100 a,
  rnd_long() l,
  timestamp_sequence(0, 10000) k
  from long_sequence(3)
) timestamp(k);


select cast(xo1.k as long), cast(xo2.k as long), *
from xo1  
join xo2 on xo1.k = xo2.k;

--or

select rnd_int()*k as zz, * 
from xo1  
join xo2 on xo1.k = xo2.k;

--Duplicate column [name=k]

Should this work for cross join as well?

select *, xo1.k as kk1 from xo1 cross join xo2;
-- vs
select xo1.k as kk1, * from xo1 cross join xo2;

@puzpuzpuz
Copy link
Contributor Author

Should this work for cross join as well?

Yes, it should. Fixed that in 3404ce6

Copy link
Contributor

@eugenels eugenels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ideoma
Copy link
Collaborator

ideoma commented Mar 10, 2023

[PR Coverage check]

😍 pass : 8 / 8 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/SqlOptimiser.java 8 8 100.00%

@bluestreak01 bluestreak01 merged commit 44f507c into master Mar 12, 2023
@bluestreak01 bluestreak01 deleted the fix_aliased_cast_followed_by_wildcard branch March 12, 2023 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate Column when using CAST and * in the same SELECT
5 participants