-
Notifications
You must be signed in to change notification settings - Fork 73
Implement Selective Export of Specific Tables from Database : #13 export few tables #45
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
base: development
Are you sure you want to change the base?
Implement Selective Export of Specific Tables from Database : #13 export few tables #45
Conversation
Development v1.2.1
development to master
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.
There was a problem hiding this 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.
| List<String> specificTableList = new ArrayList<>(); | ||
| if (!specificTables.isEmpty()) { | ||
| specificTableList = Arrays.stream(specificTables.split(",")).map(String::trim).toList(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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)) { |
There was a problem hiding this comment.
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
…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.
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
Example Usage
Users can now set the property for specific tables as follows:
@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.