Skip to content

Commit

Permalink
Merge 90cd01f into c63da82
Browse files Browse the repository at this point in the history
  • Loading branch information
azevaykin authored Jul 14, 2024
2 parents c63da82 + 90cd01f commit eaaa71f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
7 changes: 3 additions & 4 deletions ydb/library/yql/sql/v1/SQLv1.g.in
Original file line number Diff line number Diff line change
Expand Up @@ -720,14 +720,13 @@ table_index: INDEX an_id table_index_type
ON LPAREN an_id_schema (COMMA an_id_schema)* RPAREN
(COVER LPAREN an_id_schema (COMMA an_id_schema)* RPAREN)?;

table_index_type:
global_index
| local_index
;
table_index_type: (global_index | local_index) (USING index_subtype)?;

global_index: GLOBAL UNIQUE? (SYNC | ASYNC)?;
local_index: LOCAL;

index_subtype: an_id;

changefeed: CHANGEFEED an_id WITH LPAREN changefeed_settings RPAREN;
changefeed_settings: changefeed_settings_entry (COMMA changefeed_settings_entry)*;
changefeed_settings_entry: an_id EQUALS changefeed_setting_value;
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/sql/v1/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ namespace NSQLTranslationV1 {
GlobalSync,
GlobalAsync,
GlobalSyncUnique,
GlobalVectorKmeansTree
};

TIndexDescription(const TIdentifier& name, EType type = EType::GlobalSync)
Expand Down
2 changes: 2 additions & 0 deletions ydb/library/yql/sql/v1/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ static INode::TPtr CreateIndexType(TIndexDescription::EType type, const INode& n
return node.Q("asyncGlobal");
case TIndexDescription::EType::GlobalSyncUnique:
return node.Q("syncGlobalUnique");
case TIndexDescription::EType::GlobalVectorKmeansTree:
return node.Q("globalVectorKmeansTree");
}
}

Expand Down
27 changes: 22 additions & 5 deletions ydb/library/yql/sql/v1/sql_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,11 @@ bool PureColumnOrNamedListStr(const TRule_pure_column_or_named_list& node, TTran
bool CreateTableIndex(const TRule_table_index& node, TTranslation& ctx, TVector<TIndexDescription>& indexes) {
indexes.emplace_back(IdEx(node.GetRule_an_id2(), ctx));

const auto& indexType = node.GetRule_table_index_type3();
const auto& indexType = node.GetRule_table_index_type3().GetBlock1();
switch (indexType.Alt_case()) {
case TRule_table_index_type::kAltTableIndexType1: {
auto globalIndex = indexType.GetAlt_table_index_type1().GetRule_global_index1();
// "GLOBAL"
case TRule_table_index_type_TBlock1::kAlt1: {
auto globalIndex = indexType.GetAlt1().GetRule_global_index1();
bool uniqIndex = false;
if (globalIndex.HasBlock2()) {
uniqIndex = true;
Expand All @@ -658,13 +659,29 @@ bool CreateTableIndex(const TRule_table_index& node, TTranslation& ctx, TVector<
}
}
break;
case TRule_table_index_type::kAltTableIndexType2:
// "LOCAL"
case TRule_table_index_type_TBlock1::kAlt2:
ctx.AltNotImplemented("local", indexType);
return false;
case TRule_table_index_type::ALT_NOT_SET:
case TRule_table_index_type_TBlock1::ALT_NOT_SET:
Y_ABORT("You should change implementation according to grammar changes");
}

if (node.GetRule_table_index_type3().HasBlock2()) {
const TString subType = to_upper(IdEx(node.GetRule_table_index_type3().GetBlock2().GetRule_index_subtype2().GetRule_an_id1(), ctx).Name) ;
if (subType == "VECTOR_KMEANS_TREE") {
if (indexes.back().Type != TIndexDescription::EType::GlobalSync) {
ctx.Error() << subType << " index can only be GLOBAL [SYNC]";
return false;
}

indexes.back().Type = TIndexDescription::EType::GlobalVectorKmeansTree;
} else {
ctx.Error() << subType << " index subtype is not supported";
return false;
}
}

if (node.HasBlock4()) {
ctx.AltNotImplemented("with", indexType);
return false;
Expand Down
12 changes: 11 additions & 1 deletion ydb/library/yql/sql/v1/sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,17 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {

Y_UNIT_TEST(AlterTableAddIndexWithIsNotSupported) {
ExpectFailWithError("USE plato; ALTER TABLE table ADD INDEX idx LOCAL WITH (a=b, c=d, e=f) ON (col)",
"<main>:1:40: Error: local: alternative is not implemented yet: 725:7: local_index\n");
"<main>:1:40: Error: local: alternative is not implemented yet: 723:35: local_index\n");
}

Y_UNIT_TEST(AlterTableAddVectorIndex) {
const auto result = SqlToYql("USE plato; ALTER TABLE table ADD INDEX idx GLOBAL USING vector_kmeans_tree ON (col) COVER (col)");
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
}

Y_UNIT_TEST(AlterTableAddIndexWithUnknownSubtype) {
ExpectFailWithError("USE plato; ALTER TABLE table ADD INDEX idx GLOBAL USING unknown ON (col)",
"<main>:1:57: Error: UNKNOWN index subtype is not supported\n");
}

Y_UNIT_TEST(AlterTableAlterIndexSetPartitioningIsCorrect) {
Expand Down

0 comments on commit eaaa71f

Please sign in to comment.