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

feat(frontend): use function name as alias in select item #6782

Closed
wants to merge 1 commit into from

Conversation

ZENOTME
Copy link
Contributor

@ZENOTME ZENOTME commented Dec 7, 2022

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

PLEASE DO NOT LEAVE THIS EMPTY !!!

when use function, Postgres will use function name as column name

test_db=> select sum(id) from t;
 sum
-----

(1 row)

test_db=> select avg(id) from t;
 avg
-----

(1 row)

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Documentation

If your pull request contains user-facing changes, please specify the types of the changes, and create a release note. Otherwise, please feel free to remove this section.

Types of user-facing changes

Please keep the types that apply to your changes, and remove those that do not apply.

  • Installation and deployment
  • Connector (sources & sinks)
  • SQL commands, functions, and operators
  • RisingWave cluster configuration changes
  • Other (please specify in the release note below)

Release note

Please create a release note for your changes. In the release note, focus on the impact on users, and mention the environment or conditions where the impact may occur.

Refer to a related PR or issue link (optional)

Copy link
Contributor

@BowenXiao1999 BowenXiao1999 left a comment

Choose a reason for hiding this comment

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

Previously is ?column? ? 🤔

@ZENOTME
Copy link
Contributor Author

ZENOTME commented Dec 7, 2022

Seems that's because we want user to specify alias in most of time. Maybe this PR should not be merge.

// Aggregation without alias is forbidden.

@xiangjinwu
Copy link
Contributor

What is the motivation? FYI:

  • The full heuristic used by PostgreSQL for generating column names is here frontend: Derive output column names #3812 (comment)
    • For example, v1::bigint is still v1 but 1::bigint is int8. There are 3 levels of priorities.
  • We did want user to specify aliases themselves. But as we add support of discovery of column names (e.g. describe mv1;, select * from information_schema.columns where table_name = 'mv1' although still not \d mv1), it is comparably less an issue now if we generate a non-trivial name that user did not specify explicitly. So if we do need to support this and align with PG, let's just raise this to broader audience for agreement.

@ZENOTME
Copy link
Contributor Author

ZENOTME commented Dec 7, 2022

The motivation for add this is that I encouter a case in supporting create-table-as:
CREATE TABLE integers2 AS SELECT generate_series(0, 100);
In this case integers2 will have a column name 'generate_series' in postgres.
But create-table-as is kind of like create-mv, it's reasonable if we also force user to specify the column name, such as
CREATE TABLE integers2 AS SELECT generate_series(0, 100) tbl(i);
CREATE TABLE integers2(i) AS SELECT generate_series(0, 100);

@xiangjinwu
Copy link
Contributor

It seems the code change in this PR handles the following:

SELECT generate_series(0, 100);

rather than the intended case:

SELECT * FROM generate_series(0, 100);

The latter is TableFactor::TableFunction/Relation::TableFunction rather than Expr::Function

@ZENOTME ZENOTME closed this Dec 8, 2022
@ZENOTME ZENOTME deleted the zj/function_name branch December 8, 2022 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants