Skip to content

Commit 735715d

Browse files
schema inheritance from store to new tables (#15000)
1 parent 7cc0d9b commit 735715d

File tree

13 files changed

+105
-32
lines changed

13 files changed

+105
-32
lines changed

ydb/core/kqp/ut/olap/indexes_ut.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@
1414
namespace NKikimr::NKqp {
1515

1616
Y_UNIT_TEST_SUITE(KqpOlapIndexes) {
17+
Y_UNIT_TEST(TablesInStore) {
18+
auto settings = TKikimrSettings().SetWithSampleTables(false);
19+
TKikimrRunner kikimr(settings);
20+
21+
TLocalHelper(kikimr).CreateTestOlapTable();
22+
23+
auto tableClient = kikimr.GetTableClient();
24+
{
25+
auto alterQuery =
26+
R"(ALTER OBJECT `/Root/olapStore` (TYPE TABLESTORE) SET (ACTION=UPSERT_INDEX, NAME=index_ngramm_uid, TYPE=BLOOM_NGRAMM_FILTER,
27+
FEATURES=`{"column_name" : "resource_id", "ngramm_size" : 3, "hashes_count" : 2, "filter_size_bytes" : 512, "records_count" : 1024}`);
28+
)";
29+
auto session = tableClient.CreateSession().GetValueSync().GetSession();
30+
auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync();
31+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString());
32+
}
33+
{
34+
auto session = tableClient.CreateSession().GetValueSync().GetSession();
35+
36+
auto query = TStringBuilder() << R"(
37+
--!syntax_v1
38+
CREATE TABLE `/Root/olapStore/olapTableTest`
39+
(
40+
timestamp Timestamp NOT NULL,
41+
resource_id Utf8,
42+
uid Utf8 NOT NULL,
43+
level Int32,
44+
message Utf8,
45+
PRIMARY KEY (timestamp, uid)
46+
)
47+
PARTITION BY HASH(timestamp, uid)
48+
WITH (STORE = COLUMN, PARTITION_COUNT = 1))";
49+
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
50+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
51+
}
52+
}
53+
1754
Y_UNIT_TEST(IndexesActualization) {
1855
auto settings = TKikimrSettings().SetWithSampleTables(false);
1956
TKikimrRunner kikimr(settings);

ydb/core/tx/schemeshard/olap/column_families/schema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void TOlapColumnFamiliesDescription::Serialize(NKikimrSchemeOp::TColumnTableSche
8787
}
8888
}
8989

90-
bool TOlapColumnFamiliesDescription::Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
90+
bool TOlapColumnFamiliesDescription::ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
9191
ui32 lastColumnFamilyId = 0;
9292
THashSet<ui32> usedColumnFamilies;
9393
for (const auto& familyProto : opSchema.GetColumnFamilies()) {

ydb/core/tx/schemeshard/olap/column_families/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ class TOlapColumnFamiliesDescription {
3939

4040
bool Parse(const NKikimrSchemeOp::TColumnTableSchema& tableSchema);
4141
void Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchema) const;
42-
bool Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
42+
bool ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
4343
};
4444
}

ydb/core/tx/schemeshard/olap/columns/schema.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void TOlapColumnsDescription::Serialize(NKikimrSchemeOp::TColumnTableSchema& tab
165165
}
166166
}
167167

168-
bool TOlapColumnsDescription::Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
168+
bool TOlapColumnsDescription::ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
169169
const NScheme::TTypeRegistry* typeRegistry = AppData()->TypeRegistry;
170170

171171
ui32 lastColumnId = 0;

ydb/core/tx/schemeshard/olap/columns/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ class TOlapColumnsDescription {
5858

5959
void Parse(const NKikimrSchemeOp::TColumnTableSchema& tableSchema);
6060
void Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchema) const;
61-
bool Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
61+
bool ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
6262
};
6363
}

