-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Change system table check logic #36502
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: master
Are you sure you want to change the base?
Change system table check logic #36502
Conversation
There are two points I’m not fully satisfied with:
I verified it with tests. I also checked Firebird manually — everything works as intended. Looking forward to your review and suggestions for improvement. |
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.
Finally, I would like to remind you that to determine whether a table is a true system table, you also need to look at the path to which the table belongs (db - schema - table). If the path belongs to a user-defined schema, perhaps this table should be identified as a non-system table.
* Dialect system table manager. | ||
*/ | ||
@SingletonSPI | ||
public interface DialectSystemTableManager extends DatabaseTypedSPI { |
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.
Do you think DialectSystemTableDetector
is better? The meaning of Manager is broader, and we only want to add a class to detect whether a table is a system table.
@@ -124,6 +126,7 @@ private Collection<String> loadTableNames(final Connection connection, final Str | |||
} | |||
|
|||
private boolean isSystemTable(final String table) { | |||
return table.contains("$") || table.contains("/") || table.contains("##"); | |||
return DatabaseTypedSPILoader.findService(DialectSystemTableManager.class, databaseType) |
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.
Maybe you can add a engine class to hide the details of SPI loading so that other scenarios can directly call the Engine. You can refer to the logic of SQLRouteEngine.
* System table manager. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class SystemTableManager { |
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.
SystemTableDetector maybe better.
try (Stream<String> resourceNameStream = ClasspathResourceDirectoryReader.read("schema")) { | ||
resourceNames = resourceNameStream.filter(each -> each.endsWith(".yaml")).collect(Collectors.toList()); | ||
} | ||
DATABASE_TYPE_SCHEMA_TABLE_MAP = resourceNames.stream().map(resourceName -> resourceName.split("/")).filter(each -> each.length == 4) |
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.
Please put 4 costant to the left hand of each.length == 4
*/ | ||
// TODO check if this function is needed, since it's only used in SimpleTableSegmentBinder and could be replaced by SystemTableManager.isSystemTable(databaseType). (issues/36462) | ||
public static boolean isSystemTable(final String schema, final String tableName) { | ||
for (Map.Entry<String, Map<String, Collection<String>>> entry : DATABASE_TYPE_SCHEMA_TABLE_MAP.entrySet()) { |
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.
Please use Entry
to replace Map.Entry
* @param tableName table name | ||
* @return whether current table is system table or not | ||
*/ | ||
public static boolean isSystemTable(final String databaseType, final String schema, final String tableName) { |
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.
These logics seem very common. As long as the system table is configured under resource, they can work normally?
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.
If this is the case, perhaps we can refactor it without SPI, as long as we ensure that the database without configuring the system table YAML file can go to the default logic.
static void setUp() throws Exception { | ||
originalClassLoader = Thread.currentThread().getContextClassLoader(); | ||
URL[] urls = { | ||
Paths.get("../dialect/mysql/src/main/resources").toUri().toURL(), |
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.
You can write some FIXTUREs and test configurations specifically for testing to test the logic of SystemTableManager without actually loading the dialect module.
public final class FirebirdSystemTableManager implements DialectSystemTableManager { | ||
|
||
@Override | ||
public String getDatabaseType() { |
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.
It seems that the implementation classes of these SPIs are empty. Based on this, I suggest removing the SPI interface and implementation class and encapsulating these logics through a SystemTableDetector.
Hi, sorry for the late reply — I’m working on another task in parallel. I’ve reviewed your comments and will apply the fixes. Thanks! |
eliminate redundant isSystemTable overload, remove unused getTables method, rework SPI from Manager to Rule
I hope I’ve finished and done everything correctly. I think my problem was also that I just copied the old implementation from I created a new SPI — I’m looking forward to your next comments, and I hope I didn’t miss anything. It was interesting for me to dig into the core. |
I see that the build is failing, but I noticed the same error appears in other PRs as well. I’ll wait until the issue is resolved on your side and then rerun the CI. |
Fixes #36462
Changes proposed in this pull request:
Before committing this PR, I'm sure that I have checked the following options:
./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e
.