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

fix: updated the regex expression to correctly identify the table nam… #35361

Conversation

Naveen-Goud
Copy link
Contributor

@Naveen-Goud Naveen-Goud commented Aug 2, 2024

Description

When the user tries to add a postgres datasource and add any query, if the table name has hyphens in it, then quotes get assigned to first word after the schema and the dot. For example, public."counter"-with-db
The quotes should be applied to the whole table name. For example: public."counter-with-db"

Fixes #10631
Fixes #30692

changes in PR:

1.updated the regec expression to idetify the table name properly with table name consists of hypens.

2.added a test case for this scenario.

snapshots:
before:

Screenshot from 2024-07-30 17-15-27

After:

Screenshot from 2024-08-01 10-46-53

Hi @ajinkyakulkarni @rohan-arthur @Nikhil-Nandagopal ,Please review this PR.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced handling of table names in the Postgres plugin to support a wider variety of characters, including hyphens and special characters.
    • Introduced multiple new database tables for improved testing coverage.
  • Bug Fixes

    • Adjusted table name processing to correctly format names containing a broader range of characters.
  • Tests

    • Added new tests to verify the structure and integrity of tables with various naming conventions.
    • Expanded existing tests to accommodate additional table structures.

Copy link
Contributor

coderabbitai bot commented Aug 2, 2024

Walkthrough

The changes implemented in the PostgresPlugin involve modifying the regex pattern used for quoting table names to support hyphens and other characters. Additionally, the PostgresPluginTest class has been enhanced with new test cases and updated setup procedures to rigorously test these changes against diverse naming conventions, thereby improving the overall robustness of the plugin.

Changes

File Change Summary
.../PostgresPlugin.java Updated quotedTableName regex in getStructure to allow hyphens and additional characters in table names.
.../PostgresPluginTest.java Expanded setup to create new test tables and added tests for structures containing special characters, underscores, hyphens, and dots.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PostgresPlugin
    participant Database

    Client->>PostgresPlugin: Request table structure
    PostgresPlugin->>Database: Query for table structure
    Database-->>PostgresPlugin: Return table structure
    PostgresPlugin-->>Client: Return quoted table name and structure
