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: adding information_schema.views table #4342

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

lyang24
Copy link
Contributor

@lyang24 lyang24 commented Jul 10, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#4339

What's changed and what's your intention?

adding information_schema.views table to display views.
Please explain IN DETAIL what the changes are in this PR and why they are needed:

  • Summarize your change (mandatory)
    This content is generated by iterate table information from catalog manager and with filter table_type = VIEW, and retrieve view definition from table id. A very simple sqlness test is added as well.
  • How does this PR work? Need a brief introduction for the changed logic (optional)
  • Describe clearly one logical change and avoid lazy messages (optional)
  • Describe any limitations of the current code (optional)

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Introduced support for VIEWS in the information schema, allowing users to manage and query views within the database.
    • Added ability to create, query, and drop views using SQL statements.
  • Enhancements

    • Expanded SHOW queries to include the views table and relevant metadata.
    • Updated information schema tables with new columns to support view-related metadata.
  • Tests

    • Added new test scenarios to validate the creation, querying, and dropping of views.

Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

The changes introduce a new information_schema.views table in the system, allowing users to query metadata about views within the database. This enhancement involves adding new constants, importing relevant modules, defining structures and methods for handling views, and updating test cases to validate the new functionality.

Changes

Files/Paths Change Summary
src/catalog/src/information_schema.rs Added views module, imported InformationSchemaViews, and updated InformationSchemaProvider for handling VIEWS.
src/catalog/src/information_schema/table_names.rs Introduced a new constant VIEWS.
src/catalog/src/information_schema/views.rs Added structures and methods for managing views in the information schema.
src/common/catalog/src/consts.rs Added a new constant INFORMATION_SCHEMA_VIEW_TABLE_ID with value 32.
tests/cases/standalone/common/information_schema/views.result Added test scenarios for views, including creation, querying, and dropping of views.
tests/cases/standalone/common/information_schema/views.sql Included SQL commands for managing views, such as creating tables, defining views, querying, and dropping them.
tests/cases/standalone/common/show/show_databases_tables.result Updated SHOW queries to include the views table and new entries for myview.
tests/cases/standalone/common/system/information_schema.result Added columns related to views in the information_schema table and a new view entry in the public schema.
tests/cases/standalone/common/view/create.result Added a new view myview in the public schema and a new views table in information_schema.

Possibly related issues

  • Adds information_schema.views #4339: This issue involves implementing information_schema.views, which aligns directly with the changes made in this PR to provide metadata about database views.

Poem

In schemas deep where data flows,
New views arise, their structure shows.
With queries bright and swift delight,
Metadata gleams in the database night.
Constants, tests, and views anew,
A coder's dream, a task to do!
🎉🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 10, 2024
@lyang24 lyang24 marked this pull request as ready for review July 11, 2024 05:38
@lyang24 lyang24 requested a review from a team as a code owner July 11, 2024 05:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between da0c840 and f340e4a.