ydb/core/tx/schemeshard/olap/indexes/schema.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ void TOlapIndexesDescription::Serialize(NKikimrSchemeOp::TColumnTableSchema& tab
8383
}
8484
}
8585

86-
bool TOlapIndexesDescription::Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
86+
bool TOlapIndexesDescription::ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
87+
if (opSchema.GetIndexes().size() == 0) {
88+
return true;
89+
}
8790
THashSet<ui32> usedIndexes;
8891
ui32 lastIdx = 0;
8992
for (const auto& proto : opSchema.GetIndexes()) {

ydb/core/tx/schemeshard/olap/indexes/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ class TOlapIndexesDescription {
7777

7878
void Parse(const NKikimrSchemeOp::TColumnTableSchema& tableSchema);
7979
void Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchema) const;
80-
bool Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
80+
bool ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
8181
};
8282
}

ydb/core/tx/schemeshard/olap/operations/create_table.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TTableConstructorBase {
9999

100100
class TOlapPresetConstructor : public TTableConstructorBase {
101101
ui32 PresetId = 0;
102-
TString PresetName = "default";
102+
TString PresetName = TOlapStoreInfo::DefaultPresetName;
103103
const TOlapStoreInfo& StoreInfo;
104104
mutable bool NeedUpdateObject = false;
105105
public:
@@ -118,27 +118,16 @@ class TOlapPresetConstructor : public TTableConstructorBase {
118118
return false;
119119
}
120120

121-
if (description.HasSchemaPresetId()) {
122-
PresetId = description.GetSchemaPresetId();
123-
if (!StoreInfo.SchemaPresets.contains(PresetId)) {
124-
errors.AddError(Sprintf("Specified schema preset %" PRIu32 " does not exist in tablestore", PresetId));
125-
return false;
126-
}
127-
PresetName = StoreInfo.SchemaPresets.at(PresetId).GetName();
128-
} else {
129-
if (description.HasSchemaPresetName()) {
130-
PresetName = description.GetSchemaPresetName();
131-
}
132-
if (!StoreInfo.SchemaPresetByName.contains(PresetName)) {
133-
errors.AddError(Sprintf("Specified schema preset '%s' does not exist in tablestore", PresetName.c_str()));
134-
return false;
135-
}
136-
PresetId = StoreInfo.SchemaPresetByName.at(PresetName);
137-
Y_ABORT_UNLESS(StoreInfo.SchemaPresets.contains(PresetId));
121+
auto* preset = StoreInfo.GetPresetOptional(description);
122+
if (!preset) {
123+
errors.AddError("preset not found in tables store");
124+
return false;
138125
}
126+
PresetId = preset->GetId();
127+
PresetName = preset->GetName();
139128

140129
if (description.HasSchema()) {
141-
if (!GetSchema().Validate(description.GetSchema(), errors)) {
130+
if (!GetSchema().ValidateForStore(description.GetSchema(), errors)) {
142131
return false;
143132
}
144133
}

ydb/core/tx/schemeshard/olap/options/schema.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ void TOlapOptionsDescription::Serialize(NKikimrSchemeOp::TColumnTableSchema& tab
4242
}
4343
}
4444

45-
bool TOlapOptionsDescription::Validate(const NKikimrSchemeOp::TColumnTableSchema& /*opSchema*/, IErrorCollector& /*errors*/) const {
45+
bool TOlapOptionsDescription::ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& /*errors*/) const {
46+
if (!opSchema.HasOptions()) {
47+
return true;
48+
}
4649
return true;
4750
}
4851

ydb/core/tx/schemeshard/olap/options/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class TOlapOptionsDescription {
1616

1717
void Parse(const NKikimrSchemeOp::TColumnTableSchema& tableSchema);
1818
void Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchema) const;
19-
bool Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
19+
bool ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
2020
};
2121
}

ydb/core/tx/schemeshard/olap/schema/schema.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,20 @@ void TOlapSchema::Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchemaExt)
7171
std::swap(resultLocal, tableSchemaExt);
7272
}
7373

