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

add test for restore view table and fk table (#1.2-dev) #16432

Merged
merged 9 commits into from
May 30, 2024

Conversation

YANGGMM
Copy link
Contributor

@YANGGMM YANGGMM commented May 28, 2024

add test for restore view table

Approved by: @heni02, @daviszhen

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #16311

What this PR does / why we need it:

add test for restore view table and fk table

@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label May 28, 2024
@mergify mergify bot requested a review from sukki37 May 28, 2024 02:16
@mergify mergify bot added the kind/test-ci label May 28, 2024
@matrix-meow
Copy link
Contributor

@YANGGMM Thanks for your contributions!

Here are review comments for file pkg/frontend/snapshot.go:

Pull Request Review:

Title and Body:

The title of the pull request is clear and concise, indicating the purpose of the changes being made. The body provides additional context about the PR, mentioning the specific issue it addresses and the approval status. It also states the type of PR and the reason for the changes. Overall, the title and body are informative and well-structured.

Changes in pkg/frontend/snapshot.go:

  1. Logging Information:
    • The changes involve adding logging statements to provide more information during the execution of the code.
    • The added log statements use getLogger().Info to log messages related to table information retrieval.
    • The first change adds a log message with the SQL query used to get table information.
    • The second change updates a log message to include the table name being processed.

Suggestions for Improvement:

  1. Logging Enhancement:

    • While logging additional information can be helpful for debugging and monitoring, it's important to ensure that sensitive data or SQL queries are not exposed in the logs, especially in production environments.
    • Consider sanitizing or obfuscating any sensitive information before logging it.
    • Use appropriate log levels based on the importance of the information being logged. For example, debug logs can be used for detailed information, while info logs should be reserved for essential messages.
  2. Code Optimization:

    • The changes made in the pull request seem straightforward and focused on logging improvements.
    • Ensure that the logging messages added are clear, concise, and provide meaningful insights for developers and operators.
    • Review the necessity of logging each specific detail to avoid cluttering the logs with excessive information.
  3. Security Considerations:

    • Be cautious when logging SQL queries, as they may contain sensitive data or expose potential vulnerabilities if not handled properly.
    • Avoid logging sensitive information like database credentials, user inputs, or any data that could compromise the security of the system.
    • Consider implementing log masking or filtering mechanisms to prevent the exposure of sensitive data in logs.

Overall, the changes in the pull request are focused on enhancing logging for table information retrieval. It is essential to ensure that the logging modifications adhere to best practices, especially concerning security and data protection. Additionally, optimizing the logging messages for clarity and relevance can improve the overall maintainability of the codebase.

Here are review comments for file test/distributed/cases/result_count/result_count.sql:

Pull Request Review:

Title:

The title of the pull request is clear and concise, indicating that tests are being added for restoring view tables and foreign key tables.

Body:

The body of the pull request provides additional context by specifying the approval and the type of PR. It also mentions the related issue number and explains the purpose of the PR, which is to add tests for restoring view tables and foreign key tables.

Changes:

  1. The changes made in the result_count.sql file involve removing a specific SQL query related to issue [Tech Request]: add ut test for create account in on transaction #13064. The query was removed without any replacement or explanation in the diff.

Suggestions for Improvement:

  1. Provide Explanation for Removal: It is important to provide a clear explanation in the pull request description or comments in the code for why a particular query related to issue [Tech Request]: add ut test for create account in on transaction #13064 is being removed. This helps in understanding the context and reasons behind the change.

  2. Optimization: Consider optimizing the test cases by ensuring that the tests cover a comprehensive range of scenarios related to restoring view tables and foreign key tables. This can help in improving the effectiveness of the tests.

  3. Security Concern: While the removal of the query related to issue [Tech Request]: add ut test for create account in on transaction #13064 may be valid, it is crucial to ensure that the removal does not introduce any security vulnerabilities or regressions. Perform thorough testing to validate the impact of this change on the overall functionality.

  4. Documentation: Update any relevant documentation or comments to reflect the changes made in the test cases. This helps in maintaining a clear and up-to-date codebase for future reference.

By addressing the suggestions mentioned above, the pull request can be enhanced in terms of clarity, security, and overall code quality.

Here are review comments for file test/distributed/cases/snapshot/snapshot_restore_to_table_view.sql:

Pull Request Review:

Title:

The title of the pull request is clear and specific, indicating that tests are being added for restoring view tables and foreign key tables.

Body:

The body of the pull request provides essential information such as the type of PR, the issue it fixes, and the purpose of the changes made. It also lists the approvers for the PR.

Changes:

  1. The changes in the snapshot_restore_to_table_view.sql file involve adding test cases for restoring view tables and foreign key tables in different databases (School, University, EducationSystem).
  2. Tables, views, and data are created and inserted into the databases to simulate a scenario where data is being restored from a snapshot.
  3. Various views like StudentCourses, HighGradeStudents, CourseAverageGrades, etc., are created to demonstrate the data relationships.
  4. The script includes the creation of snapshots, dropping databases, and restoring data from a snapshot to verify the restoration process.

Feedback and Suggestions:

  1. Security Concern - Foreign Key Constraints:

    • When dropping databases and restoring data, ensure that foreign key constraints are properly handled to avoid data integrity issues. It's important to consider the order of dropping and restoring tables with foreign key relationships to prevent constraint violations.
    • Suggestion: Add checks or disable foreign key constraints before dropping tables and enable them after data restoration to maintain data consistency.
  2. Code Organization and Reusability:

    • The script contains repetitive code for creating similar views in different databases. This can lead to maintenance issues and code duplication.
    • Suggestion: Consider refactoring the script to extract common view creation logic into functions or stored procedures to improve code reusability and maintainability.
  3. Data Cleanup:

    • After running the tests, there is no explicit data cleanup step to remove the test data created during the script execution.
    • Suggestion: Include a data cleanup section at the end of the script to drop temporary tables, views, and other objects created during testing to keep the environment clean.
  4. Testing Scenarios:

    • While the script covers a wide range of testing scenarios, it's essential to ensure that edge cases and error conditions are also tested to validate the robustness of the restoration process.
    • Suggestion: Add additional test cases to cover scenarios like partial data restoration, invalid data formats, or unexpected errors during the restoration process.
  5. Documentation:

    • Providing inline comments or a separate documentation section within the script can help in understanding the purpose of each test case and the expected outcomes.
    • Suggestion: Add comments to explain the rationale behind each test case and the expected results to improve code readability and maintainability.
  6. Optimization:

    • The script includes multiple SELECT * statements which can impact performance, especially when dealing with large datasets.
    • Suggestion: Consider selecting only the necessary columns instead of using SELECT * to optimize query performance and reduce unnecessary data retrieval.

By addressing the security concerns, improving code organization, adding data cleanup steps, enhancing testing scenarios, documenting

@YANGGMM
Copy link
Contributor Author

YANGGMM commented May 28, 2024

需要等 @ck89119 的pr cherry-pick 到1.2-dev

@mergify mergify bot merged commit 7d957a2 into matrixorigin:1.2-dev May 30, 2024
17 of 18 checks passed
@YANGGMM YANGGMM deleted the fix-fk-view-1.2-dev branch June 3, 2024 07:46
@aylei aylei mentioned this pull request Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/test-ci size/XXL Denotes a PR that changes 2000+ lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants