-
Notifications
You must be signed in to change notification settings - Fork 101
feat: complete after error syntax #334
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: next
Are you sure you want to change the base?
Conversation
f6b1a3d
to
56e4d0d
Compare
过程中遇到的问题尝试过以独立语句开头的关键词(如:
REVOKE SELECT (co_name) ON table_name |FROM PUBLIC;
GRANT SELECT (column_name) ON table_name TO |role_specification;
MERGE INTO wines w USING wine_stock_changes s ON s.winename = w.winename
WHEN NOT MATCHED AND stock_delta > 0
THEN INSERT (col_name) |VALUES(s.winename, s.stock_delta);
WITH with_query_name (col_name) AS (SELECT id FROM table_expression) SEARCH DEPTH
FIRST BY column_name SET column_name
CYCLE col_name SET col_name
USING col_name SELECT|; 上述语法中的
SELECT c.customer_id, c.customer_name, c.email, total_orders.total_amount, total_orders.order_count
FROM customers c
JOIN (
SELECT o.customer_id, SUM(o.total_amount) AS total_amount, COUNT(o.order_id) AS order_count
FROM orders o
WHERE o.order_date BETWEEN '2024-08-01' AND '2024-08-31'
GROUP BY o.customer_id
HAVING COUNT(o.order_id) > 5
) AS total_orders
ON c.customer_id = total_orders.customer_id
WHERE| c.status = 'active'
ORDER BY total_orders.total_amount DESC; 上述语句中存在多层级的子查询,此时如果在子查询后出现光标,且光标位置和子查询不是同一层级,那么会出现较为明显的切分错误,结果如下,连子查询的括号都不完整,更不谈正确进行自动补全了。 SELECT o.customer_id, SUM(o.total_amount) AS total_amount, COUNT(o.order_id) AS order_count
FROM orders o
WHERE o.order_date BETWEEN '2024-08-01' AND '2024-08-31'
GROUP BY o.customer_id
HAVING COUNT(o.order_id) > 5
) AS total_orders
ON c.customer_id = total_orders.customer_id
WHERE| 因此,放弃通过以独立语句开头的关键词进行切分,仅通过分隔符进行切分(通常是 |
b610cb3
to
d841e3c
Compare
944a97f
to
417c063
Compare
已发 beta 包在离线中验证效果符合预期, |
9ce9722
to
6cebe8e
Compare
6cebe8e
to
c031b24
Compare
c031b24
to
f2b72ed
Compare
f2b72ed
to
de3b760
Compare
所以左右边界都是采取分号来做划分吗? |
有冲突 |
和 #378 部分设计重合,待重新验证功能 |
@JackWang032 将 getMinimumParserInfo 方法的内容拆分为 getMinimumInputInfo 和 parserWithNewInput,作用分别是 获取最小解析边界 和 重新解析新的 inputSlice。便于后续通过 具体改动在 bd83147 |
src/parser/common/basicSQL.ts
Outdated
* @param input source string | ||
* @returns parse and parserTree | ||
*/ | ||
private parserWithNewInput(inputSlice: string) { |
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.
这个方法对标的是createParserWithCache
,我觉得方法名可以改下,其次只返回parserIns是不是更好点?由有具体方法决定何时去生成解析树
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.
这个方法对标的是
createParserWithCache
,我觉得方法名可以改下,其次只返回parserIns是不是更好点?由有具体方法决定何时去生成解析树
方法名的话有什么建议吗,这个方法更多的是 createParserWithCache 和 parseWithCache 的结合,所以同时返回了 parserIns 和 parserTree,我觉得还有 parserWithInput、parserWithInputSlice 这些可选
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.
我倾向于直接使用已有的createParser
,两者功能重叠了
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.
createParser
推了一个新的 commit,使用已有的 createParser 方法获取 parserIns 即可
+1 |
在错误语法的 SQL 后进行自动补全
现状举例
预期举例
改动思路
提到的左边界和右边界可以参考 dt-sql-parser #231 的描述。
通过分隔符进行切分(通常是
;
),这里依旧保留现状寻找最小合适范围的策略,并在此策略上继续优化,借助两种方式进一步缩小解析范围。实现效果