74-
bool TOlapSchema::Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
75-
if (!Columns.Validate(opSchema, errors)) {
74+
bool TOlapSchema::ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const {
75+
if (!Columns.ValidateForStore(opSchema, errors)) {
7676
return false;
7777
}
7878

79-
if (!Indexes.Validate(opSchema, errors)) {
79+
if (!Indexes.ValidateForStore(opSchema, errors)) {
8080
return false;
8181
}
8282

83-
if (!Options.Validate(opSchema, errors)) {
83+
if (!Options.ValidateForStore(opSchema, errors)) {
84+
return false;
85+
}
86+
87+
if (!ColumnFamilies.ValidateForStore(opSchema, errors)) {
8488
return false;
8589
}
8690
return true;

ydb/core/tx/schemeshard/olap/schema/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace NKikimr::NSchemeShard {
3030

3131
void ParseFromLocalDB(const NKikimrSchemeOp::TColumnTableSchema& tableSchema);
3232
void Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchema) const;
33-
bool Validate(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
33+
bool ValidateForStore(const NKikimrSchemeOp::TColumnTableSchema& opSchema, IErrorCollector& errors) const;
3434
bool ValidateTtlSettings(const NKikimrSchemeOp::TColumnDataLifeCycle& ttlSettings, const TOperationContext& context, IErrorCollector& errors) const;
3535
};
3636

ydb/core/tx/schemeshard/olap/store/store.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct TOlapStoreInfo {
1717
NKikimrSchemeOp::TColumnStoreDescription Description;
1818
ui64 AlterVersion = 0;
1919
public:
20+
static const inline TString DefaultPresetName = "default";
21+
2022
using TPtr = std::shared_ptr<TOlapStoreInfo>;
2123

2224
class TLayoutInfo {
@@ -99,6 +101,41 @@ struct TOlapStoreInfo {
99101
shardInfoProto->SetLocalId(idx.GetLocalId().GetValue());
100102
}
101103
}
104+
105+
const TOlapStoreSchemaPreset* GetPresetOptional(const ui32 presetId) const {
106+
auto it = SchemaPresets.find(presetId);
107+
if (it == SchemaPresets.end()) {
108+
return nullptr;
109+
}
110+
return &it->second;
111+
}
112+
113+
const TOlapStoreSchemaPreset& GetPresetVerified(const ui32 presetId) const {
114+
auto* result = GetPresetOptional(presetId);
115+
AFL_VERIFY(result);
116+
return *result;
117+
}
118+
119+
const TOlapStoreSchemaPreset* GetPresetOptional(const TString& presetName) const {
120+
auto it = SchemaPresetByName.find(presetName);
121+
if (it == SchemaPresetByName.end()) {
122+
return nullptr;
123+
}
124+
return &GetPresetVerified(it->second);
125+
}
126+
127+
const TOlapStoreSchemaPreset* GetPresetOptional(const NKikimrSchemeOp::TColumnTableDescription& description) const {
128+
if (description.HasSchemaPresetId()) {
129+
return GetPresetOptional(description.GetSchemaPresetId());
130+
} else {
131+
if (description.HasSchemaPresetName()) {
132+
return GetPresetOptional(description.GetSchemaPresetName());
133+
} else {
134+
return GetPresetOptional(DefaultPresetName);
135+
}
136+
}
137+
}
138+
102139
void SerializeDescription(NKikimrSchemeOp::TColumnStoreDescription& descriptionProto) const;
103140
void ParseFromLocalDB(const NKikimrSchemeOp::TColumnStoreDescription& descriptionProto);
104141
bool ParseFromRequest(const NKikimrSchemeOp::TColumnStoreDescription& descriptionProto, IErrorCollector& errors);

0 commit comments

Comments
 (0)