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

bug: LATERAL VALUES still ignores some NULLs #15886

Closed
1 task done
rad-pat opened this issue Jun 24, 2024 · 0 comments · Fixed by #15924
Closed
1 task done

bug: LATERAL VALUES still ignores some NULLs #15886

rad-pat opened this issue Jun 24, 2024 · 0 comments · Fixed by #15924
Assignees
Labels
C-bug Category: something isn't working

Comments

@rad-pat
Copy link

rad-pat commented Jun 24, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

Version

datafuselabs/databend-query:v1.2.540-nightly

What's Wrong?

When using Lateral values statement, some NULL values are still excluded from results. This is a follow-up from testing with fix for #15722

How to Reproduce?

drop table if exists rates;	
create table rates(origin varchar, dest varchar, distance int, "r2023" decimal(38,10), "r2022" decimal(38,10), "r2021" decimal(38,10));
insert into rates values ('a', 'b', 500, 2023.12, 2022.23, 2021.34);
insert into rates values ('a', 'c', 500, 2023.11, null, null);
-- futher nulls
insert into rates values ('a', 'd', 400, null, null, null);
insert into rates values ('a', 'e', null, null, null, null);

WITH source AS(
	SELECT origin, 
		dest,  
		distance, 
		"r2023", 
		"r2022",
		"r2021"
	FROM "rates"
)
SELECT r.origin, r.dest, r.rates, r.values
FROM (
	SELECT source.origin, 
		source.dest, 
		v.rates,
		v.values
	FROM source 
	JOIN LATERAL (
		VALUES 
			(source."distance", 'distance'), 
			(source."r2023", 'r2023'), 
			(source."r2022", 'r2022'),  
			(source."r2021", 'r2021')
	) AS v ("values", "rates") ON true
) AS r

Expected Results:

origin|dest|rates   |values |
------+----+--------+-------+
a     |b   |distance|  500.0|
a     |b   |r2023   |2023.12|
a     |b   |r2022   |2022.23|
a     |b   |r2021   |2021.34|
a     |c   |distance|  500.0|
a     |c   |r2023   |2023.11|
a     |c   |r2022   |   null|
a     |c   |r2021   |   null|
a     |d   |distance|  400.0|
a     |d   |r2023   |   null|
a     |d   |r2022   |   null|
a     |d   |r2021   |   null|
a     |e   |distance|   null|
a     |e   |r2023   |   null|
a     |e   |r2022   |   null|
a     |e   |r2021   |   null|

Actual Results:

origin|dest|rates   |values |
------+----+--------+-------+
a     |b   |distance|  500.0|
a     |b   |r2023   |2023.12|
a     |b   |r2022   |2022.23|
a     |b   |r2021   |2021.34|
a     |c   |distance|  500.0|
a     |c   |r2023   |2023.11|
a     |c   |r2022   |   null|
a     |c   |r2021   |   null|
@rad-pat rad-pat added the C-bug Category: something isn't working label Jun 24, 2024
@b41sh b41sh assigned b41sh and Dousir9 and unassigned b41sh Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants