Skip to content

Commit 4d425b0

Browse files
authored
[KQP] Analyze OLAP supported, OLTP unsupported. (#8395)
1 parent 3e2cc95 commit 4d425b0

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

ydb/core/kqp/provider/yql_kikimr_datasink.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,16 @@ class TKikimrDataSink : public TDataProviderBase
886886
return false;
887887
}
888888

889-
if (tableDesc.Metadata->Kind == EKikimrTableKind::Olap && mode != "replace" && mode != "drop" && mode != "drop_if_exists" && mode != "insert_abort" && mode != "update" && mode != "upsert" && mode != "delete" && mode != "update_on" && mode != "delete_on") {
889+
if (tableDesc.Metadata->Kind == EKikimrTableKind::Olap && mode != "replace" && mode != "drop" && mode != "drop_if_exists" && mode != "insert_abort" && mode != "update" && mode != "upsert" && mode != "delete" && mode != "update_on" && mode != "delete_on" && mode != "analyze") {
890890
ctx.AddError(TIssue(ctx.GetPosition(node->Pos()), TStringBuilder() << "Write mode '" << static_cast<TStringBuf>(mode) << "' is not supported for olap tables."));
891891
return true;
892892
}
893893

894+
if (tableDesc.Metadata->Kind == EKikimrTableKind::Datashard && mode == "analyze") {
895+
ctx.AddError(TIssue(ctx.GetPosition(node->Pos()), TStringBuilder() << static_cast<TStringBuf>(mode) << " is not supported for oltp tables."));
896+
return true;
897+
}
898+
894899
return false;
895900
}
896901

ydb/core/kqp/ut/query/kqp_analyze_ut.cpp

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,52 @@ using namespace NYdb::NTable;
1616

1717
Y_UNIT_TEST_SUITE(KqpAnalyze) {
1818

19-
void CreateTable(NStat::TTestEnv& env, const TString& databaseName, const TString& tableName) {
20-
TTableClient client(env.GetDriver());
21-
auto session = client.CreateSession().GetValueSync().GetSession();
22-
23-
auto fullTableName = Sprintf("Root/%s/%s", databaseName.c_str(), tableName.c_str());
24-
auto result = session.ExecuteSchemeQuery(Sprintf(R"(
25-
CREATE TABLE `%s` (
26-
Key Uint64 NOT NULL,
27-
Value String,
28-
PRIMARY KEY (Key)
29-
)
30-
)", fullTableName.c_str())).GetValueSync();
31-
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
32-
33-
TValueBuilder rows;
34-
rows.BeginList();
35-
for (size_t i = 0; i < 1000; ++i) {
36-
auto key = TValueBuilder().Uint64(i).Build();
37-
auto value = TValueBuilder().OptionalString("Hello, world!").Build();
38-
39-
rows.AddListItem();
40-
rows.BeginStruct();
41-
rows.AddMember("Key", key);
42-
rows.AddMember("Value", value);
43-
rows.EndStruct();
44-
}
45-
rows.EndList();
46-
47-
result = client.BulkUpsert(fullTableName, rows.Build()).GetValueSync();
48-
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
49-
}
50-
5119
using namespace NStat;
5220

53-
Y_UNIT_TEST(AnalyzeDatashardTable) {
21+
Y_UNIT_TEST_TWIN(AnalyzeTable, ColumnStore) {
5422
TTestEnv env(1, 1, 1, true);
5523
CreateDatabase(env, "Database");
5624

5725
TTableClient client(env.GetDriver());
5826
auto session = client.CreateSession().GetValueSync().GetSession();
5927

60-
auto result = session.ExecuteSchemeQuery(
61-
Sprintf(R"(
28+
TString createTable = Sprintf(R"(
6229
CREATE TABLE `%s` (
6330
Key Uint64 NOT NULL,
6431
Value String,
6532
PRIMARY KEY (Key)
6633
)
67-
)", "Root/Database/Table")
68-
).GetValueSync();
34+
)", "Root/Database/Table");
35+
if (ColumnStore) {
36+
createTable +=
37+
R"(
38+
PARTITION BY HASH(Key)
39+
WITH (
40+
STORE = COLUMN,
41+
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 16
42+
)
43+
)";
44+
}
45+
46+
auto result = session.ExecuteSchemeQuery(createTable).GetValueSync();
6947
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
7048

49+
if (ColumnStore) {
50+
result = session.ExecuteSchemeQuery(
51+
Sprintf(R"(
52+
ALTER OBJECT `%s` (TYPE TABLE)
53+
SET (
54+
ACTION=UPSERT_INDEX,
55+
NAME=cms_value,
56+
TYPE=COUNT_MIN_SKETCH,
57+
FEATURES=`{"column_names" : ['Value']}`
58+
);
59+
)", "Root/Database/Table"
60+
)
61+
).GetValueSync();
62+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
63+
}
64+
7165
TValueBuilder rows;
7266
rows.BeginList();
7367
for (size_t i = 0; i < 1500; ++i) {
@@ -88,7 +82,15 @@ Y_UNIT_TEST(AnalyzeDatashardTable) {
8882
result = session.ExecuteSchemeQuery(
8983
Sprintf(R"(ANALYZE `Root/%s/%s`)", "Database", "Table")
9084
).GetValueSync();
91-
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
85+
86+
if (ColumnStore) {
87+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
88+
} else {
89+
UNIT_ASSERT(!result.IsSuccess());
90+
auto issues = result.GetIssues().ToString();
91+
UNIT_ASSERT_C(issues.find("analyze is not supported for oltp tables.") != TString::npos, issues);
92+
return;
93+
}
9294

9395
auto& runtime = *env.GetServer().GetRuntime();
9496
ui64 saTabletId;

0 commit comments

Comments
 (0)