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: support show views statement #4360

Merged
merged 1 commit into from
Jul 15, 2024
Merged

Conversation

lyang24
Copy link
Contributor

@lyang24 lyang24 commented Jul 14, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#4338

What's changed and what's your intention?

!!! DO NOT LEAVE THIS BLOCK EMPTY !!!

Please explain IN DETAIL what the changes are in this PR and why they are needed:

  • Summarize your change (mandatory)
  • 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

    • Added support for SHOW VIEWS SQL statements to display views in the database.
    • Users can now display views within a database using SHOW VIEWS and SHOW VIEWS IN <database> commands.
  • Tests

    • Added test cases for SHOW VIEWS and SHOW VIEWS IN <database> statements to ensure correctness.

Copy link
Contributor

coderabbitai bot commented Jul 14, 2024

Walkthrough

The changes introduce support for SHOW VIEWS SQL statements, allowing users to list all views in the database. This includes updates to SQL parsing, permission checking, statement execution, and adding new methods to handle the SHOW VIEWS functionality. Tests for these features have also been included to ensure correctness.

Changes

Files Changed Summary
src/frontend/src/instance.rs Added handling for Statement::ShowViews(stmt) in check_permission function.
src/operator/src/statement.rs Added show_views method in StatementExecutor implementation.
src/operator/src/statement/show.rs Added pub(super) async fn show_views(&self, stmt: ShowViews, query_ctx: QueryContextRef).
src/query/src/sql.rs Added ShowViews support, including imports, constants, and show_views function.
src/sql/src/parsers/show_parser.rs Added ShowViews to imports and parse_show_views function; added tests for SHOW VIEWS.
src/sql/src/statements/show.rs Introduced ShowViews struct and Display implementation; added test cases.
src/sql/src/statements/statement.rs Added ShowViews to the Statement enum and updated Display implementation.
tests/cases/standalone/common/view/view.result Added results for SHOW VIEWS statements in SQL script.
tests/cases/standalone/common/view/view.sql Added SHOW VIEWS statements after creating and dropping views.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant SQL Parser
    participant Statement Executor
    participant Database

    User->>CLI: Input SHOW VIEWS;
    CLI->>SQL Parser: Parse SHOW VIEWS statement
    SQL Parser->>Statement Executor: Create ShowViews statement
    Statement Executor->>Database: Query views information
    Database-->>Statement Executor: Return views list
    Statement Executor-->>CLI: Display views list
    CLI-->>User: Show views list
Loading

Possibly related issues

Poem

In the realm of views, a tale unfolds,
SQL commands, in stories told,
A SHOW VIEWS magic now in sight,
Revealing schemes in pure delight.
With parser's might and executor's grace,
Database secrets we now embrace.
🐇✨


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 14, 2024
@lyang24 lyang24 changed the title (wip) feat: support show views feat: support show views statement Jul 14, 2024
src/query/src/sql.rs Outdated Show resolved Hide resolved
@lyang24 lyang24 marked this pull request as ready for review July 14, 2024 02:23
@lyang24 lyang24 requested review from evenyag and a team as code owners July 14, 2024 02:23
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: 1

Outside diff range, codebase verification and nitpick comments (1)
src/query/src/sql.rs (1)

746-746: Consider replacing hardcoded string.

It would be great if we can replace the hardcoded string "VIEW" with a constant or an enum value for better maintainability.

const VIEW_TYPE: &str = "VIEW";
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5a17322 and 031cedd.

Files selected for processing (9)
  • src/frontend/src/instance.rs (1 hunks)
  • src/operator/src/statement.rs (1 hunks)
  • src/operator/src/statement/show.rs (2 hunks)
  • src/query/src/sql.rs (4 hunks)
  • src/sql/src/parsers/show_parser.rs (4 hunks)
  • src/sql/src/statements/show.rs (2 hunks)
  • src/sql/src/statements/statement.rs (3 hunks)
  • tests/cases/standalone/common/view/view.result (2 hunks)
  • tests/cases/standalone/common/view/view.sql (2 hunks)
Files skipped from review due to trivial changes (2)
  • tests/cases/standalone/common/view/view.result
  • tests/cases/standalone/common/view/view.sql
Additional comments not posted (11)
src/sql/src/statements/statement.rs (2)

94-95: Addition of ShowViews variant to Statement enum looks good.

The ShowViews variant is correctly added to the Statement enum.


137-137: Addition of ShowViews match arm to Display implementation looks good.

The ShowViews match arm is correctly added to the Display implementation.

src/operator/src/statement/show.rs (1)

155-164: Addition of show_views method to StatementExecutor looks good.

The show_views method is correctly added and follows the pattern of other show_* methods.

src/sql/src/statements/show.rs (2)

203-208: Addition of ShowViews struct looks good.

The ShowViews struct is correctly added with fields kind and database.


210-220: Addition of Display implementation for ShowViews looks good.

The Display implementation for ShowViews is correctly added.

src/operator/src/statement.rs (1)

139-140: Addition of ShowViews match arm to execute_sql method looks good.

The ShowViews match arm is correctly added to the execute_sql method.

src/frontend/src/instance.rs (1)

509-511: LGTM!

The addition of handling for Statement::ShowViews in the check_permission function is consistent with the handling for other similar statements.

src/sql/src/parsers/show_parser.rs (3)

47-48: LGTM!

The addition of handling for SHOW VIEWS statements in the parse_show function is consistent with the handling for other similar statements.


436-462: LGTM!

The new parse_show_views function correctly parses SHOW VIEWS statements and is consistent with the parsing of other similar statements.


977-1008: LGTM!

The new test cases comprehensively cover the parsing of SHOW VIEWS statements.

src/query/src/sql.rs (1)

729-764: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that the new show_views function is correctly used and tested in the codebase.

Verification successful

The show_views function is correctly used and tested in the codebase.

  • src/operator/src/statement.rs - The function is invoked here.
  • src/operator/src/statement/show.rs - Another function calls show_views here.
  • Related test functions and parsing functions are present in src/sql/src/statements/show.rs and src/sql/src/parsers/show_parser.rs.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new `show_views` function in the codebase.

# Test: Search for the function usage. Expect: Occurrences of the new function usage.
rg --type rust -A 5 $'show_views'

Length of output: 4008

src/query/src/sql.rs Show resolved Hide resolved
Copy link

codecov bot commented Jul 14, 2024

Codecov Report

Attention: Patch coverage is 68.03279% with 39 lines in your changes missing coverage. Please review.

Project coverage is 84.87%. Comparing base (15ac811) to head (b4d974c).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4360      +/-   ##
==========================================
- Coverage   85.15%   84.87%   -0.29%     
==========================================
  Files        1063     1063              
  Lines      189987   190116     +129     
==========================================
- Hits       161782   161358     -424     
- Misses      28205    28758     +553     

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 031cedd and 483cc1f.

Files selected for processing (9)
  • src/frontend/src/instance.rs (1 hunks)
  • src/operator/src/statement.rs (1 hunks)
  • src/operator/src/statement/show.rs (2 hunks)
  • src/query/src/sql.rs (3 hunks)
  • src/sql/src/parsers/show_parser.rs (4 hunks)
  • src/sql/src/statements/show.rs (2 hunks)
  • src/sql/src/statements/statement.rs (3 hunks)
  • tests/cases/standalone/common/view/view.result (2 hunks)
  • tests/cases/standalone/common/view/view.sql (2 hunks)
Files skipped from review due to trivial changes (1)
  • src/query/src/sql.rs
Files skipped from review as they are similar to previous changes (6)
  • src/frontend/src/instance.rs
  • src/operator/src/statement.rs
  • src/operator/src/statement/show.rs
  • src/sql/src/statements/show.rs
  • src/sql/src/statements/statement.rs
  • tests/cases/standalone/common/view/view.sql
Additional context used
Learnings (1)
tests/cases/standalone/common/view/view.result (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 (5)
tests/cases/standalone/common/view/view.result (2)

55-62: LGTM! Added SHOW VIEWS statement and its result are correct.

The SHOW VIEWS statement correctly lists the views in the database, and the expected result format is accurate.


92-96: LGTM! Added SHOW VIEWS statement and its result are correct.

The SHOW VIEWS statement correctly lists the views in the database, and the expected result format is accurate.

src/sql/src/parsers/show_parser.rs (3)

436-456: LGTM! Added parse_show_views function is correct.

The parse_show_views function correctly parses the SHOW VIEWS statement and returns the corresponding Statement.


971-985: LGTM! Added test_show_views function is correct.

The test_show_views function correctly tests the parsing of the SHOW VIEWS statement.


987-1002: LGTM! Added test_show_views_in_db function is correct.

The test_show_views_in_db function correctly tests the parsing of the SHOW VIEWS IN <database> statement.

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.

Good job!

src/query/src/sql.rs Outdated Show resolved Hide resolved
src/query/src/sql.rs Outdated Show resolved Hide resolved
src/query/src/sql.rs Outdated Show resolved Hide resolved
src/sql/src/statements/show.rs Outdated Show resolved Hide resolved
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 483cc1f and b4d974c.

Files selected for processing (9)
  • src/frontend/src/instance.rs (1 hunks)
  • src/operator/src/statement.rs (1 hunks)
  • src/operator/src/statement/show.rs (2 hunks)
  • src/query/src/sql.rs (4 hunks)
  • src/sql/src/parsers/show_parser.rs (4 hunks)
  • src/sql/src/statements/show.rs (2 hunks)
  • src/sql/src/statements/statement.rs (3 hunks)
  • tests/cases/standalone/common/view/view.result (2 hunks)
  • tests/cases/standalone/common/view/view.sql (2 hunks)
Files skipped from review due to trivial changes (1)
  • tests/cases/standalone/common/view/view.result
Files skipped from review as they are similar to previous changes (7)
  • src/frontend/src/instance.rs
  • src/operator/src/statement.rs
  • src/operator/src/statement/show.rs
  • src/sql/src/parsers/show_parser.rs
  • src/sql/src/statements/show.rs
  • src/sql/src/statements/statement.rs
  • tests/cases/standalone/common/view/view.sql
Additional comments not posted (2)
src/query/src/sql.rs (2)

73-73: LGTM!

The addition of the constant VIEWS_COLUMN aligns with the existing pattern for other columns.


730-764: LGTM! But add documentation.

The implementation of the show_views function is well-structured and consistent with other show functions.

Ensure that the new show_views function is documented, explaining its purpose and usage.

@killme2008 killme2008 mentioned this pull request Jul 15, 2024
13 tasks
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

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 fengjiachun added this pull request to the merge queue Jul 15, 2024
Merged via the queue into GreptimeTeam:main with commit 9501318 Jul 15, 2024
55 checks passed
@killme2008 killme2008 mentioned this pull request Jul 18, 2024
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