Skip to content

Conversation

@KKould
Copy link
Member

@KKould KKould commented Nov 20, 2025

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

Summary

pivot would cause additional columns to be selected within the pivot's internal select when selecting individual columns, resulting in more columns than expected.

example:

CREATE OR REPLACE TABLE test_string_pivot (
    id INT,
    region VARCHAR(10),
    month VARCHAR(10),
    sales INT
);

INSERT INTO test_string_pivot VALUES
    (1, 'North', 'Jan', 100),
    (1, 'North', 'Mar', 300),
    (1, 'North', 'Feb', 200),
    (2, 'South', 'Jan', 150),
    (2, 'South', 'Mar', 350),
    (2, 'South', 'Feb', 250);

# It only needs 2 columns but returned 7 columns.
query ITIII
SELECT id, region FROM test_string_pivot PIVOT (
    SUM(sales) FOR month IN (ANY ORDER BY month)
)
ORDER BY id, region;
----
1 North 1 North 200 100 300
2 South 2 South 250 150 350

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

@KKould KKould self-assigned this Nov 20, 2025
@github-actions github-actions bot added the pr-chore this PR only has small changes that no need to record, like coding styles. label Nov 20, 2025
@KKould KKould changed the title chore: fix scalars test fix: fix pivot extra columns on projection Nov 20, 2025
@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Nov 20, 2025
@KKould KKould force-pushed the fix/pivot_extra_columns branch from 841d5c5 to c65af67 Compare November 20, 2025 07:11
@KKould KKould marked this pull request as ready for review November 20, 2025 07:59
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@KKould KKould force-pushed the fix/pivot_extra_columns branch from c65af67 to e36e183 Compare November 20, 2025 10:06
@KKould KKould changed the title fix: fix pivot extra columns on projection fix: pivot extra columns on projection Nov 20, 2025
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 pr-chore this PR only has small changes that no need to record, like coding styles.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant