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): support show create [materialized] view command #6921

Merged
merged 5 commits into from
Dec 16, 2022

Conversation

yezizp2012
Copy link
Member

@yezizp2012 yezizp2012 commented Dec 15, 2022

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

What's changed and what's your intention?

Support show create create [materialized] view commands.

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

  • SQL commands, functions, and operators
    Support show create create [materialized] view commands:
dev=> create table t2(v1 int);
CREATE_TABLE
dev=> create materialized view mv1 as select * from t2;
CREATE_MATERIALIZED_VIEW
dev=> create view v1 as select * from t2;
CREATE_VIEW
dev=> show create materialized view public.mv1;
    Name    |                    Create Sql
------------+--------------------------------------------------
 public.mv1 | CREATE MATERIALIZED VIEW mv1 AS SELECT * FROM t2
(1 row)

dev=> show create view v1;
   Name    |             Create Sql
-----------+------------------------------------
 public.v1 | CREATE VIEW v1 AS SELECT * FROM t2
(1 row)

Release note

Support show create create [materialized] view commands.

Refer to a related PR or issue link (optional)

Resolve #6913

@yezizp2012 yezizp2012 added the user-facing-changes Contains changes that are visible to users label Dec 15, 2022
Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

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

LGTM.

Should we also support showing the view definition in a pg compatible way (via pg_get_viewdef or pg_views)?

@yezizp2012
Copy link
Member Author

LGTM.

Should we also support showing the view definition in a pg compatible way (via pg_get_viewdef or pg_views)?

Yes, we already support definition column in pg_views. 😄

Copy link
Member

@fuyufjh fuyufjh left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you a lot! ❤️

Comment on lines +169 to +173
// We only stored original sql in catalog, uses parser to parse and format.
let stmt = Parser::parse_sql(&view.sql)
.map_err(|err| anyhow!("Failed to parse view create sql: {}, {}", view.sql, err))?;
assert!(stmt.len() == 1);
stmt[0].to_string()
Copy link
Member

Choose a reason for hiding this comment

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

The SQL unparsed from the AST might be incorrect. :( #6801 Will this be a problem, if this is for some programs to read?

Copy link
Member

Choose a reason for hiding this comment

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

If so, I guess we need to carefully review the fmt::Display for all AST nodes and add a comprehensive test suite for it.

Copy link
Member Author

@yezizp2012 yezizp2012 Dec 16, 2022

Choose a reason for hiding this comment

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

🥵 I think this is just for user to check how the mview and view are created.

If so, I guess we need to carefully review the fmt::Display for all AST nodes and add a comprehensive test suite for it.

But this's also needed, does the tests in sql_parser meet demand? It seems that we only have few tests there.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure. cc @lmatz

Copy link
Member

@xxchan xxchan Dec 16, 2022

Choose a reason for hiding this comment

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

We can test roundtrip parsing (parse(unparse(parse(sql))) == parse(sql) ) in sqlsmith. Created an issue #6935

Copy link
Member

Choose a reason for hiding this comment

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

Agree.

Copy link
Member

@BugenZhao BugenZhao Dec 16, 2022

Choose a reason for hiding this comment

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

We can test roundtrip parsing (parse(unparse(parse(sql))) == parse(sql) ) in sqlsmith.

I'm afraid there's a case that some different SQLs are parsed to the same AST, which requires some binder context to distinguish. So when we unparse it, we cannot find the original representation, and this roundtrip test cannot cover this. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that's exactly why using AST instead of original sql to compare in xxchan's proposal?

@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Merging #6921 (8ddc05d) into main (98a1853) will decrease coverage by 0.03%.
The diff coverage is 20.40%.

@@            Coverage Diff             @@
##             main    #6921      +/-   ##
==========================================
- Coverage   72.71%   72.68%   -0.04%     
==========================================
  Files        1036     1036              
  Lines      166192   166289      +97     
==========================================
+ Hits       120840   120859      +19     
- Misses      45352    45430      +78     
Flag Coverage Δ
rust 72.68% <20.40%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/frontend/src/handler/mod.rs 63.93% <0.00%> (-0.71%) ⬇️
src/frontend/src/handler/show.rs 63.59% <0.00%> (-23.20%) ⬇️
src/sqlparser/src/parser.rs 92.45% <44.00%> (-0.50%) ⬇️
src/sqlparser/src/ast/mod.rs 86.67% <69.23%> (-0.22%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: support show create [materialized] view
6 participants