<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ydb/yql/essentials/sql/v1/complete/syntax/local.cpp, branch CLI_2.21.0</title>
<subtitle>Mirror of YDB github repos</subtitle>
<id>https://code.mastervirt.ru/ydb/atom?h=CLI_2.21.0</id>
<link rel='self' href='https://code.mastervirt.ru/ydb/atom?h=CLI_2.21.0'/>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/'/>
<updated>2025-05-20T10:23:38Z</updated>
<entry>
<title>YQL-19747: Recover from unclosed ID_QUOTED</title>
<updated>2025-05-20T10:23:38Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-05-20T10:09:37Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=ae913bccb4fd8a8ba5f536c8afe622e2ad229fbc'/>
<id>urn:sha1:ae913bccb4fd8a8ba5f536c8afe622e2ad229fbc</id>
<content type='text'>
The simplest solution actually is an SQL injection.

---

- Related to `YQL-19747`
- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/ydb-platform/ydb/pull/18146
- Related to https://github.com/vityaman/ydb/issues/46

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1283
commit_hash:7043e7cdd1e0d378926783d31cf5f8e055393aaa
</content>
</entry>
<entry>
<title>YQL-19747: Fix unquoted object path completion</title>
<updated>2025-05-19T14:51:48Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-05-19T14:36:10Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=f16ede95953f8cdd44e3b762b175bd22e106bb5c'/>
<id>urn:sha1:f16ede95953f8cdd44e3b762b175bd22e106bb5c</id>
<content type='text'>
On `SELECT * FROM pn` it completed to `SELECT * FROM ppnv1`, but expected ``` SELECT * FROM `pnv1` ```.

---

- Related to `YQL-19747`
- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/vityaman/ydb/issues/44
- Related to https://github.com/ydb-platform/ydb/pull/18146

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1280
commit_hash:e937239fae7bf609bde6358b9b27c2b504c8ba32
</content>
</entry>
<entry>
<title>YQL-19747: Fix caret token position</title>
<updated>2025-05-12T18:00:51Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-05-12T17:47:40Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=b336ad5ec16dd1f541c55b7944fc9e6b5bba57a2'/>
<id>urn:sha1:b336ad5ec16dd1f541c55b7944fc9e6b5bba57a2</id>
<content type='text'>
Outcomes:
1. Need to think more deeply about library interfaces. If you think that an interface is redundant, think again, because author knows a usecase that you do not imagine.
2. If you are lazy now to implement something robustly, think twice because the day will come and this code
will fire.

The problem was that on input ``` ... cluster.`/yql/t#` ``` C3 receives only a prefix ``` ... cluster.`/yql/t ``` and a token stream produced was incorrect and therefore completions too.

---

- Related to `YQL-19747`
- Related to https://github.com/ytsaurus/ytsaurus/pull/1257
- Related to https://github.com/ydb-platform/ydb/issues/9056

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1271
commit_hash:8bf5f2683c9e41963003da923f255f63b898aac5
</content>
</entry>
<entry>
<title>YQL-19747 Complete folder, table and cluster names</title>
<updated>2025-05-06T13:04:08Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-05-06T12:49:02Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=9c3fdca51d8ae892c5ad8f6ef92df73fafc09e28'/>
<id>urn:sha1:9c3fdca51d8ae892c5ad8f6ef92df73fafc09e28</id>
<content type='text'>
---

- Related to `YQL-19747`
- On top of https://github.com/ytsaurus/ytsaurus/pull/1253
- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/vityaman/ydb/issues/14
- Related to https://github.com/vityaman/ydb/issues/35
- Related to https://github.com/vityaman/ydb/issues/40

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1257
commit_hash:0b842abb27184c88b8177beeea29fb1ea86b7a04
</content>
</entry>
<entry>
<title>YQL-19747 Use TMaybe</title>
<updated>2025-04-28T10:52:54Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-04-28T10:29:56Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=3dfd8d9b20fe8902588dc35edb24423fbf165917'/>
<id>urn:sha1:3dfd8d9b20fe8902588dc35edb24423fbf165917</id>
<content type='text'>
Just replaced `std::optional` usages with `TMaybe` to prevent this refactoring noise in future PRs.

---

- Related to `YQL-19747`
- Related to https://github.com/ydb-platform/ydb/issues/9056

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1247
commit_hash:dca8a6849e5ba9cb614d8350996f9423a1dc2373
</content>
</entry>
<entry>
<title>YQL-19747: Refactor sql/v1/complete usage of Future and Ptr</title>
<updated>2025-04-25T13:30:34Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-04-25T13:08:47Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=2b59203eb9ccded916b53b3410e3f15abf4b623f'/>
<id>urn:sha1:2b59203eb9ccded916b53b3410e3f15abf4b623f</id>
<content type='text'>
- [x] Chained futures, add `CompleteAsync` method (then will migrate the YDB CLI on it).
- [x] Removed deadlined and fallback NameService as unused
- [x] Annotate thread-safe methods with `const` and use `AtomicSharedPtr` for them.
- [x] Move `name` to `name/service` with backward compatibility with the YDB CLI.

---

`CompletionEngine` is left thread-unsafe because of the dependency chain `CompletionEngine -&gt; LocalSyntaxAnalysis -&gt; C3Engine` which is thread-unsafe, but readonly indexed data structures such as `Ranking` and `NameService` are annotated with const and distributed via shared pointers.

I removed deadlined and fallback name services because the first is stupid the second is ahead of its time and is better to be added later to keep interfaces as minimal as possible.

---

The migration on async complete plan:
1. Introduce CompleteAsync
2. Migrate clients on CompleteAsync
3. Make Complete to return Future
4. Migrate clients on Complete
5. Remove CompleteAsync

---

- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/vityaman/ydb/issues/33
- Related to https://github.com/vityaman/ydb/issues/31

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1241

Co-authored-by: vvvv &lt;vvvv@yandex-team.com&gt;
Co-authored-by: vvvv &lt;vvvv@yandex-team.com&gt;
commit_hash:497cc081ab78bebf7354e0acfaa418d936cc8240
</content>
</entry>
<entry>
<title>YQL-19747 Detect a token at the caret position</title>
<updated>2025-04-23T12:27:38Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-04-23T12:04:48Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=c222f6f103376934dd705e16bf9a3bad66e44365'/>
<id>urn:sha1:c222f6f103376934dd705e16bf9a3bad66e44365</id>
<content type='text'>
When I tried to implement a folder and object names completion at `ID_QUOTED` I faced with a problem, that I actually can't detect, that cursor is at `ID_QUOTED` token because `TCompletionInput::Text` it was cut until the `TCompletionInput::CursorPosition`, therefore at input ``` SELECT * FROM `#` ``` prefix was ``` SELECT * FROM `# ``` and then lexer failed.

While we actually want tokenize the whole current statement, `C3` still needs to receive a prefix as input. I tried to tokenize the whole statement and then on input `SELECT Optional&lt;#&gt;` got nothing because `&lt;&gt;` is solid token in the `SQL`. The only way to fix it I found is to cut a query to prefix until the cursor position.

BTW, current implementation is not so efficient as we tokenize the input multiple times. Especially `SplitQueryToStatemnts` seems heavy. In future we anyway will parse the whole input so will need to design APIs to receive ready token streams to do statements splitting, for example, just not to do the work twice.

![image](https://github.com/user-attachments/assets/114804d3-f311-4a46-be84-8ed4650bc9dd)

So I introduce you the following changes

- [x] Select the whole current statement, not just prefix.
- [x] Find the token at caret and output no candidates when caret is at `STRING_VALUE`, `DIGIGTS` and so on.
- [x] Change `C3` wrapper interface to take `TCompletionInput` to hide an implementation detail that it runs on cut prefix.
- [x] `#` annotated queries in unit tests.
- [x] Detect `CaretTokenPosition` -- if is it enclosed with a token or between two.
- [x] Ensure that `maxErrors` in `ILexer::Tokenize` is positive. Just a tiny bugfix.

---

- Related to https://github.com/ytsaurus/ytsaurus/pull/1209
- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/vityaman/ydb/issues/14

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1225
commit_hash:a434b9888ec8a7356247d63d9f1420e256ae4fca
</content>
</entry>
<entry>
<title>YQL-19747 Rank keywords just by plain usages</title>
<updated>2025-04-14T10:40:02Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-04-14T10:06:15Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=14005fcfba8efa6918e54d823bff6780d9922f8f'/>
<id>urn:sha1:14005fcfba8efa6918e54d823bff6780d9922f8f</id>
<content type='text'>
- [x] Rank keywords just by plain usages
- [x] `LocalSyntaxAnalysis` now returns a mapping `:: Keyword -&gt; [Following Keywords]`.
- [x] Extracted keyword sequence formatting from `syntax/local` to `syntax/format`.
- [x] Extracted token display logic from `syntax/local` to `antlr4/vocabulary` as it is ANTLR dependent.

---

Example

```python
$ ./yql_complete &lt;&lt;&lt; "select "
[Keyword] CAST(
[Keyword] NULL
[Keyword] NOT
[FunctionName] If(
[FunctionName] Yson::ConvertToString(
[FunctionName] Count(
[FunctionName] Sum(
[FunctionName] Unwrap(
[FunctionName] Coalesce(
[Keyword] DISTINCT
[Keyword] ALL
[Keyword] CASE
[FunctionName] Max(
[Keyword] FALSE
[FunctionName] Some(
```

---

- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/vityaman/ydb/issues/17

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1197
commit_hash:f42cb4aaffe6de7c9137069c4d9c635ee110a805
</content>
</entry>
<entry>
<title>YQL-19747 Complete select and insert hints</title>
<updated>2025-04-09T15:12:05Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-04-09T14:57:35Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=394fee4aa8d48e58cf82c72bcb9dda0a5dd50190'/>
<id>urn:sha1:394fee4aa8d48e58cf82c72bcb9dda0a5dd50190</id>
<content type='text'>
- Related to https://github.com/ydb-platform/ydb/issues/9056
- Related to https://github.com/vityaman/ydb/issues/19

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1189
commit_hash:7f1cb1dcf0617aa2c94c3f2188fc9bd481380252
</content>
</entry>
<entry>
<title>YQL-19747 Complete after PRAGMA and multi-token names</title>
<updated>2025-04-08T13:26:47Z</updated>
<author>
<name>vityaman</name>
<email>vityaman.dev@yandex.ru</email>
</author>
<published>2025-04-08T13:11:56Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=2f90258cf6f1625ba0c99f6f37b6c9f336590534'/>
<id>urn:sha1:2f90258cf6f1625ba0c99f6f37b6c9f336590534</id>
<content type='text'>
- [x] Complete after PRAGMA
- [x] Complete multi-token names correctly, for example, `yt.` returns only `DisableStrict`, not `yt.DisableStrict` and `DateTime::` returns `Split`, not `DateTime::Split`.

I tried to implement it using `CompletedToken` edition, but not all completion environments support candidates with various `contextLen` (`Replxx` does not). So I decided that completions should rewrite only the current token, not sequences. For example, on `DateTime::Spl` rewrite only `Spl`. It makes sense as multi-token names have some namespace separated by a punctuation, so used types only namespace and gets names inside of it.

---

Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1181
commit_hash:9d8967ac43b9348f6dbb53837d92a9dcc9b51f48
</content>
</entry>
</feed>
