-
Notifications
You must be signed in to change notification settings - Fork 90
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
Feat/flink auto complete #115
Merged
Merged
Conversation
This file contains 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
HaydenOrz
force-pushed
the
feat/flink_auto_complete
branch
3 times, most recently
from
June 7, 2023 01:59
c8edbc1
to
a996ec8
Compare
不同功能建议拆分为多个pr |
mumiao
reviewed
Jun 8, 2023
HaydenOrz
force-pushed
the
feat/flink_auto_complete
branch
2 times, most recently
from
June 8, 2023 11:15
267f6e0
to
e69e204
Compare
HaydenOrz
force-pushed
the
feat/flink_auto_complete
branch
from
June 8, 2023 13:28
4e27ab6
to
09f74c6
Compare
wewoor
approved these changes
Jun 9, 2023
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.
+1
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.
简介
Flink SQL 支持自动补全 #13
主要变更
tablePath
、tablePathCreate
、databasePath
、databasePathCreate
、catalogPath
规则,替代uid
sqlStatements
移到sqlStatement
规则下,方便做代码切割自动补全功能
自动补全功能主要依靠 antlr4-c3 实现,使用 antlr4-c3 有两个关键点
caretTokenIndex
通常来说需要补全的位置(下文中统称“插入位置”)一般用行和列来表示,所以需要把行和列转化为 Token 索引,主体实现思路是先获取到所有的token,然后寻找出插入位置对应的行和列被哪一个token包含
context
参考 antlr4-c3 文档 https://github.com/mike-lischke/antlr4-c3#constraining-the-search-space
出于性能问题考虑,我们需要找到一个子树,来减少 antlr4-c3 的解析/查找时间,这里采取的方案是先将 sql 按语句切分,并找到插入位置位于哪一个语句中, antlr4-c3 将根据这个语句对应的解析树来解析/查找
但是还需要考虑另一个问题,如果输入的 sql 文本中有语法错误,那么从语法错误的位置直到sql文本的末尾尾,都将无法构建为 ruleContext,如下图所示:
此时,采取的策略是,把 从最后一条语句开始(包括最后一条语句)直到sql文本末尾 对应的所有文本,重新解析,形成一颗新的解析树,antlr4-c3 将根据这个新的解析树来解析/查找。
另外,即使语法错误出现在 sql 文本的开头,并且 sql 文本较大,也不会太影响性能,因为此时 antlr4 的解析结果都是如上图中的散状结构,并未形成完整的树结构。