Skip to content

Commit 13e1fb5

Browse files
committed
Fixes
1 parent eb4fd87 commit 13e1fb5

File tree

5 files changed

+54
-43
lines changed

5 files changed

+54
-43
lines changed

ydb/core/kqp/gateway/kqp_ic_gateway.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,11 @@ class TKikimrIcGateway : public IKqpGateway {
10021002
}
10031003

10041004
TFuture<TGenericResult> CreateTableStore(const TString& cluster,
1005-
const NYql::TCreateTableStoreSettings& settings) override {
1005+
const NYql::TCreateTableStoreSettings& settings,
1006+
bool existingOk) override {
10061007
Y_UNUSED(cluster);
10071008
Y_UNUSED(settings);
1009+
Y_UNUSED(existingOk);
10081010
return NotImplemented<TGenericResult>();
10091011
}
10101012

@@ -1016,9 +1018,10 @@ class TKikimrIcGateway : public IKqpGateway {
10161018
}
10171019

10181020
TFuture<TGenericResult> DropTableStore(const TString& cluster,
1019-
const NYql::TDropTableStoreSettings& settings) override {
1021+
const NYql::TDropTableStoreSettings& settings, bool missingOk) override {
10201022
Y_UNUSED(cluster);
10211023
Y_UNUSED(settings);
1024+
Y_UNUSED(missingOk);
10221025
return NotImplemented<TGenericResult>();
10231026
}
10241027

ydb/core/kqp/host/kqp_gateway_proxy.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ class TKqpGatewayProxy : public IKikimrGateway {
13811381
}
13821382

13831383
TFuture<TGenericResult> CreateTableStore(const TString& cluster,
1384-
const TCreateTableStoreSettings& settings) override
1384+
const TCreateTableStoreSettings& settings, bool existingOk) override
13851385
{
13861386
CHECK_PREPARED_DDL(CreateTableStore);
13871387

@@ -1405,6 +1405,8 @@ class TKqpGatewayProxy : public IKikimrGateway {
14051405
schemeTx.SetWorkingDir(pathPair.first);
14061406

14071407
schemeTx.SetOperationType(NKikimrSchemeOp::ESchemeOpCreateColumnStore);
1408+
schemeTx.SetFailedOnAlreadyExists(!existingOk);
1409+
14081410
NKikimrSchemeOp::TColumnStoreDescription* storeDesc = schemeTx.MutableCreateColumnStore();
14091411
storeDesc->SetName(pathPair.second);
14101412
storeDesc->SetColumnShardCount(settings.ShardsCount);
@@ -1462,7 +1464,7 @@ class TKqpGatewayProxy : public IKikimrGateway {
14621464
}
14631465

14641466
TFuture<TGenericResult> DropTableStore(const TString& cluster,
1465-
const TDropTableStoreSettings& settings) override
1467+
const TDropTableStoreSettings& settings, bool missingOk) override
14661468
{
14671469
CHECK_PREPARED_DDL(DropTableStore);
14681470

@@ -1484,7 +1486,7 @@ class TKqpGatewayProxy : public IKikimrGateway {
14841486

14851487
auto& schemeTx = *phyTx.MutableSchemeOperation()->MutableDropTableStore();
14861488
schemeTx.SetWorkingDir(pathPair.first);
1487-
1489+
schemeTx.SetSuccessOnNotExist(missingOk);
14881490
schemeTx.SetOperationType(NKikimrSchemeOp::ESchemeOpDropColumnStore);
14891491
NKikimrSchemeOp::TDrop* drop = schemeTx.MutableDrop();
14901492
drop->SetName(pathPair.second);

ydb/core/kqp/provider/yql_kikimr_exec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi
948948
return SyncError();
949949
}
950950
future = Gateway->CreateTableStore(cluster,
951-
ParseCreateTableStoreSettings(maybeCreate.Cast(), table.Metadata->TableSettings));
951+
ParseCreateTableStoreSettings(maybeCreate.Cast(), table.Metadata->TableSettings), existingOk);
952952
break;
953953
}
954954
case ETableType::Table:
@@ -1018,7 +1018,7 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi
10181018
}
10191019
break;
10201020
case ETableType::TableStore:
1021-
future = Gateway->DropTableStore(cluster, ParseDropTableStoreSettings(maybeDrop.Cast()));
1021+
future = Gateway->DropTableStore(cluster, ParseDropTableStoreSettings(maybeDrop.Cast()), missingOk);
10221022
break;
10231023
case ETableType::ExternalTable:
10241024
future = Gateway->DropExternalTable(cluster, ParseDropExternalTableSettings(maybeDrop.Cast()), missingOk);

ydb/core/kqp/provider/yql_kikimr_gateway.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,13 @@ class IKikimrGateway : public TThrRefBase {
838838

839839
virtual NThreading::TFuture<TGenericResult> AlterColumnTable(const TString& cluster, const TAlterColumnTableSettings& settings) = 0;
840840

841-
virtual NThreading::TFuture<TGenericResult> CreateTableStore(const TString& cluster, const TCreateTableStoreSettings& settings) = 0;
841+
virtual NThreading::TFuture<TGenericResult> CreateTableStore(const TString& cluster,
842+
const TCreateTableStoreSettings& settings, bool existingOk = false) = 0;
842843

843844
virtual NThreading::TFuture<TGenericResult> AlterTableStore(const TString& cluster, const TAlterTableStoreSettings& settings) = 0;
844845

845-
virtual NThreading::TFuture<TGenericResult> DropTableStore(const TString& cluster, const TDropTableStoreSettings& settings) = 0;
846+
virtual NThreading::TFuture<TGenericResult> DropTableStore(const TString& cluster,
847+
const TDropTableStoreSettings& settings, bool missingOk) = 0;
846848

847849
virtual NThreading::TFuture<TGenericResult> CreateExternalTable(const TString& cluster, const TCreateExternalTableSettings& settings, bool createDir, bool existingOk, bool replaceIfExists) = 0;
848850

ydb/core/kqp/ut/service/kqp_qs_queries_ut.cpp

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -701,20 +701,17 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
701701
UNIT_ASSERT_UNEQUAL(exMode, EEx::IfExists);
702702
const TString ifNotExistsStatement = exMode == EEx::IfNotExists ? "IF NOT EXISTS" : "";
703703
const TString objType = isStore ? "TABLESTORE" : "TABLE";
704-
const TString sql = fmt::format(R"sql(
705-
CREATE {obj_type} {if_not_exists} {obj_path} (
704+
auto sql = TStringBuilder() << R"(
705+
--!syntax_v1
706+
CREATE )" << objType << " " << ifNotExistsStatement << " `" << objPath << R"(` (
706707
Key Uint64 NOT NULL,
707708
Value String,
708709
PRIMARY KEY (Key)
709710
)
710711
WITH (
711712
STORE = COLUMN,
712713
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10
713-
);)sql",
714-
"obj_type"_a = objType,
715-
"if_not_exists"_a = ifNotExistsStatement,
716-
"obj_path"_a = objPath
717-
);
714+
);)";
718715

719716
auto result = db.ExecuteQuery(sql, TTxControl::NoTx()).ExtractValueSync();
720717
if (expectSuccess) {
@@ -727,29 +724,36 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
727724

728725
auto checkAlter = [&](const TString& objPath, bool isStore) {
729726
const TString objType = isStore ? "TABLESTORE" : "TABLE";
730-
const TString sql = fmt::format(R"sql(
731-
ALTER {obj_type} {obj_path} (
732-
SET (AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10)
733-
);)sql",
734-
"obj_type"_a = objType,
735-
"obj_path"_a = objPath
736-
);
727+
{
728+
auto sql = TStringBuilder() << R"(
729+
--!syntax_v1
730+
ALTER )" << objType << " `" << objPath << R"(`
731+
ADD COLUMN NewColumn Uint64;
732+
;)";
737733

738-
auto result = db.ExecuteQuery(sql, TTxControl::NoTx()).ExtractValueSync();
734+
auto result = db.ExecuteQuery(sql, TTxControl::NoTx()).ExtractValueSync();
735+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
736+
}
737+
{
738+
auto sql = TStringBuilder() << R"(
739+
--!syntax_v1
740+
ALTER )" << objType << " `" << objPath << R"(`
741+
DROP COLUMN NewColumn;
742+
;)";
743+
744+
auto result = db.ExecuteQuery(sql, TTxControl::NoTx()).ExtractValueSync();
745+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
746+
}
739747
};
740748

741749
auto checkDrop = [&](bool expectSuccess, EEx exMode,
742750
const TString& objPath, bool isStore) {
743751
UNIT_ASSERT_UNEQUAL(exMode, EEx::IfNotExists);
744752
const TString ifExistsStatement = exMode == EEx::IfExists ? "IF EXISTS" : "";
745753
const TString objType = isStore ? "TABLESTORE" : "TABLE";
746-
const TString sql = fmt::format(R"sql(
747-
DROP {obj_type} {if_exists} {obj_path};
748-
)sql",
749-
"obj_type"_a = objType,
750-
"if_exists"_a = ifExistsStatement,
751-
"obj_path"_a = objPath
752-
);
754+
auto sql = TStringBuilder() << R"(
755+
--!syntax_v1
756+
DROP )" << objType << " " << ifExistsStatement << " `" << objPath << R"(`;)";
753757

754758
auto result = db.ExecuteQuery(sql, TTxControl::NoTx()).ExtractValueSync();
755759
if (expectSuccess) {
@@ -779,7 +783,7 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
779783

780784
auto settings = NYdb::NTable::TDescribeTableSettings().WithTableStatistics(true);
781785
auto describeResult =
782-
testHelper.GetSession().DescribeTable("/Root/TableStoreTest/ColumnTableTest", settings).GetValueSync();
786+
testHelper.GetSession().DescribeTable(objPath, settings).GetValueSync();
783787

784788
UNIT_ASSERT_C(describeResult.IsSuccess(), describeResult.GetIssues().ToString());
785789

@@ -792,26 +796,26 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
792796
checkCreate(true, EEx::Empty, "/Root/TableStoreTest", true);
793797
checkCreate(false, EEx::Empty, "/Root/TableStoreTest", true);
794798
checkCreate(true, EEx::IfNotExists, "/Root/TableStoreTest", true);
795-
checkAlter("/Root/TableStoreTest", true);
796799
checkDrop(true, EEx::Empty, "/Root/TableStoreTest", true);
797800
checkDrop(true, EEx::IfExists, "/Root/TableStoreTest", true);
798801
checkDrop(false, EEx::Empty, "/Root/TableStoreTest", true);
799802

800803
checkCreate(true, EEx::IfNotExists, "/Root/TableStoreTest", true);
801804
checkCreate(false, EEx::Empty, "/Root/TableStoreTest", true);
802-
checkAlter("/Root/TableStoreTest", true);
803805
checkDrop(true, EEx::IfExists, "/Root/TableStoreTest", true);
804806
checkDrop(false, EEx::Empty, "/Root/TableStoreTest", true);
805807

806-
checkCreate(true, EEx::IfNotExists, "/Root/TableStoreTest", true);
807-
checkCreate(true, EEx::Empty, "/Root/TableStoreTest/ColumnTable", false);
808-
checkCreate(false, EEx::Empty, "/Root/TableStoreTest/ColumnTable", false);
809-
checkCreate(true, EEx::IfNotExists, "/Root/TableStoreTest/ColumnTable", false);
810-
checkAddRow("/Root/TableStoreTest/ColumnTable");
811-
checkDrop(true, EEx::IfExists, "/Root/TableStoreTest/ColumnTable", false);
812-
checkDrop(false, EEx::Empty, "/Root/TableStoreTest/ColumnTable", false);
813-
checkDrop(true, EEx::IfExists, "/Root/TableStoreTest/ColumnTable", false);
814-
checkDrop(false, EEx::Empty, "/Root/TableStoreTest", true);
808+
checkCreate(true, EEx::IfNotExists, "/Root/ColumnTable", false);
809+
checkAlter("/Root/ColumnTable", false);
810+
checkDrop(true, EEx::IfExists, "/Root/ColumnTable", false);
811+
812+
checkCreate(true, EEx::Empty, "/Root/ColumnTable", false);
813+
checkCreate(false, EEx::Empty, "/Root/ColumnTable", false);
814+
checkCreate(true, EEx::IfNotExists, "/Root/ColumnTable", false);
815+
checkAddRow("/Root/ColumnTable");
816+
checkDrop(true, EEx::IfExists, "/Root/ColumnTable", false);
817+
checkDrop(false, EEx::Empty, "/Root/ColumnTable", false);
818+
checkDrop(true, EEx::IfExists, "/Root/ColumnTable", false);
815819
}
816820

817821
Y_UNIT_TEST(DdlUser) {

0 commit comments

Comments
 (0)