Skip to content

fix drop publication if exists statement - #16449

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
YANGGMM:fix-16447
May 28, 2024
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
YANGGMM:fix-16447

Conversation

@YANGGMM

@YANGGMM YANGGMM commented May 28, 2024 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #16447

What this PR does / why we need it:

fix drop publication if exists statement


PR Type

Bug fix, Tests


Description

  • Added condition to handle IF EXISTS clause in DROP PUBLICATION statement to prevent internal errors when the publication does not exist.
  • Added tests to verify the behavior of the DROP PUBLICATION IF EXISTS statement.
  • Included setup and teardown steps in the test cases to ensure proper testing environment.

Changes walkthrough 📝

Relevant files
Bug fix
authenticate.go
Handle `IF EXISTS` clause in `DROP PUBLICATION` statement

pkg/frontend/authenticate.go

  • Added condition to handle IF EXISTS clause in DROP PUBLICATION
    statement.
  • Prevented internal error when publication does not exist and IF EXISTS
    is specified.
  • +5/-1     
    Tests
    pub_sub2.result
    Add tests for `DROP PUBLICATION IF EXISTS` statement         

    test/distributed/cases/tenant/pub_sub2.result

  • Added tests for DROP PUBLICATION IF EXISTS statement.
  • Verified behavior when publication does not exist.
  • +7/-0     
    pub_sub2.sql
    Add SQL commands to test `DROP PUBLICATION IF EXISTS`       

    test/distributed/cases/tenant/pub_sub2.sql

  • Added SQL commands to test DROP PUBLICATION IF EXISTS.
  • Included setup and teardown steps for the test.
  • +12/-1   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are localized and straightforward, affecting only a specific functionality. The added condition and the corresponding tests are clear and concise.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    Possible Bug: The else block in the modified if statement returns err which might not be initialized if execResultArrayHasData(erArray) is true. This could potentially lead to returning a nil or unrelated error. Consider returning a specific message or nil explicitly.

    🔒 Security concerns

    No

    @matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label May 28, 2024
    @mergify mergify Bot added the kind/bug Something isn't working label May 28, 2024
    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Test coverage
    Add a test case for dropping a non-existent publication without IF EXISTS to verify error handling

    Consider adding a test case for dropping a publication that does not exist without the IF
    EXISTS clause to ensure the error handling works correctly.

    test/distributed/cases/tenant/pub_sub2.result [124-125]

     drop publication if exists pub1;
     drop publication if exists pub1;
    +-- Test dropping a non-existent publication without IF EXISTS
    +drop publication pub2;
     
    Suggestion importance[1-10]: 8

    Why: Adding a test case for error handling when dropping a non-existent publication without the IF EXISTS clause is crucial for ensuring robustness and completeness of the test suite. This suggestion correctly identifies a gap in the test coverage.

    8
    Best practice
    Refactor to remove the else block by returning early for better readability

    Instead of using an else block after if !dp.IfExists, you can return early and remove the
    else block to make the code more readable.

    pkg/frontend/authenticate.go [4029-4033]

     if !dp.IfExists {
         return moerr.NewInternalError(ctx, "publication '%s' does not exist", dp.Name)
    -} else {
    -    return err
     }
    +return err
     
    Suggestion importance[1-10]: 7

    Why: The suggestion correctly identifies a way to improve code readability by removing an unnecessary else block, which is a good practice in Go for reducing nesting and improving clarity.

    7

    @mergify
    mergify Bot merged commit d50b89e into matrixorigin:main May 28, 2024
    YANGGMM added a commit to YANGGMM/matrixone that referenced this pull request May 29, 2024
    fix drop publication if exists statement
    
    
    ___
    
    ### **PR Type**
    Bug fix, Tests
    
    
    ___
    
    ### **Description**
    - Added condition to handle `IF EXISTS` clause in `DROP PUBLICATION` statement to prevent internal errors when the publication does not exist.
    - Added tests to verify the behavior of the `DROP PUBLICATION IF EXISTS` statement.
    - Included setup and teardown steps in the test cases to ensure proper testing environment.
    
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix
    </strong></td><td><table>
    <tr>
    <td>
    <details>
    <summary><strong>authenticate.go</strong><dd><code>Handle `IF EXISTS` clause in `DROP PUBLICATION` statement</code></dd></summary>
    <hr>
    
    pkg/frontend/authenticate.go
    
    <li>Added condition to handle <code>IF EXISTS</code> clause in <code>DROP PUBLICATION</code> <br>statement.<br> <li> Prevented internal error when publication does not exist and <code>IF EXISTS</code> <br>is specified.<br>
    
    
    </details>
    
    
    </td>
    <td><a href="https://github.com/matrixorigin/matrixone/pull/16449/files#diff-849f201c351210bd95807e99d1538e2602a5244b256c35e58467afe304c509e6">+5/-1</a>&nbsp; &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests
    </strong></td><td><table>
    <tr>
    <td>
    <details>
    <summary><strong>pub_sub2.result</strong><dd><code>Add tests for `DROP PUBLICATION IF EXISTS` statement</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/distributed/cases/tenant/pub_sub2.result
    
    <li>Added tests for <code>DROP PUBLICATION IF EXISTS</code> statement.<br> <li> Verified behavior when publication does not exist.<br>
    
    
    </details>
    
    
    </td>
    <td><a href="https://github.com/matrixorigin/matrixone/pull/16449/files#diff-b8d12747873e9eca46444acc746b3157e5715dcee599fa5353c036a19b550b13">+7/-0</a>&nbsp; &nbsp; &nbsp; </td>
    
    </tr>
    
    <tr>
    <td>
    <details>
    <summary><strong>pub_sub2.sql</strong><dd><code>Add SQL commands to test `DROP PUBLICATION IF EXISTS`</code>&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/distributed/cases/tenant/pub_sub2.sql
    
    <li>Added SQL commands to test <code>DROP PUBLICATION IF EXISTS</code>.<br> <li> Included setup and teardown steps for the test.<br>
    
    
    </details>
    
    
    </td>
    <td><a href="https://github.com/matrixorigin/matrixone/pull/16449/files#diff-d185c58ec352113c102571a08f1f6b69a4cb33e75b69c5d6ed221cbc47c7df91">+12/-1</a>&nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > 💡 **PR-Agent usage**:
    >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions
    
    Approved by: @daviszhen, @heni02
    @YANGGMM
    YANGGMM deleted the fix-16447 branch June 3, 2024 07:46
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    fix drop publication if exists statement
    
    
    ___
    
    ### **PR Type**
    Bug fix, Tests
    
    
    ___
    
    ### **Description**
    - Added condition to handle `IF EXISTS` clause in `DROP PUBLICATION` statement to prevent internal errors when the publication does not exist.
    - Added tests to verify the behavior of the `DROP PUBLICATION IF EXISTS` statement.
    - Included setup and teardown steps in the test cases to ensure proper testing environment.
    
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix
    </strong></td><td><table>
    <tr>
    <td>
    <details>
    <summary><strong>authenticate.go</strong><dd><code>Handle `IF EXISTS` clause in `DROP PUBLICATION` statement</code></dd></summary>
    <hr>
    
    pkg/frontend/authenticate.go
    
    <li>Added condition to handle <code>IF EXISTS</code> clause in <code>DROP PUBLICATION</code> <br>statement.<br> <li> Prevented internal error when publication does not exist and <code>IF EXISTS</code> <br>is specified.<br>
    
    
    </details>
    
    
    </td>
    <td><a href="https://github.com/matrixorigin/matrixone/pull/16449/files#diff-849f201c351210bd95807e99d1538e2602a5244b256c35e58467afe304c509e6">+5/-1</a>&nbsp; &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests
    </strong></td><td><table>
    <tr>
    <td>
    <details>
    <summary><strong>pub_sub2.result</strong><dd><code>Add tests for `DROP PUBLICATION IF EXISTS` statement</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/distributed/cases/tenant/pub_sub2.result
    
    <li>Added tests for <code>DROP PUBLICATION IF EXISTS</code> statement.<br> <li> Verified behavior when publication does not exist.<br>
    
    
    </details>
    
    
    </td>
    <td><a href="https://github.com/matrixorigin/matrixone/pull/16449/files#diff-b8d12747873e9eca46444acc746b3157e5715dcee599fa5353c036a19b550b13">+7/-0</a>&nbsp; &nbsp; &nbsp; </td>
    
    </tr>
    
    <tr>
    <td>
    <details>
    <summary><strong>pub_sub2.sql</strong><dd><code>Add SQL commands to test `DROP PUBLICATION IF EXISTS`</code>&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/distributed/cases/tenant/pub_sub2.sql
    
    <li>Added SQL commands to test <code>DROP PUBLICATION IF EXISTS</code>.<br> <li> Included setup and teardown steps for the test.<br>
    
    
    </details>
    
    
    </td>
    <td><a href="https://github.com/matrixorigin/matrixone/pull/16449/files#diff-d185c58ec352113c102571a08f1f6b69a4cb33e75b69c5d6ed221cbc47c7df91">+12/-1</a>&nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > 💡 **PR-Agent usage**:
    >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions
    
    Approved by: @daviszhen, @heni02
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Bug fix kind/bug Something isn't working Review effort [1-5]: 2 size/S Denotes a PR that changes [10,99] lines Tests

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants