Skip to content

Commit b26f7d1

Browse files
stebloevqyryq
authored andcommitted
Add n-gram kqp tests (ydb-platform#28636)
1 parent 5ee43a6 commit b26f7d1

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

ydb/core/kqp/ut/indexes/kqp_indexes_fulltext_ut.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ void AddIndex(NQuery::TQueryClient& db) {
6161
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
6262
}
6363

64+
void AddIndexNGram(NQuery::TQueryClient& db, const size_t nGramMinLength = 3, const size_t nGramMaxLength = 3, const bool edgeNGram = false) {
65+
const TString query = Sprintf(R"sql(
66+
ALTER TABLE `/Root/Texts` ADD INDEX fulltext_idx
67+
GLOBAL USING fulltext
68+
ON (Text)
69+
WITH (
70+
layout=flat,
71+
tokenizer=standard,
72+
use_filter_lowercase=true,
73+
use_filter_ngram=%d,
74+
use_filter_edge_ngram=%d,
75+
filter_ngram_min_length=%d,
76+
filter_ngram_max_length=%d
77+
);
78+
)sql", !edgeNGram, edgeNGram, nGramMinLength, nGramMaxLength);
79+
auto result = db.ExecuteQuery(query, NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
80+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
81+
}
82+
6483
void AddIndexCovered(NQuery::TQueryClient& db) {
6584
TString query = R"sql(
6685
ALTER TABLE `/Root/Texts` ADD INDEX fulltext_idx
@@ -131,6 +150,80 @@ Y_UNIT_TEST(AddIndexCovered) {
131150
])", NYdb::FormatResultSetYson(index));
132151
}
133152

153+
Y_UNIT_TEST(AddIndexNGram) {
154+
auto kikimr = Kikimr();
155+
auto db = kikimr.GetQueryClient();
156+
157+
CreateTexts(db);
158+
UpsertTexts(db);
159+
AddIndexNGram(db);
160+
161+
const auto index = ReadIndex(db);
162+
163+
CompareYson(R"([
164+
[[100u];"all"];
165+
[[200u];"all"];
166+
[[100u];"als"];
167+
[[100u];"ani"];
168+
[[100u];"ase"];
169+
[[200u];"ase"];
170+
[[100u];"ats"];
171+
[[200u];"ats"];
172+
[[300u];"ats"];
173+
[[100u];"cat"];
174+
[[200u];"cat"];
175+
[[300u];"cat"];
176+
[[100u];"cha"];
177+
[[200u];"cha"];
178+
[[200u];"dog"];
179+
[[400u];"dog"];
180+
[[400u];"fox"];
181+
[[100u];"has"];
182+
[[200u];"has"];
183+
[[100u];"ima"];
184+
[[300u];"lov"];
185+
[[400u];"lov"];
186+
[[100u];"mal"];
187+
[[200u];"mal"];
188+
[[100u];"nim"];
189+
[[200u];"ogs"];
190+
[[400u];"ogs"];
191+
[[300u];"ove"];
192+
[[400u];"ove"];
193+
[[400u];"oxe"];
194+
[[100u];"sma"];
195+
[[200u];"sma"];
196+
[[400u];"xes"]
197+
])", NYdb::FormatResultSetYson(index));
198+
}
199+
200+
Y_UNIT_TEST(AddIndexEdgeNGram) {
201+
auto kikimr = Kikimr();
202+
auto db = kikimr.GetQueryClient();
203+
204+
CreateTexts(db);
205+
UpsertTexts(db);
206+
AddIndexNGram(db, 3, 3, true);
207+
208+
const auto index = ReadIndex(db);
209+
Cerr << NYdb::FormatResultSetYson(index) << Endl;
210+
CompareYson(R"([
211+
[[100u];"ani"];
212+
[[100u];"cat"];
213+
[[200u];"cat"];
214+
[[300u];"cat"];
215+
[[100u];"cha"];
216+
[[200u];"cha"];
217+
[[200u];"dog"];
218+
[[400u];"dog"];
219+
[[400u];"fox"];
220+
[[300u];"lov"];
221+
[[400u];"lov"];
222+
[[100u];"sma"];
223+
[[200u];"sma"]
224+
])", NYdb::FormatResultSetYson(index));
225+
}
226+
134227
Y_UNIT_TEST(InsertRow) {
135228
auto kikimr = Kikimr();
136229
auto db = kikimr.GetQueryClient();

0 commit comments

Comments
 (0)