Loading
sequenceDiagram
    participant TestRunner
    participant PostgresPluginTest
    participant Database

    TestRunner->>PostgresPluginTest: Run setup
    PostgresPluginTest->>Database: Create new test tables
    Database-->>PostgresPluginTest: Confirm table creation
    TestRunner->>PostgresPluginTest: Execute test cases for various naming conventions
    PostgresPluginTest->>Database: Validate table structures
    Database-->>PostgresPluginTest: Return structure data
    PostgresPluginTest-->>TestRunner: Return test results
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly quote database table names with hyphens (#10631, #30692)
Ensure table previews function correctly for tables with hyphens (#30692)
Validate that quoting is applied to the entire table name instead of part (#10631)

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 Configuration 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.

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 a0f2ee1 and 6e69460.

Files selected for processing (2)
  • app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (1 hunks)
  • app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (3 hunks)
Additional comments not posted (3)
app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (1)

887-887: Verify the updated regex pattern for correctness.

The regex pattern has been updated to \\.(.+) to capture any character sequence following the period. This change should correctly handle table names with hyphens. Ensure that this pattern does not introduce any unexpected behavior with other table name formats.

app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (2)

715-781: LGTM! Ensure comprehensive test coverage.

The new test method testStructure_containing_hyphen correctly verifies the structure of the testing-table-data table.

However, ensure that the test coverage is comprehensive and includes edge cases.


195-202: LGTM! Ensure the new table creation is verified.

The SQL command for creating the testing-table-data table appears correct.

However, ensure that the new table creation is verified in subsequent tests.

@Naveen-Goud
Copy link
Contributor Author

Hii @rohan-arthur @ajinkyakulkarni ,Could you please assign the reviewer for it.

@Naveen-Goud
Copy link
Contributor Author

Hii @IAmAnubhavSaini , I have updated with proper regex to identify the table names with hypens .I have also cross checked with , Its working as expected.Please review it.

thank you.

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 6e69460 and 419ffdb.

Files selected for processing (1)
  • app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (1 hunks)
Additional comments not posted (1)
app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (1)

887-887: LGTM! Verify the impact of the regex change across the codebase.

The regex pattern has been correctly updated to handle table names with hyphens. Ensure that this change does not introduce any unintended side effects in other parts of the codebase that might rely on the previous pattern.

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Aug 20, 2024
@Nikhil-Nandagopal Nikhil-Nandagopal requested review from NilanshBansal and removed request for IAmAnubhavSaini August 20, 2024 16:53
@NilanshBansal
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10494572254.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35361.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-35361.dp.appsmith.com

@NilanshBansal
Copy link
Contributor

@Naveen-Goud this regex does not work if the table name has dots in it.
image

@NilanshBansal
Copy link
Contributor

@Naveen-Goud this regex may work out better for the table names containing dots as well.

final String quotedTableName = table.getName().replaceFirst("\\.(.+)", ".\"$1\"");
Any reason you chose to change this in the latest commit?

@NilanshBansal
Copy link
Contributor

NilanshBansal commented Aug 22, 2024

@Naveen-Goud the server-unit-test PostgresPluginTest#testStructure is failing, please check. Also, please pull the latest release and run mvn spotless:apply before committing the changes as the server spotless check is also failing
image

@Naveen-Goud
Copy link
Contributor Author

Hii @NilanshBansal , I have updated the regex in latest commit because we want to accept the hypes(-) only , when we are using dot(.) in regex , its accepting all the special characters in table names .

if you want me to use the prev regex ,it allows all the special chars like $,#,@,*,& in table names , If you are okay with this ,I will updated it to prev regex.

My thought was to not allow special characters other than hypens(-),underscore(_)

also we cannot have mutliple dot in table names, it leads nested structure if we use mutliple dots in table names.

@github-actions github-actions bot removed the Stale label Aug 22, 2024
@NilanshBansal
Copy link
Contributor

NilanshBansal commented Aug 23, 2024

Hii @NilanshBansal , I have updated the regex in latest commit because we want to accept the hypes(-) only , when we are using dot(.) in regex , its accepting all the special characters in table names .

if you want me to use the prev regex ,it allows all the special chars like $,#,@,*,& in table names , If you are okay with this ,I will updated it to prev regex.

My thought was to not allow special characters other than hypens(-),underscore(_)

also we cannot have mutliple dot in table names, it leads nested structure if we use mutliple dots in table names.

@Naveen-Goud yes we should update the regex to this to allow special characters also as supabase also supports these naming for their tables.
image

image

Please make the relevant changes along with the suggestions in comment 1, comment 2 and comment 3

Let me know once you have done the changes will re-review the PR

@Naveen-Goud
Copy link
Contributor Author

Hii @NilanshBansal , I have updated the regex and the test case as you mentioned in the above comments.Can review now.

thank you.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 419ffdb and 1c8dd4a.

Files selected for processing (2)
  • app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (1 hunks)
  • app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (5 hunks)
Additional comments not posted (4)
app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (1)

887-887: Evaluate the implications of the updated regex pattern.

The regex pattern in quotedTableName was changed from \\.(\\w+) to \\.(.+), which broadens the matching criteria. While this change allows for more complex table names, it may also permit unintended characters. Ensure that this change does not introduce security vulnerabilities or incorrect behavior by allowing special characters that should be restricted.

Consider adding unit tests to cover edge cases with special characters and validate the expected behavior.

app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (3)

352-414: LGTM! Comprehensive test for special characters in table names.

The test case effectively verifies the structure and templates for a table with special characters.


416-478: LGTM! Thorough test for underscores and hyphens in table names.

The test case effectively verifies the structure and templates for a table with underscores and hyphens.


480-542: LGTM! Comprehensive test for dots in table names.

The test case effectively verifies the structure and templates for a table with dots.

@NilanshBansal
Copy link
Contributor

Thanks @Naveen-Goud for the changes. I have pulled the latest changes and triggered tests on the shadow PR here: #35832
If all the tests pass, we should be good to go ahead and merge this PR in.

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 1c8dd4a and fafbe3d.

Files selected for processing (1)
  • app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (5 hunks)
Additional comments not posted (4)
app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (4)

352-414: Comprehensive test for special characters in table names.

The test method testStructure_containing_special_chars effectively verifies the structure of a table with special characters in its name. The assertions cover the table's existence, columns, primary keys, and SQL templates.


416-478: Comprehensive test for underscores and hyphens in table names.

The test method testStructure_containing_underscore_and_hyphen effectively verifies the structure of a table with underscores and hyphens in its name. The assertions cover the table's existence, columns, primary keys, and SQL templates.


480-542: Comprehensive test for dots in table names.

The test method testStructure_containing_dots effectively verifies the structure of a table with dots in its name. The assertions cover the table's existence, columns, primary keys, and SQL templates.


941-1006: Comprehensive test for hyphens in table names.

The test method testStructure_containing_hyphen effectively verifies the structure of a table with hyphens in its name. The assertions cover the table's existence, columns, primary keys, and SQL templates.

@NilanshBansal
Copy link
Contributor

@Naveen-Goud tests are failing on the shadow PR, please check and fix.
#35832 (comment)

@Naveen-Goud
Copy link
Contributor Author

Hii @NilanshBansal , The test failing are related to cypress which are for frontend. My changes are in backend only and added Junit tests.

thank you.

@NilanshBansal
Copy link
Contributor

@Naveen-Goud the backend changes can also trigger failure for certain cypress tests. Can you please confirm once if these are related to your PR or not?

@Naveen-Goud
Copy link
Contributor Author

@NilanshBansal , those tests are not related to my PR.
thank you.

@NilanshBansal
Copy link
Contributor

@Naveen-Goud thanks for confirming, I have re-triggered tests on the shadow PR
#35832 (comment)

@NilanshBansal
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10576066486.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35361.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-35361.dp.appsmith.com

@abhvsn abhvsn merged commit cbd7ccc into appsmithorg:release Aug 27, 2024
16 of 17 checks passed
@NilanshBansal
Copy link
Contributor

@Naveen-Goud thank you for your patience, this PR has been merged! We appreciate your contribution towards making Appsmith better ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants