linyimin0812 / mybatis-sql-viewer

convert mybatis xml to sql statement; mybatis param mock; sql specification check; sql index check; sql execution; sql stress; mybatis sql scan
MIT License
135 stars 27 forks source link

sql 解析出错 #6

Open watchingfun opened 1 year ago

watchingfun commented 1 year ago

如图 image

Validate sql statement error.
java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.SetOperationList cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.SetOperationList and net.sf.jsqlparser.statement.select.PlainSelect are in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @1cb83097)
    at io.github.linyimin.plugin.sql.checker.rule.CheckRuleAbstract.checkFromItem(CheckRuleAbstract.java:121)
    at io.github.linyimin.plugin.sql.checker.rule.CheckRuleAbstract.checkJoin(CheckRuleAbstract.java:110)
    at io.github.linyimin.plugin.sql.checker.rule.CheckRuleAbstract.checkPlainSelect(CheckRuleAbstract.java:54)
    at io.github.linyimin.plugin.sql.checker.rule.SelectCheckRuleAbstract.check(SelectCheckRuleAbstract.java:31)
    at io.github.linyimin.plugin.sql.checker.Checker.check(Checker.java:28)
    at io.github.linyimin.plugin.ui.SqlTabbedPane.checkRules(SqlTabbedPane.java:341)
    at io.github.linyimin.plugin.ui.SqlTabbedPane.validateSql(SqlTabbedPane.java:312)
    at io.github.linyimin.plugin.ui.SqlTabbedPane.access$400(SqlTabbedPane.java:48)
    at io.github.linyimin.plugin.ui.SqlTabbedPane$3.changedUpdate(SqlTabbedPane.java:181)
    at java.desktop/javax.swing.text.AbstractDocument.fireChangedUpdate(AbstractDocument.java:255)
    at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.updateLastTokensBelow(RSyntaxDocument.java:618)
    at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.fireInsertUpdate(RSyntaxDocument.java:174)
    at java.desktop/javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:780)
    at java.desktop/javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:739)
    at java.desktop/javax.swing.text.PlainDocument.insertString(PlainDocument.java:131)
    at io.github.linyimin.plugin.ui.CustomTextField$MaxLengthDocument.insertString(CustomTextField.java:80)
    at java.desktop/javax.swing.text.AbstractDocument.replace(AbstractDocument.java:698)
    at java.desktop/javax.swing.text.JTextComponent.setText(JTextComponent.java:1729)
    at io.github.linyimin.plugin.ui.SqlTabbedPane$4.lambda$run$1(SqlTabbedPane.java:269)
    at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
    at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
    at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
    at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:456)
    at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:79)
    at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:122)
    at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:41)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:788)
    at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
    at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:731)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:758)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:667)
    at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$7(IdeEventQueue.kt:571)
    at com.intellij.openapi.application.impl.ApplicationImpl.withoutImplicitRead(ApplicationImpl.java:1446)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:571)
    at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343)
    at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:995)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
    at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:995)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

xml中有<if test="_databaseId=='mysql'">这种表达式,不知道有影响不 statement的sql 没有完全转换成可执行的: statement中还带有where substr(vy.trade_date, 1, 7) = #{param.currentMonth, jdbcType=VARCHAR}这种片段

watchingfun commented 1 year ago

我大概猜到原因了,xml中有<if test="_databaseId=='mysql'">这种表达式,表达式里包裹了一个left join子查询,其他部分有使用子查询的表的别名,_databaseId这个参数我没法传入,生成的sql就没有带这个子查询,导致sql解析失败,可否参数里能额外传参,因为有的参数不是mapper里传入的