Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug]: 通过行号以及列号获取token的Index不太对 #376

Open
openai0229 opened this issue Nov 28, 2024 · 7 comments · May be fixed by #385
Open

[Bug]: 通过行号以及列号获取token的Index不太对 #376

openai0229 opened this issue Nov 28, 2024 · 7 comments · May be fixed by #385
Labels
bug Something isn't working

Comments

@openai0229
Copy link

Version

the latest

Which SQL?

MySQL

SQL content

create table abcd ( {$空格}  
      {$光标}

)

JavaScript/TypeScript code

No response

What happened?

如果按照行列获取的话,此时光标所处的行数是第二行,但是这个token的起始行是第一行

Relevant log output

No response

@openai0229
Copy link
Author

或者说是我使用的姿势不对?

@liuxy0551
Copy link
Collaborator

liuxy0551 commented Nov 28, 2024

能否提供更多细节帮助复现该问题,比如一个最小 demo 或你使用时的代码。也可以看下这个文档:关于文本位置和文本范围,看是否有帮助,

@openai0229
Copy link
Author

create table abcd (  {$这是token的开始
        {$这是光标当前的位置}

 这是token的结束}  )

这个token从第一行开始的,一直到)这个token结束,此时这个token开始的行数其实第一行,但是我们光标在第二行,所以就不太对好像?

周一我再找找我写的demo代码,不过我的代码好像使用Java写的,我是借鉴咱这获取token的index的方法的时候发现的错误

@liuxy0551
Copy link
Collaborator

dt-sql-parser 会将换行理解为 token 未结束,也就是解析为一个 token,如文档中描述的这样:
image

我在代码中使用 getAllTokens 方法获取 sql 的 tokens 数据,拿到的数据也确实如此。光标所在的 token 从第一行开始,到第三行结束,如下图:
image

@openai0229
Copy link
Author

image
那看这个方法的话,光标和token的行数不一致,所以确实拿不到?我当时好像是复制这个方法到Java里面改了改,可能我贴错了?

@JackWang032
Copy link
Collaborator

的确是bug, 这个二分查找一开始应该是基于 Hive 去写的,hive 的语法定义中每个空白符都会被切分成单独的 token 所以没问题
image

@JackWang032 JackWang032 added the bug Something isn't working label Dec 2, 2024
@openai0229
Copy link
Author

okok

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants