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(query): fix group by with alias column can't bind the column #16804

Merged
merged 8 commits into from
Nov 14, 2024

Conversation

b41sh
Copy link
Member

@b41sh b41sh commented Nov 11, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • Fix group by can't bind the column in the Set-returning function.
  • If the Set-returning function arguments contains Aggregate function or group by item, set it as lazy Set-returning function and build ProjectSet plan after Aggregate plan.
  • Check group by item before create derive column to avoid duplicate column.
  • Modify mock redis ports to avoid conflicts.

for example:

MySQL [(none)]> CREATE OR REPLACE TABLE t_str (col1 string, col2 string);
Query OK, 0 rows affected (0.155 sec)

MySQL [(none)]> INSERT INTO t_str VALUES ('test', 'a1,a2'),('test', 'a1,a2,a3');
Query OK, 2 rows affected (0.206 sec)

MySQL [(none)]> SELECT t.col1 AS col1, unnest(split(t.col2, ',')) AS col2 FROM t_str AS t GROUP BY col1, col2 ORDER BY col2;
+------+------+
| col1 | col2 |
+------+------+
| test | a1   |
| test | a1   |
| test | a2   |
| test | a2   |
| test | a3   |
+------+------+
5 rows in set (0.095 sec)

MySQL [(none)]> SELECT t.col1 AS col1, unnest(split(t.col2, ',')) AS col3 FROM t_str AS t GROUP BY col1, col3 ORDER BY col3;
+------+------+
| col1 | col3 |
+------+------+
| test | a1   |
| test | a2   |
| test | a3   |
+------+------+
3 rows in set (0.102 sec)

MySQL [(none)]> SELECT max(unnest(split(t.col2, ','))) FROM t_str AS t;
+---------------------------------+
| max(unnest(split(t.col2, ','))) |
+---------------------------------+
| a3                              |
+---------------------------------+
1 row in set (0.106 sec)

MySQL [(none)]> SELECT unnest(split(max(t.col2), ',')) FROM t_str AS t;
+---------------------------------+
| unnest(split(max(t.col2), ',')) |
+---------------------------------+
| a1                              |
| a2                              |
| a3                              |
+---------------------------------+
3 rows in set (0.089 sec)

fixes: #16797

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@b41sh b41sh requested a review from sundy-li November 11, 2024 05:48
@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Nov 11, 2024
@b41sh b41sh marked this pull request as draft November 11, 2024 15:06
@b41sh b41sh marked this pull request as ready for review November 13, 2024 15:42
@b41sh b41sh requested a review from sundy-li November 13, 2024 15:48
@sundy-li sundy-li added this pull request to the merge queue Nov 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Nov 14, 2024
@b41sh b41sh enabled auto-merge November 14, 2024 06:43
@b41sh b41sh added this pull request to the merge queue Nov 14, 2024
Merged via the queue into databendlabs:main with commit 7509439 Nov 14, 2024
74 checks passed
@b41sh b41sh deleted the fix-srf-group branch November 14, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: SQL semantics prevent use of unnest with group by
2 participants