Skip to content

Conversation

@Josel099
Copy link

@Josel099 Josel099 commented Oct 30, 2024

Overview

This pull request introduces a new feature that allows users to export specific tables from the database by specifying their names as a comma-separated list.

Changes Made

  • Added a property key for specifying specific tables to export.
  • Implemented logic to generate SQL statements for the specified tables.
  • Updated documentation to include instructions on how to use the new feature.

Example Usage

Users can now set the property for specific tables as follows:

properties.setProperty(MysqlExportService.SPECIFIC_TABLES_FOR_EXPORT, "table_1,table_2,table_3");

@SeunMatt Could you check if this approach is okay with you? If so, I'd also like to contribute to the section on importing specific tables from the dump file.

SeunMatt and others added 6 commits April 3, 2021 11:16
Added support for exporting only specified tables from the database. The implementation checks for a list of specific tables to be exported and generates the corresponding SQL statements for table creation and data insertion.
Copy link
Owner

@SeunMatt SeunMatt left a comment

Choose a reason for hiding this comment

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

Kindly rebase your clone with the master branch so you can have the automated test code. Kindly add a test case for your new feature implementation as well.

Thank you for your contribution. I have made some suggestions and I am looking forward to the revised PR.

Comment on lines 357 to 360
List<String> specificTableList = new ArrayList<>();
if (!specificTables.isEmpty()) {
specificTableList = Arrays.stream(specificTables.split(",")).map(String::trim).toList();
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
List<String> specificTableList = new ArrayList<>();
if (!specificTables.isEmpty()) {
specificTableList = Arrays.stream(specificTables.split(",")).map(String::trim).toList();
}
List<String> specificTableList = new ArrayList<>();
if (!specificTables.isEmpty()) {
specificTableList = Arrays.stream(specificTables.split(",")).map(String::trim).toList();
}

We can replace the above snippet with a ternary operator. As in:

List<String> specificTableList = !specificTables.isEmpty()
                                 ? Arrays.stream(specificTables.split(",")).map(String::trim).collect(Collectors.toList())
                                 : Collections.emptyList();


// Determine if the specific table list is empty or includes the current table name
// If so, generate SQL statements for table creation and data insertion
if (specificTableList.isEmpty() || specificTableList.contains(specificTableName)) {
Copy link
Owner

Choose a reason for hiding this comment

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

This logic is better placed in the function com.smattme.MysqlBaseService#getAllTablesAndViews. Since the function is the one responsible for determining which tables will be added to list of tables for processing or not.

ResultSet rs;
        rs = stmt.executeQuery("SHOW TABLE STATUS FROM `" + database + "`;");
        while ( rs.next() ) {
           String name = rs.getString("Name");
           //TODO check if the table/view name is in the specified list OR the list is empty before adding them to the final list
            String comment = rs.getString("Comment");
            if("VIEW".equals(comment)) {
                views.add(name);
            }
            else {
                tables.add(name);
            }
        }

This means you'll need to modify the signature of the com.smattme.MysqlBaseService#getAllTablesAndViews to expect a Properties object. Then, in it, you'll construct a table whitelist and use it in the while loop for building the table.

It would be even more awesome if it is possible to add the whitelist to the SHOW TABLE STATUS FROM database query directly.

Looking forward to your update

Josel099 and others added 3 commits February 15, 2025 22:45
…ovided list

- Moved filtering logic from exportToSql into getAllTablesAndViews.
- Now, if a non-empty specificTableList is provided, only tables/views in that list are returned.
- Preserved default behavior: if specificTableList is empty, all tables/views are included.
…level

- Modify query to use a WHERE clause with an IN operator for filtering specific tables.
- Remove in-code filtering logic; rely on the database to return only the desired results.
-update readme.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants