mattcasters commented on code in PR #8541:
URL: https://github.com/apache/hop/pull/8541#discussion_r4083711259
##########
core/src/main/java/org/apache/hop/core/database/SqlQueryClassifier.java:
##########
@@ -153,6 +202,36 @@ public static String statementVerb(String sql) {
return first;
}
+ /**
+ * Whether a statement changes the layout of a table or a view, which makes
any row metadata
+ * cached for that connection unreliable.
+ *
+ * @param sql one statement, comments allowed
+ * @return {@code true} for statements such as {@code ALTER TABLE ...},
{@code DROP TABLE IF
+ * EXISTS ...} or {@code CREATE OR REPLACE VIEW ...}
+ */
+ public static boolean isSchemaChange(String sql) {
+ if (Utils.isEmpty(sql)) {
+ return false;
+ }
+ int i = skipTrivia(sql, 0);
+ String keyword = keywordAt(sql, i);
+ if (keyword == null || !SCHEMA_CHANGE_VERBS.contains(keyword)) {
+ return false;
+ }
+ i = skipKeyword(sql, i);
+ while ((keyword = keywordAt(sql, i)) != null) {
+ if (SCHEMA_CHANGE_OBJECTS.contains(keyword)) {
+ return true;
+ }
+ if (!SCHEMA_CHANGE_MODIFIERS.contains(keyword)) {
Review Comment:
**[suggestion]** `isSchemaChange` returns false on the first token that is
neither an object type nor a listed modifier, so the usual MySQL/MariaDB view
statement never clears the cache.
`SHOW CREATE VIEW` / `mysqldump` emit `CREATE ALGORITHM=UNDEFINED
DEFINER=\`root\`@\`localhost\` SQL SECURITY DEFINER VIEW v AS SELECT ...`.
`ALGORITHM` is not in `SCHEMA_CHANGE_MODIFIERS`, and `keywordAt` stops at `=`,
so the next lookup is not a keyword and this returns false at the end of the
loop even if `ALGORITHM` were added to the set. The same early return misses
bare words in `SQL SECURITY DEFINER` and Oracle forms that are not in the set
(`CREATE OR REPLACE NOFORCE EDITIONABLE VIEW`, `CREATE OR REPLACE EDITIONING
VIEW`). Plain `CREATE OR REPLACE VIEW` is covered, and this is not a regression
against `startsWith("CREATE TABLE")`, but `execStatement` will keep the
previous view layout cached after these statements.
**Suggestion:** While scanning the prefix, skip a `keyword = value` clause
(value is a keyword, number, or quoted identifier; also accept MySQL ``
`user`@`host` ``) instead of aborting, and treat `ALGORITHM`, `DEFINER`, `SQL`,
`SECURITY`, `INVOKER`, `UNDEFINED`, `MERGE`, `TEMPTABLE`, `NOFORCE`, and
`EDITIONING` as modifiers. Add a test for the `SHOW CREATE VIEW` text, not only
`CREATE OR REPLACE VIEW`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]