Skip to content

[KQP] Analyze OLAP supported, OLTP unsupported. #8395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ydb/core/kqp/provider/yql_kikimr_datasink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,16 @@ class TKikimrDataSink : public TDataProviderBase
return false;
}

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") {
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") {
ctx.AddError(TIssue(ctx.GetPosition(node->Pos()), TStringBuilder() << "Write mode '" << static_cast<TStringBuf>(mode) << "' is not supported for olap tables."));
return true;
}

if (tableDesc.Metadata->Kind == EKikimrTableKind::Datashard && mode == "analyze") {
ctx.AddError(TIssue(ctx.GetPosition(node->Pos()), TStringBuilder() << static_cast<TStringBuf>(mode) << " is not supported for oltp tables."));
return true;
}

return false;
}

Expand Down
78 changes: 40 additions & 38 deletions ydb/core/kqp/ut/query/kqp_analyze_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,52 @@ using namespace NYdb::NTable;

Y_UNIT_TEST_SUITE(KqpAnalyze) {

void CreateTable(NStat::TTestEnv& env, const TString& databaseName, const TString& tableName) {
TTableClient client(env.GetDriver());
auto session = client.CreateSession().GetValueSync().GetSession();

auto fullTableName = Sprintf("Root/%s/%s", databaseName.c_str(), tableName.c_str());
auto result = session.ExecuteSchemeQuery(Sprintf(R"(
CREATE TABLE `%s` (
Key Uint64 NOT NULL,
Value String,
PRIMARY KEY (Key)
)
)", fullTableName.c_str())).GetValueSync();
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());

TValueBuilder rows;
rows.BeginList();
for (size_t i = 0; i < 1000; ++i) {
auto key = TValueBuilder().Uint64(i).Build();
auto value = TValueBuilder().OptionalString("Hello, world!").Build();

rows.AddListItem();
rows.BeginStruct();
rows.AddMember("Key", key);
rows.AddMember("Value", value);
rows.EndStruct();
}
rows.EndList();

result = client.BulkUpsert(fullTableName, rows.Build()).GetValueSync();
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
}

using namespace NStat;

Y_UNIT_TEST(AnalyzeDatashardTable) {
Y_UNIT_TEST_TWIN(AnalyzeTable, ColumnStore) {
TTestEnv env(1, 1, 1, true);
CreateDatabase(env, "Database");

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

auto result = session.ExecuteSchemeQuery(
Sprintf(R"(
TString createTable = Sprintf(R"(
CREATE TABLE `%s` (
Key Uint64 NOT NULL,
Value String,
PRIMARY KEY (Key)
)
)", "Root/Database/Table")
).GetValueSync();
)", "Root/Database/Table");
if (ColumnStore) {
createTable +=
R"(
PARTITION BY HASH(Key)
WITH (
STORE = COLUMN,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 16
)
)";
}

auto result = session.ExecuteSchemeQuery(createTable).GetValueSync();
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());

if (ColumnStore) {
result = session.ExecuteSchemeQuery(
Sprintf(R"(
ALTER OBJECT `%s` (TYPE TABLE)
SET (
ACTION=UPSERT_INDEX,
NAME=cms_value,
TYPE=COUNT_MIN_SKETCH,
FEATURES=`{"column_names" : ['Value']}`
);
)", "Root/Database/Table"
)
).GetValueSync();
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
}

TValueBuilder rows;
rows.BeginList();
for (size_t i = 0; i < 1500; ++i) {
Expand All @@ -88,7 +82,15 @@ Y_UNIT_TEST(AnalyzeDatashardTable) {
result = session.ExecuteSchemeQuery(
Sprintf(R"(ANALYZE `Root/%s/%s`)", "Database", "Table")
).GetValueSync();
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());

if (ColumnStore) {
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
} else {
UNIT_ASSERT(!result.IsSuccess());
auto issues = result.GetIssues().ToString();
UNIT_ASSERT_C(issues.find("analyze is not supported for oltp tables.") != TString::npos, issues);
return;
}

auto& runtime = *env.GetServer().GetRuntime();
ui64 saTabletId;
Expand Down
Loading