summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/sql_complete_ut.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_ut.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_ut.cpp')
-rw-r--r--yql/essentials/sql/v1/complete/sql_complete_ut.cpp85
1 files changed, 27 insertions, 58 deletions
diff --git a/yql/essentials/sql/v1/complete/sql_complete_ut.cpp b/yql/essentials/sql/v1/complete/sql_complete_ut.cpp
index 5ad2f87e867..b614f561492 100644
--- a/yql/essentials/sql/v1/complete/sql_complete_ut.cpp
+++ b/yql/essentials/sql/v1/complete/sql_complete_ut.cpp
@@ -1,9 +1,8 @@
#include "sql_complete.h"
-#include <yql/essentials/sql/v1/complete/name/fallback/name_service.h>
-#include <yql/essentials/sql/v1/complete/name/static/frequency.h>
-#include <yql/essentials/sql/v1/complete/name/static/name_service.h>
-#include <yql/essentials/sql/v1/complete/name/static/ranking.h>
+#include <yql/essentials/sql/v1/complete/name/service/static/frequency.h>
+#include <yql/essentials/sql/v1/complete/name/service/static/name_service.h>
+#include <yql/essentials/sql/v1/complete/name/service/static/ranking.h>
#include <yql/essentials/sql/v1/lexer/lexer.h>
#include <yql/essentials/sql/v1/lexer/antlr4_pure/lexer.h>
@@ -24,20 +23,12 @@ public:
class TFailingNameService: public INameService {
public:
- TFuture<TNameResponse> Lookup(TNameRequest) override {
+ TFuture<TNameResponse> Lookup(TNameRequest) const override {
auto e = std::make_exception_ptr(TDummyException());
return NThreading::MakeErrorFuture<TNameResponse>(e);
}
};
-class TSilentNameService: public INameService {
-public:
- TFuture<TNameResponse> Lookup(TNameRequest) override {
- auto promise = NThreading::NewPromise<TNameResponse>();
- return promise.GetFuture();
- }
-};
-
Y_UNIT_TEST_SUITE(SqlCompleteTests) {
using ECandidateKind::FunctionName;
using ECandidateKind::HintName;
@@ -91,7 +82,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
}
TVector<TCandidate> Complete(ISqlCompletionEngine::TPtr& engine, TString sharped) {
- return engine->Complete(SharpedInput(sharped)).Candidates;
+ return engine->CompleteAsync(SharpedInput(sharped)).GetValueSync().Candidates;
}
TVector<TCandidate> CompleteTop(size_t limit, ISqlCompletionEngine::TPtr& engine, TString sharped) {
@@ -305,28 +296,28 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
TVector<TCandidate> expected = {
{Keyword, "ANSI"},
{PragmaName, "yson.CastToString"}};
- auto completion = engine->Complete({"PRAGMA "});
+ auto completion = engine->CompleteAsync({"PRAGMA "}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "");
}
{
TVector<TCandidate> expected = {
{PragmaName, "yson.CastToString"}};
- auto completion = engine->Complete({"PRAGMA yson"});
+ auto completion = engine->CompleteAsync({"PRAGMA yson"}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "yson");
}
{
TVector<TCandidate> expected = {
{PragmaName, "CastToString"}};
- auto completion = engine->Complete({"PRAGMA yson."});
+ auto completion = engine->CompleteAsync({"PRAGMA yson."}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "");
}
{
TVector<TCandidate> expected = {
{PragmaName, "CastToString"}};
- auto completion = engine->Complete({"PRAGMA yson.cast"});
+ auto completion = engine->CompleteAsync({"PRAGMA yson.cast"}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "cast");
}
@@ -489,7 +480,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
TVector<TCandidate> expected = {
{FunctionName, "DateTime::Split("},
};
- auto completion = engine->Complete({"SELECT Date"});
+ auto completion = engine->CompleteAsync({"SELECT Date"}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "Date");
}
@@ -497,14 +488,14 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
TVector<TCandidate> expected = {
{FunctionName, "Split("},
};
- auto completion = engine->Complete({"SELECT DateTime:"});
+ auto completion = engine->CompleteAsync({"SELECT DateTime:"}).GetValueSync();
UNIT_ASSERT(completion.Candidates.empty());
}
{
TVector<TCandidate> expected = {
{FunctionName, "Split("},
};
- auto completion = engine->Complete({"SELECT DateTime::"});
+ auto completion = engine->CompleteAsync({"SELECT DateTime::"}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "");
}
@@ -512,7 +503,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
TVector<TCandidate> expected = {
{FunctionName, "Split("},
};
- auto completion = engine->Complete({"SELECT DateTime::s"});
+ auto completion = engine->CompleteAsync({"SELECT DateTime::s"}).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(completion.Candidates, expected);
UNIT_ASSERT_VALUES_EQUAL(completion.CompletedToken.Content, "s");
}
@@ -606,7 +597,7 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
for (std::size_t size = 0; size <= queryUtf16.size(); ++size) {
const TWtringBuf prefixUtf16(queryUtf16, 0, size);
- auto completion = engine->Complete({TString::FromUtf16(prefixUtf16)});
+ TCompletion completion = engine->CompleteAsync({TString::FromUtf16(prefixUtf16)}).GetValueSync();
Y_DO_NOT_OPTIMIZE_AWAY(completion);
}
}
@@ -630,10 +621,11 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
wchar32 rune;
while (ptr < end) {
Y_ENSURE(ReadUTF8CharAndAdvance(rune, ptr, end) == RECODE_OK);
- auto completion = engine->Complete({
- .Text = query,
- .CursorPosition = static_cast<size_t>(std::distance(begin, ptr)),
- });
+ TCompletion completion = engine->CompleteAsync({
+ .Text = query,
+ .CursorPosition = static_cast<size_t>(std::distance(begin, ptr)),
+ })
+ .GetValueSync();
Y_DO_NOT_OPTIMIZE_AWAY(completion);
}
}
@@ -665,15 +657,15 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
Y_UNIT_TEST(InvalidCursorPosition) {
auto engine = MakeSqlCompletionEngineUT();
- UNIT_ASSERT_NO_EXCEPTION(engine->Complete({"", 0}));
- UNIT_ASSERT_EXCEPTION(engine->Complete({"", 1}), yexception);
+ UNIT_ASSERT_NO_EXCEPTION(engine->CompleteAsync({"", 0}).GetValueSync());
+ UNIT_ASSERT_EXCEPTION(engine->CompleteAsync({"", 1}).GetValueSync(), yexception);
- UNIT_ASSERT_NO_EXCEPTION(engine->Complete({"s", 0}));
- UNIT_ASSERT_NO_EXCEPTION(engine->Complete({"s", 1}));
+ UNIT_ASSERT_NO_EXCEPTION(engine->CompleteAsync({"s", 0}).GetValueSync());
+ UNIT_ASSERT_NO_EXCEPTION(engine->CompleteAsync({"s", 1}).GetValueSync());
- UNIT_ASSERT_NO_EXCEPTION(engine->Complete({"ы", 0}));
- UNIT_ASSERT_EXCEPTION(engine->Complete({"ы", 1}), yexception);
- UNIT_ASSERT_NO_EXCEPTION(engine->Complete({"ы", 2}));
+ UNIT_ASSERT_NO_EXCEPTION(engine->CompleteAsync({"ы", 0}).GetValueSync());
+ UNIT_ASSERT_EXCEPTION(engine->CompleteAsync({"ы", 1}).GetValueSync(), yexception);
+ UNIT_ASSERT_NO_EXCEPTION(engine->CompleteAsync({"ы", 2}).GetValueSync());
}
Y_UNIT_TEST(DefaultNameService) {
@@ -711,36 +703,13 @@ Y_UNIT_TEST_SUITE(SqlCompleteTests) {
}
Y_UNIT_TEST(OnFailingNameService) {
- auto service = MakeHolder<TFailingNameService>();
+ auto service = MakeIntrusive<TFailingNameService>();
auto engine = MakeSqlCompletionEngine(MakePureLexerSupplier(), std::move(service));
UNIT_ASSERT_EXCEPTION(Complete(engine, ""), TDummyException);
UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT OPTIONAL<U"), TDummyException);
UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT CAST (1 AS ").size(), TDummyException);
}
- Y_UNIT_TEST(OnSilentNameService) {
- auto silent = MakeHolder<TSilentNameService>();
- auto deadlined = MakeDeadlinedNameService(std::move(silent), TDuration::MilliSeconds(1));
-
- auto engine = MakeSqlCompletionEngine(MakePureLexerSupplier(), std::move(deadlined));
- UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT OPTIONAL<U"), NThreading::TFutureException);
- UNIT_ASSERT_EXCEPTION(Complete(engine, "SELECT OPTIONAL<"), NThreading::TFutureException);
- }
-
- Y_UNIT_TEST(OnFallbackNameService) {
- auto silent = MakeHolder<TSilentNameService>();
- auto primary = MakeDeadlinedNameService(std::move(silent), TDuration::MilliSeconds(1));
-
- auto standby = MakeStaticNameService(MakeDefaultNameSet(), MakeDefaultRanking({}));
-
- auto fallback = MakeFallbackNameService(std::move(primary), std::move(standby));
-
- auto engine = MakeSqlCompletionEngine(MakePureLexerSupplier(), std::move(fallback));
- UNIT_ASSERT_GE(Complete(engine, "SELECT CAST (1 AS U").size(), 6);
- UNIT_ASSERT_GE(Complete(engine, "SELECT CAST (1 AS ").size(), 47);
- UNIT_ASSERT_GE(Complete(engine, "SELECT ").size(), 55);
- }
-
Y_UNIT_TEST(NameNormalization) {
auto set = MakeDefaultNameSet();
auto service = MakeStaticNameService(std::move(set), MakeDefaultRanking());