summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/sql_complete.cpp
diff options
context:
space:
mode:
authorvityaman <[email protected]>2025-04-25 16:08:47 +0300
committerrobot-piglet <[email protected]>2025-04-25 16:30:34 +0300
commit2b59203eb9ccded916b53b3410e3f15abf4b623f (patch)
treeaa66fc9fec95a23f8f33fafacbe2bc642be1ad3f /yql/essentials/sql/v1/complete/sql_complete.cpp
parente739c22f1b227bc18a976d21555c542b4c3e7646 (diff)
YQL-19747: Refactor sql/v1/complete usage of Future and Ptr
- [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 -> LocalSyntaxAnalysis -> 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 <[email protected]> Co-authored-by: vvvv <[email protected]> commit_hash:497cc081ab78bebf7354e0acfaa418d936cc8240
Diffstat (limited to 'yql/essentials/sql/v1/complete/sql_complete.cpp')
-rw-r--r--yql/essentials/sql/v1/complete/sql_complete.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/yql/essentials/sql/v1/complete/sql_complete.cpp b/yql/essentials/sql/v1/complete/sql_complete.cpp
index 0789aa4bfc0..0ec34e212db 100644
--- a/yql/essentials/sql/v1/complete/sql_complete.cpp
+++ b/yql/essentials/sql/v1/complete/sql_complete.cpp
@@ -1,7 +1,7 @@
#include "sql_complete.h"
#include <yql/essentials/sql/v1/complete/text/word.h>
-#include <yql/essentials/sql/v1/complete/name/static/name_service.h>
+#include <yql/essentials/sql/v1/complete/name/service/static/name_service.h>
#include <yql/essentials/sql/v1/complete/syntax/local.h>
#include <yql/essentials/sql/v1/complete/syntax/format.h>
@@ -22,7 +22,11 @@ namespace NSQLComplete {
{
}
- TCompletion Complete(TCompletionInput input) {
+ TCompletion Complete(TCompletionInput input) override {
+ return CompleteAsync(std::move(input)).ExtractValueSync();
+ }
+
+ virtual NThreading::TFuture<TCompletion> CompleteAsync(TCompletionInput input) override {
if (
input.CursorPosition < input.Text.length() &&
IsUTF8ContinuationByte(input.Text.at(input.CursorPosition)) ||
@@ -37,21 +41,24 @@ namespace NSQLComplete {
TStringBuf prefix = input.Text.Head(input.CursorPosition);
TCompletedToken completedToken = GetCompletedToken(prefix);
- return {
- .CompletedToken = std::move(completedToken),
- .Candidates = GetCanidates(std::move(context), completedToken),
- };
+ return GetCandidates(std::move(context), completedToken)
+ .Apply([completedToken](NThreading::TFuture<TVector<TCandidate>> f) {
+ return TCompletion{
+ .CompletedToken = std::move(completedToken),
+ .Candidates = f.ExtractValue(),
+ };
+ });
}
private:
- TCompletedToken GetCompletedToken(TStringBuf prefix) {
+ TCompletedToken GetCompletedToken(TStringBuf prefix) const {
return {
.Content = LastWord(prefix),
.SourcePosition = LastWordIndex(prefix),
};
}
- TVector<TCandidate> GetCanidates(TLocalSyntaxContext context, const TCompletedToken& prefix) {
+ NThreading::TFuture<TVector<TCandidate>> GetCandidates(TLocalSyntaxContext context, const TCompletedToken& prefix) const {
TNameRequest request = {
.Prefix = TString(prefix.Content),
.Limit = Configuration.Limit,
@@ -84,16 +91,17 @@ namespace NSQLComplete {
}
if (request.IsEmpty()) {
- return {};
+ return NThreading::MakeFuture<TVector<TCandidate>>({});
}
- // User should prepare a robust INameService
- TNameResponse response = Names->Lookup(std::move(request)).ExtractValueSync();
-
- return Convert(std::move(response.RankedNames), std::move(context.Keywords));
+ return Names->Lookup(std::move(request))
+ .Apply([keywords = std::move(context.Keywords)](NThreading::TFuture<TNameResponse> f) {
+ TNameResponse response = f.ExtractValue();
+ return Convert(std::move(response.RankedNames), std::move(keywords));
+ });
}
- TVector<TCandidate> Convert(TVector<TGenericName> names, TLocalSyntaxContext::TKeywords keywords) {
+ static TVector<TCandidate> Convert(TVector<TGenericName> names, TLocalSyntaxContext::TKeywords keywords) {
TVector<TCandidate> candidates;
for (auto& name : names) {
candidates.emplace_back(std::visit([&](auto&& name) -> TCandidate {
@@ -130,8 +138,8 @@ namespace NSQLComplete {
TLexerSupplier lexer,
INameService::TPtr names,
ISqlCompletionEngine::TConfiguration configuration) {
- return ISqlCompletionEngine::TPtr(
- new TSqlCompletionEngine(lexer, std::move(names), std::move(configuration)));
+ return MakeHolder<TSqlCompletionEngine>(
+ lexer, std::move(names), std::move(configuration));
}
} // namespace NSQLComplete