Skip to content

Commit 5011c62

Browse files
authored
Get next val by path id in SequencerActor (#10519)
1 parent 86fa578 commit 5011c62

File tree

14 files changed

+243
-56
lines changed

14 files changed

+243
-56
lines changed

ydb/core/kqp/common/kqp_resolve.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <ydb/core/base/appdata.h>
77
#include <ydb/core/tx/datashard/range_ops.h>
88
#endif
9-
#include <ydb/core/kqp/provider/yql_kikimr_gateway.h>
109

1110
namespace NKikimr {
1211
namespace NKqp {

ydb/core/kqp/common/kqp_resolve.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ydb/core/tx/sharding/sharding.h>
55
#include <ydb/core/tx/sharding/unboxed_reader.h>
66
#include <ydb/core/kqp/expr_nodes/kqp_expr_nodes.h>
7+
#include <ydb/core/kqp/provider/yql_kikimr_gateway.h>
78
#include <ydb/public/api/protos/ydb_value.pb.h>
89
#include <ydb/core/protos/kqp_physical.pb.h>
910
#include <ydb/core/scheme/scheme_tabledefs.h>
@@ -31,7 +32,7 @@ struct TTableConstInfo : public TAtomicRefCount<TTableConstInfo> {
3132
TVector<TString> KeyColumns;
3233
TVector<NScheme::TTypeInfo> KeyColumnTypes;
3334
ETableKind TableKind = ETableKind::Unknown;
34-
THashMap<TString, TString> Sequences;
35+
THashMap<TString, std::pair<TString, NYql::TKikimrPathId>> Sequences;
3536
THashMap<TString, Ydb::TypedValue> DefaultFromLiteral;
3637
bool IsBuildInProgress = false;
3738

@@ -71,8 +72,8 @@ struct TTableConstInfo : public TAtomicRefCount<TTableConstInfo> {
7172
if (!seq.StartsWith("/")) {
7273
seq = Path + "/" + seq;
7374
}
74-
75-
Sequences.emplace(phyColumn.GetId().GetName(), seq);
75+
NYql::TKikimrPathId pathId(phyColumn.GetDefaultFromSequencePathId().GetOwnerId(), phyColumn.GetDefaultFromSequencePathId().GetLocalPathId());
76+
Sequences.emplace(phyColumn.GetId().GetName(), std::make_pair(seq, pathId));
7677
}
7778

7879
if (phyColumn.HasDefaultFromLiteral()) {
@@ -169,10 +170,6 @@ class TKqpTableKeys {
169170
return TableConstInfo->TableKind;
170171
}
171172

172-
const THashMap<TString, TString>& GetSequences() const {
173-
return TableConstInfo->Sequences;
174-
}
175-
176173
TIntrusiveConstPtr<NSchemeCache::TSchemeCacheNavigate::TColumnTableInfo> GetColumnTableInfo() const {
177174
return ColumnTableInfo;
178175
}

ydb/core/kqp/executer_actor/kqp_tasks_graph.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ void BuildSequencerChannels(TKqpTasksGraph& graph, const TStageInfo& stageInfo,
323323
if (aic != autoIncrementColumns.end()) {
324324
auto sequenceIt = tableInfo->Sequences.find(column);
325325
if (sequenceIt != tableInfo->Sequences.end()) {
326-
columnProto->SetDefaultFromSequence(sequenceIt->second);
326+
auto sequencePath = sequenceIt->second.first;
327+
auto sequencePathId = sequenceIt->second.second;
328+
columnProto->SetDefaultFromSequence(sequencePath);
329+
sequencePathId.ToMessage(columnProto->MutableDefaultFromSequencePathId());
327330
columnProto->SetDefaultKind(
328331
NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_SEQUENCE);
329332
} else {

ydb/core/kqp/gateway/kqp_metadata_loader.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,37 @@ TTableMetadataResult GetTableMetadataResult(const NSchemeCache::TSchemeCacheNavi
168168
tableMeta->QueryName = queryName;
169169
}
170170

171+
THashMap<TString, NYql::TKikimrPathId> sequences;
172+
173+
for (const auto& sequenceDesc : entry.Sequences) {
174+
sequences[sequenceDesc.GetName()] =
175+
NYql::TKikimrPathId(sequenceDesc.GetPathId().GetOwnerId(), sequenceDesc.GetPathId().GetLocalId());
176+
}
177+
171178
std::map<ui32, TString, std::less<ui32>> keyColumns;
172179
std::map<ui32, TString, std::less<ui32>> columnOrder;
173180
for (auto& pair : entry.Columns) {
174181
const auto& columnDesc = pair.second;
175182
auto notNull = entry.NotNullColumns.contains(columnDesc.Name);
176183
const TString typeName = GetTypeName(NScheme::TTypeInfoMod{columnDesc.PType, columnDesc.PTypeMod});
177184
auto defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_UNSPECIFIED;
178-
if (columnDesc.IsDefaultFromSequence())
185+
NYql::TKikimrPathId defaultFromSequencePathId = {};
186+
187+
if (columnDesc.IsDefaultFromSequence()) {
179188
defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_SEQUENCE;
180-
else if (columnDesc.IsDefaultFromLiteral())
189+
auto sequenceIt = sequences.find(columnDesc.DefaultFromSequence);
190+
YQL_ENSURE(sequenceIt != sequences.end());
191+
defaultFromSequencePathId = sequenceIt->second;
192+
} else if (columnDesc.IsDefaultFromLiteral()) {
181193
defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_LITERAL;
182-
194+
}
195+
183196
tableMeta->Columns.emplace(
184197
columnDesc.Name,
185198
NYql::TKikimrColumnMetadata(
186199
columnDesc.Name, columnDesc.Id, typeName, notNull, columnDesc.PType, columnDesc.PTypeMod,
187200
columnDesc.DefaultFromSequence,
201+
defaultFromSequencePathId,
188202
defaultKind,
189203
columnDesc.DefaultFromLiteral,
190204
columnDesc.IsBuildInProgress

ydb/core/kqp/provider/yql_kikimr_gateway.h

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,52 @@ struct TTableSettings {
252252
bool IsSet() const;
253253
};
254254

255+
struct TKikimrPathId {
256+
257+
static const ui64 InvalidOwnerId = Max<ui64>();
258+
static const ui64 InvalidTableId = Max<ui64>();
259+
260+
explicit TKikimrPathId(const std::pair<ui64, ui64>& raw)
261+
: Raw(raw) {}
262+
263+
TKikimrPathId(ui64 ownerId, ui64 tableId)
264+
: TKikimrPathId(std::make_pair(ownerId, tableId)) {}
265+
266+
TKikimrPathId(const NKikimrKqp::TKqpPathIdProto* message)
267+
: TKikimrPathId(std::make_pair(message->GetOwnerId(), message->GetTableId())) {}
268+
269+
TKikimrPathId()
270+
: TKikimrPathId(InvalidOwnerId, InvalidTableId) {}
271+
272+
ui64 OwnerId() const { return Raw.first; }
273+
ui64 TableId() const { return Raw.second; }
274+
275+
TString ToString() const {
276+
return ::ToString(OwnerId()) + ':' + ::ToString(TableId());
277+
}
278+
279+
bool operator==(const TKikimrPathId& x) const {
280+
return Raw == x.Raw;
281+
}
282+
283+
bool operator!=(const TKikimrPathId& x) const {
284+
return !operator==(x);
285+
}
286+
287+
ui64 Hash() const noexcept {
288+
return THash<decltype(Raw)>()(Raw);
289+
}
290+
291+
static TKikimrPathId Parse(const TStringBuf& str);
292+
293+
std::pair<ui64, ui64> Raw;
294+
295+
void ToMessage(NKikimrKqp::TKqpPathIdProto* message) const {
296+
message->SetOwnerId(OwnerId());
297+
message->SetTableId(TableId());
298+
}
299+
};
300+
255301
struct TKikimrColumnMetadata {
256302

257303
TString Name;
@@ -263,14 +309,15 @@ struct TKikimrColumnMetadata {
263309
TVector<TString> Families;
264310
NKikimrKqp::TKqpColumnMetadataProto::EDefaultKind DefaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_UNSPECIFIED;
265311
TString DefaultFromSequence;
312+
TKikimrPathId DefaultFromSequencePathId;
266313
Ydb::TypedValue DefaultFromLiteral;
267314
bool IsBuildInProgress = false;
268315

269316
TKikimrColumnMetadata() = default;
270317

271318
TKikimrColumnMetadata(const TString& name, ui32 id, const TString& type, bool notNull,
272-
NKikimr::NScheme::TTypeInfo typeInfo = {}, const TString& typeMod = {}, const TString& defaultFromSequence = {},
273-
NKikimrKqp::TKqpColumnMetadataProto::EDefaultKind defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_UNSPECIFIED,
319+
NKikimr::NScheme::TTypeInfo typeInfo = {}, const TString& typeMod = {}, const TString& defaultFromSequence = {},
320+
const TKikimrPathId& defaultFromSequencePathId = {}, NKikimrKqp::TKqpColumnMetadataProto::EDefaultKind defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_UNSPECIFIED,
274321
const Ydb::TypedValue& defaultFromLiteral = {}, bool isBuildInProgress = false)
275322
: Name(name)
276323
, Id(id)
@@ -280,6 +327,7 @@ struct TKikimrColumnMetadata {
280327
, TypeMod(typeMod)
281328
, DefaultKind(defaultKind)
282329
, DefaultFromSequence(defaultFromSequence)
330+
, DefaultFromSequencePathId(defaultFromSequencePathId)
283331
, DefaultFromLiteral(defaultFromLiteral)
284332
, IsBuildInProgress(isBuildInProgress)
285333
{}
@@ -292,6 +340,7 @@ struct TKikimrColumnMetadata {
292340
, Families(message->GetFamily().begin(), message->GetFamily().end())
293341
, DefaultKind(message->GetDefaultKind())
294342
, DefaultFromSequence(message->GetDefaultFromSequence())
343+
, DefaultFromSequencePathId(&message->GetDefaultFromSequencePathId())
295344
, DefaultFromLiteral(message->GetDefaultFromLiteral())
296345
, IsBuildInProgress(message->GetIsBuildInProgress())
297346
{
@@ -329,6 +378,7 @@ struct TKikimrColumnMetadata {
329378
auto columnType = NKikimr::NScheme::ProtoColumnTypeFromTypeInfoMod(TypeInfo, TypeMod);
330379
message->SetTypeId(columnType.TypeId);
331380
message->SetDefaultFromSequence(DefaultFromSequence);
381+
DefaultFromSequencePathId.ToMessage(message->MutableDefaultFromSequencePathId());
332382
message->SetDefaultKind(DefaultKind);
333383
message->MutableDefaultFromLiteral()->CopyFrom(DefaultFromLiteral);
334384
message->SetIsBuildInProgress(IsBuildInProgress);
@@ -349,45 +399,6 @@ struct TKikimrColumnMetadata {
349399
}
350400
};
351401

352-
struct TKikimrPathId {
353-
explicit TKikimrPathId(const std::pair<ui64, ui64>& raw)
354-
: Raw(raw) {}
355-
356-
TKikimrPathId(ui64 ownerId, ui64 tableId)
357-
: TKikimrPathId(std::make_pair(ownerId, tableId)) {}
358-
359-
TKikimrPathId(const NKikimrKqp::TKqpPathIdProto* message)
360-
: TKikimrPathId(std::make_pair(message->GetOwnerId(), message->GetTableId())) {}
361-
362-
ui64 OwnerId() const { return Raw.first; }
363-
ui64 TableId() const { return Raw.second; }
364-
365-
TString ToString() const {
366-
return ::ToString(OwnerId()) + ':' + ::ToString(TableId());
367-
}
368-
369-
bool operator==(const TKikimrPathId& x) const {
370-
return Raw == x.Raw;
371-
}
372-
373-
bool operator!=(const TKikimrPathId& x) const {
374-
return !operator==(x);
375-
}
376-
377-
ui64 Hash() const noexcept {
378-
return THash<decltype(Raw)>()(Raw);
379-
}
380-
381-
static TKikimrPathId Parse(const TStringBuf& str);
382-
383-
std::pair<ui64, ui64> Raw;
384-
385-
void ToMessage(NKikimrKqp::TKqpPathIdProto* message) const {
386-
message->SetOwnerId(OwnerId());
387-
message->SetTableId(TableId());
388-
}
389-
};
390-
391402
enum class EKikimrTableKind : ui32 {
392403
Unspecified = 0,
393404
Datashard = 1,

ydb/core/kqp/query_compiler/kqp_query_compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ void FillTable(const TKikimrTableMetadata& tableMeta, THashSet<TStringBuf>&& col
191191
phyColumn.SetIsBuildInProgress(column->IsBuildInProgress);
192192
if (column->IsDefaultFromSequence()) {
193193
phyColumn.SetDefaultFromSequence(column->DefaultFromSequence);
194+
phyColumn.MutableDefaultFromSequencePathId()->SetOwnerId(column->DefaultFromSequencePathId.OwnerId());
195+
phyColumn.MutableDefaultFromSequencePathId()->SetLocalPathId(column->DefaultFromSequencePathId.TableId());
194196
} else if (column->IsDefaultFromLiteral()) {
195197
phyColumn.MutableDefaultFromLiteral()->CopyFrom(column->DefaultFromLiteral);
196198
}

ydb/core/kqp/query_data/ya.make

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ SRCS(
77
)
88

99
PEERDIR(
10+
ydb/public/api/grpc/draft
11+
ydb/public/lib/operation_id/protos
1012
ydb/library/actors/core
1113
ydb/core/actorlib_impl
1214
ydb/core/base
1315
ydb/core/kqp/common/simple
1416
ydb/library/yql/dq/expr_nodes
1517
ydb/library/yql/dq/proto
18+
ydb/library/yql/providers/result/expr_nodes
1619
ydb/core/kqp/expr_nodes
1720
)
1821

ydb/core/kqp/runtime/kqp_sequencer_actor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TKqpSequencerActor : public NActors::TActorBootstrapped<TKqpSequencerActor
3939
using TCProto = NKikimrKqp::TKqpColumnMetadataProto;
4040

4141
TString DefaultFromSequence;
42+
TPathId DefaultFromSequencePathId;
4243
std::set<i64> AllocatedSequenceValues;
4344
NScheme::TTypeInfo TypeInfo;
4445
NUdf::TUnboxedValue UvLiteral;
@@ -52,6 +53,8 @@ class TKqpSequencerActor : public NActors::TActorBootstrapped<TKqpSequencerActor
5253
{
5354
if (DefaultKind == TCProto::DEFAULT_KIND_SEQUENCE) {
5455
DefaultFromSequence = proto.GetDefaultFromSequence();
56+
DefaultFromSequencePathId = TPathId(proto.GetDefaultFromSequencePathId().GetOwnerId(),
57+
proto.GetDefaultFromSequencePathId().GetTableId());
5558
}
5659

5760
if (DefaultKind == TCProto::DEFAULT_KIND_LITERAL) {
@@ -260,7 +263,11 @@ class TKqpSequencerActor : public NActors::TActorBootstrapped<TKqpSequencerActor
260263
continue;
261264
}
262265

263-
Send(SequenceProxyId, new TEvSequenceProxy::TEvNextVal(Settings.GetDatabase(), col.DefaultFromSequence), 0, colIdx);
266+
if (col.DefaultFromSequencePathId != TPathId()) {
267+
Send(SequenceProxyId, new TEvSequenceProxy::TEvNextVal(Settings.GetDatabase(), col.DefaultFromSequencePathId), 0, colIdx);
268+
} else {
269+
Send(SequenceProxyId, new TEvSequenceProxy::TEvNextVal(Settings.GetDatabase(), col.DefaultFromSequence), 0, colIdx);
270+
}
264271
WaitingReplies++;
265272
}
266273
}

0 commit comments

Comments
 (0)