-
Notifications
You must be signed in to change notification settings - Fork 107
feat: match empty column when in entityCollecting context #457
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
Draft
JackWang032
wants to merge
15
commits into
next
Choose a base branch
from
feat/emptyColumn
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* feat: support queryResult and derived table entities collecting * feat: support query result and derived table entity collecting * test: enhance hive and spark entity collect test case * fix: remove _ctx and add tokenIndex into position * fix: rename declareType COMMON to LITERAL * fix: optimize entity collector and update grammar * test: add derived table and query result entities test case * fix: remove isCaretInDerivedTableStmt and set default isAccessible to null * fix: update _caretStmt docs * test: add isAccessible test case * fix: skip _caretStmt ts check * docs: update README to include additional entity information * test: fix create view test case * fix: import from error sql module * test: update entity collection tests * fix: remove unused type
Collaborator
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

当输入的SQL不完整时,特别是没有输入字段或者输入了表名
table1.<empty>时,会导致语法解析错误恢复失败,最终的语法解析树无法作为实体收集的参考模板, 实体收集失败。如在MySQL中输入

SELECT t1. FROM t1,没法收集到任何实体,那么就没法去提供对应的补全我们已在 grammar 中对
columnName添加了{this.shouldMatchEmpty()}?语义谓词分支的支持,使在实体收集时能够匹配空字段,但这仅能覆盖一小部分情况,当where、order by、join on等场景时(会匹配 expression )无效,并且输入点时也无法命中。语义谓词:语义谓词是 ANTLR4 中将语法规则与自定义代码逻辑结合的核心机制,用于在语法解析过程中动态控制规则的匹配行为
一般来说 grammar 中将字段拆分成了
columnName与columnNamePath两个规则,columnName在select item中匹配,columnNamePath在表达式中匹配。目前有两种方法利用语义谓词解决该问题:
方案一
为
columnNamePath也添加空字段的语义谓词分支,但该方式会导致比较多的语法校验单测失败(语义谓词分支会影响预测,即使该语义谓词分支没有匹配上),影响范围也没法确定。目前PGSQL尝试使用了该方式。方案二
最小化改动原则(当前尝试的方式),在具体规则(where、 order by、 join on等)后添加语义谓词,基本不会导致现有的单测报错。
如果采用方案一,其表现效果很好,但需要深入分析下语义谓词对antlr4 预测、错误恢复等阶段的影响,避免其影响到非实体收集上下文时的功能。
如果采用方案二,需要处理很多不同 expression下的场景,如需要处理
join ... on t1.id = t2.id中 比较操作符=可能会嵌套递归的情况使用语义谓词后语法解析树基本能保证完整

Preview地址 https://jackwang032.github.io/monaco-sql-languages/