Files selected for processing (10)
  • src/catalog/src/information_schema.rs (4 hunks)
  • src/catalog/src/information_schema/table_names.rs (1 hunks)
  • src/catalog/src/information_schema/views.rs (1 hunks)
  • src/common/catalog/src/consts.rs (1 hunks)
  • tests/cases/standalone/common/information_schema/views.result (1 hunks)
  • tests/cases/standalone/common/information_schema/views.sql (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (4 hunks)
  • tests/cases/standalone/common/system/information_schema.result (4 hunks)
  • tests/cases/standalone/common/view/create.result (3 hunks)
  • tests/cases/standalone/create/recover_created.result (1 hunks)
Files skipped from review due to trivial changes (3)
  • src/catalog/src/information_schema/table_names.rs
  • tests/cases/standalone/common/information_schema/views.result
  • tests/cases/standalone/create/recover_created.result
Additional context used
Learnings (1)
tests/cases/standalone/common/information_schema/views.sql (1)
Learnt from: killme2008
PR: GreptimeTeam/greptimedb#4231
File: tests/cases/standalone/common/view/show_create.sql:37-37
Timestamp: 2024-07-09T20:51:21.719Z
Learning: The SQL located in `tests/cases` represents test cases designed to target specific corner cases. Suggestions such as using `DROP VIEW IF EXISTS` to avoid errors should not be applied in this context.
Additional comments not posted (17)
tests/cases/standalone/common/information_schema/views.sql (1)

1-13: SQL Test Cases Approved.

The SQL statements for creating the table, view, and querying the information_schema.views table are correct and cover the necessary functionality.

The DROP VIEW statement is commented out with a FIXME comment indicating it is not supported yet. This is acceptable for now, given the context.

src/common/catalog/src/consts.rs (1)

96-97: New Constant Addition Approved.

The addition of the INFORMATION_SCHEMA_VIEW_TABLE_ID constant follows the existing pattern and is appropriate for the new views table in the information schema.

src/catalog/src/information_schema/views.rs (1)

1-290: Implementation of InformationSchemaViews Approved.

The implementation of the InformationSchemaViews struct and its associated methods is comprehensive and follows best practices. The schema construction, data streaming, and builder methods are well-structured. Attention to error handling and the use of async/await for asynchronous operations are commendable.

src/catalog/src/information_schema.rs (2)

28-28: Integration of views Module Approved.

The integration of the views module into the InformationSchemaProvider is seamless and consistent with the existing codebase. The use of macros for setting up memory tables and the lazy_static block for initializing memory tables are well-aligned with the overall architecture.


268-271: Addition of InformationSchemaViews to information_table Approved.

The addition of the InformationSchemaViews to the information_table method in InformationSchemaProvider is correct and necessary for the new views table functionality.

tests/cases/standalone/common/show/show_databases_tables.result (3)

59-59: Approved: Addition of views to the list of tables.

The addition of the views table to the list of tables in the SHOW TABLES result is correct and aligns with the PR objectives.


104-104: Approved: Addition of views to the list of full tables.

The addition of the views table to the list of full tables in the SHOW FULL TABLES result is correct and aligns with the PR objectives.


142-142: Approved: Addition of views to the SHOW TABLE STATUS result.

The addition of the views table to the SHOW TABLE STATUS result is correct and aligns with the PR objectives.

tests/cases/standalone/common/view/create.result (6)

93-93: Approved: Addition of myview view to the SHOW TABLE STATUS from public section.

The addition of the myview view to the SHOW TABLE STATUS from public section is correct and aligns with the PR objectives.


112-112: Approved: Addition of views table to the SHOW TABLE STATUS result.

The addition of the views table to the SHOW TABLE STATUS result is correct and aligns with the PR objectives.


121-121: Approved: Addition of myview and test_view views to the SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW' result.

The addition of the myview and test_view views to the SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW' result is correct and aligns with the PR objectives.


Line range hint 169-169:
Approved: Creation of schema_for_view_test and test_view.

The creation of schema_for_view_test and test_view is correct and aligns with the PR objectives.


93-93: Approved: Addition of test_view to the SHOW TABLES result.

The addition of the test_view view to the SHOW TABLES result is correct and aligns with the PR objectives.


112-112: Approved: Addition of test_view to the SHOW FULL TABLES result.

The addition of the test_view view to the SHOW FULL TABLES result is correct and aligns with the PR objectives.

tests/cases/standalone/common/system/information_schema.result (3)

45-46: LGTM!

The addition of views and myview entries in the information schema is correct.


392-401: LGTM!

The added columns related to views in the information schema are correct and consistent with the expected structure.


Line range hint 441-464:
LGTM!

The addition of myview entries in the information schema is correct and consistent.

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

Attention: Patch coverage is 23.24324% with 142 lines in your changes missing coverage. Please review.

Project coverage is 84.83%. Comparing base (ab22bba) to head (1b38b6e).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4342      +/-   ##
==========================================
- Coverage   85.18%   84.83%   -0.35%     
==========================================
  Files        1061     1062       +1     
  Lines      189447   189632     +185     
==========================================
- Hits       161372   160883     -489     
- Misses      28075    28749     +674     

@lyang24 lyang24 changed the title wip: information schema views feat: adding information_schema.views table Jul 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f340e4a and 0fa915f.

Files selected for processing (10)
  • src/catalog/src/information_schema.rs (4 hunks)
  • src/catalog/src/information_schema/table_names.rs (1 hunks)
  • src/catalog/src/information_schema/views.rs (1 hunks)
  • src/common/catalog/src/consts.rs (1 hunks)
  • tests/cases/standalone/common/information_schema/views.result (1 hunks)
  • tests/cases/standalone/common/information_schema/views.sql (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (4 hunks)
  • tests/cases/standalone/common/system/information_schema.result (4 hunks)
  • tests/cases/standalone/common/view/create.result (3 hunks)
  • tests/cases/standalone/create/recover_created.result (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/catalog/src/information_schema.rs
Files skipped from review as they are similar to previous changes (8)
  • src/catalog/src/information_schema/table_names.rs
  • src/catalog/src/information_schema/views.rs
  • src/common/catalog/src/consts.rs
  • tests/cases/standalone/common/information_schema/views.result
  • tests/cases/standalone/common/show/show_databases_tables.result
  • tests/cases/standalone/common/system/information_schema.result
  • tests/cases/standalone/common/view/create.result
  • tests/cases/standalone/create/recover_created.result
Additional context used
Learnings (1)
tests/cases/standalone/common/information_schema/views.sql (1)
Learnt from: killme2008
PR: GreptimeTeam/greptimedb#4231
File: tests/cases/standalone/common/view/show_create.sql:37-37
Timestamp: 2024-07-09T20:51:21.719Z
Learning: The SQL located in `tests/cases` represents test cases designed to target specific corner cases. Suggestions such as using `DROP VIEW IF EXISTS` to avoid errors should not be applied in this context.
Additional comments not posted (7)
tests/cases/standalone/common/information_schema/views.sql (7)

1-1: Test header approved.

The header comment correctly indicates the purpose of the test.


2-2: Schema selection approved.

The USE public; statement correctly sets the current schema to public.


4-4: Table creation approved.

The create table t (ts timestamp time index, val int); statement correctly creates a table with the specified columns.


6-6: View creation approved.

The create view myview as select * from t where val > 5; statement correctly creates a view with the specified query.


8-8: Query statement approved.

The select table_catalog, table_schema, table_name, view_definition from information_schema.views; statement correctly queries the information schema views.


13-13: Table drop statement approved.

The drop table t; statement correctly drops the table.


10-11: Commented-out lines approved.

The comments correctly indicate that DROP VIEW is not supported yet.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0fa915f and 65c483c.

Files selected for processing (10)
  • src/catalog/src/information_schema.rs (4 hunks)
  • src/catalog/src/information_schema/table_names.rs (1 hunks)
  • src/catalog/src/information_schema/views.rs (1 hunks)
  • src/common/catalog/src/consts.rs (1 hunks)
  • tests/cases/standalone/common/information_schema/views.result (1 hunks)
  • tests/cases/standalone/common/information_schema/views.sql (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (4 hunks)
  • tests/cases/standalone/common/system/information_schema.result (4 hunks)
  • tests/cases/standalone/common/view/create.result (3 hunks)
  • tests/cases/standalone/create/recover_created.result (1 hunks)
Files skipped from review as they are similar to previous changes (9)
  • src/catalog/src/information_schema.rs
  • src/catalog/src/information_schema/table_names.rs
  • src/catalog/src/information_schema/views.rs
  • tests/cases/standalone/common/information_schema/views.result
  • tests/cases/standalone/common/information_schema/views.sql
  • tests/cases/standalone/common/show/show_databases_tables.result
  • tests/cases/standalone/common/system/information_schema.result
  • tests/cases/standalone/common/view/create.result
  • tests/cases/standalone/create/recover_created.result
Additional comments not posted (2)
src/common/catalog/src/consts.rs (2)

96-96: Comment is consistent with existing comments.

The comment indicating the ID for information_schema.VIEWS is consistent with the existing comments for other information_schema tables.


97-97: Constant follows naming conventions and is correctly placed.

The constant INFORMATION_SCHEMA_VIEW_TABLE_ID with a value of 32 follows the naming conventions and is correctly placed within the file.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 65c483c and e9d83e7.

Files selected for processing (9)
  • src/catalog/src/information_schema.rs (4 hunks)
  • src/catalog/src/information_schema/table_names.rs (1 hunks)
  • src/catalog/src/information_schema/views.rs (1 hunks)
  • src/common/catalog/src/consts.rs (1 hunks)
  • tests/cases/standalone/common/information_schema/views.result (1 hunks)
  • tests/cases/standalone/common/information_schema/views.sql (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (3 hunks)
  • tests/cases/standalone/common/system/information_schema.result (2 hunks)
  • tests/cases/standalone/common/view/create.result (1 hunks)
Files skipped from review as they are similar to previous changes (9)
  • src/catalog/src/information_schema.rs
  • src/catalog/src/information_schema/table_names.rs
  • src/catalog/src/information_schema/views.rs
  • src/common/catalog/src/consts.rs
  • tests/cases/standalone/common/information_schema/views.result
  • tests/cases/standalone/common/information_schema/views.sql
  • tests/cases/standalone/common/show/show_databases_tables.result
  • tests/cases/standalone/common/system/information_schema.result
  • tests/cases/standalone/common/view/create.result

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e9d83e7 and f1d312e.

Files selected for processing (9)
  • src/catalog/src/information_schema.rs (4 hunks)
  • src/catalog/src/information_schema/table_names.rs (1 hunks)
  • src/catalog/src/information_schema/views.rs (1 hunks)
  • src/common/catalog/src/consts.rs (1 hunks)
  • tests/cases/standalone/common/information_schema/views.result (1 hunks)
  • tests/cases/standalone/common/information_schema/views.sql (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (3 hunks)
  • tests/cases/standalone/common/system/information_schema.result (2 hunks)
  • tests/cases/standalone/common/view/create.result (1 hunks)
Files skipped from review as they are similar to previous changes (9)
  • src/catalog/src/information_schema.rs
  • src/catalog/src/information_schema/table_names.rs
  • src/catalog/src/information_schema/views.rs
  • src/common/catalog/src/consts.rs
  • tests/cases/standalone/common/information_schema/views.result
  • tests/cases/standalone/common/information_schema/views.sql
  • tests/cases/standalone/common/show/show_databases_tables.result
  • tests/cases/standalone/common/system/information_schema.result
  • tests/cases/standalone/common/view/create.result

…e provides

information about views in databases.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f1d312e and 1b38b6e.

Files selected for processing (9)
  • src/catalog/src/information_schema.rs (4 hunks)
  • src/catalog/src/information_schema/table_names.rs (1 hunks)
  • src/catalog/src/information_schema/views.rs (1 hunks)
  • src/common/catalog/src/consts.rs (1 hunks)
  • tests/cases/standalone/common/information_schema/views.result (1 hunks)
  • tests/cases/standalone/common/information_schema/views.sql (1 hunks)
  • tests/cases/standalone/common/show/show_databases_tables.result (3 hunks)
  • tests/cases/standalone/common/system/information_schema.result (2 hunks)
  • tests/cases/standalone/common/view/create.result (1 hunks)
Files skipped from review as they are similar to previous changes (9)
  • src/catalog/src/information_schema.rs
  • src/catalog/src/information_schema/table_names.rs
  • src/catalog/src/information_schema/views.rs
  • src/common/catalog/src/consts.rs
  • tests/cases/standalone/common/information_schema/views.result
  • tests/cases/standalone/common/information_schema/views.sql
  • tests/cases/standalone/common/show/show_databases_tables.result
  • tests/cases/standalone/common/system/information_schema.result
  • tests/cases/standalone/common/view/create.result

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

@killme2008
Copy link
Contributor

@fengjiachun @sunng87 Please take a look.

Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

LGTM

@fengjiachun
Copy link
Collaborator

@lyang24 Thank you!

@fengjiachun fengjiachun added this pull request to the merge queue Jul 14, 2024
Merged via the queue into GreptimeTeam:main with commit 15ac811 Jul 14, 2024
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants