Skip to content

Commit

Permalink
KIKIMR-19139 Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kunga committed Sep 11, 2023
1 parent c800950 commit 66a3bbb
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 188 deletions.
2 changes: 1 addition & 1 deletion ydb/core/tablet_flat/flat_part_charge.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ namespace NTable {

// Note: as we may have cut index key we may both need prev and next pages

if (auto prev = found; --prev) {
if (auto prev = found; prev.Off() && --prev) {
TRowId pageBegin = prev->GetRowId();
TRowId pageEnd = found ? found->GetRowId() : Index.GetEndRowId();
if (pageBegin < endRowId && beginRowId < pageEnd) {
Expand Down
128 changes: 128 additions & 0 deletions ydb/core/tablet_flat/flat_part_index_iter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#pragma once

#include "flat_part_iface.h"
#include "flat_page_index.h"
#include "flat_table_part.h"


namespace NKikimr::NTable {

class TPartIndexIt {
public:
using TCells = NPage::TCells;
using TRecord = NPage::TIndex::TRecord;
using TIndex = NPage::TIndex;
using TIter = NPage::TIndex::TIter;
using TGroupId = NPage::TGroupId;

TPartIndexIt(const TPart* part, TGroupId groupId)
: Part(part)
, GroupId(groupId)
, EndRowId(part->GetGroupIndex(groupId).GetEndRowId())
{ }

EReady Seek(TRowId rowId, bool restart = false) {
auto index = TryGetIndex();
if (!index) {
return EReady::Page;
}

Iter = index->LookupRow(rowId, restart ? TIter() : Iter);
return DataOrGone();
}

EReady Seek(TCells key, ESeek seek, const TPartScheme::TGroupInfo &scheme, const TKeyCellDefaults *keyDefaults) {
auto index = TryGetIndex();
if (!index) {
return EReady::Page;
}

Iter = index->LookupKey(key, scheme, seek, keyDefaults);
return DataOrGone();
}

EReady SeekReverse(TCells key, ESeek seek, const TPartScheme::TGroupInfo &scheme, const TKeyCellDefaults *keyDefaults) {
auto index = TryGetIndex();
if (!index) {
return EReady::Page;
}

Iter = index->LookupKeyReverse(key, scheme, seek, keyDefaults);
return DataOrGone();
}

EReady Next() {
auto index = TryGetIndex();
if (!index) {
return EReady::Page;
}
Iter++;
return DataOrGone();
}

EReady Prev() {
auto index = TryGetIndex();
if (!index) {
return EReady::Page;
}
if (Iter.Off() == 0) {
return EReady::Gone;
}
Iter--;
return DataOrGone();
}

bool IsValid() {
return bool(Iter);
}

public:
TRowId GetEndRowId() {
return EndRowId;
}

TPageId GetPageId() {
Y_VERIFY(Index);
return Iter->GetPageId();
}

TRowId GetRowId() {
Y_VERIFY(Index);
return Iter->GetRowId();
}

TRowId GetNextRowId() {
Y_VERIFY(Index);
auto next = Iter + 1;
return next
? next->GetRowId()
: Max<TRowId>();
}
const TRecord * GetRecord() {
Y_VERIFY(Index);
return Iter.GetRecord();
}

private:
EReady DataOrGone() {
return Iter ? EReady::Data : EReady::Gone;
}

TIndex* TryGetIndex() {
if (Index) {
return &*Index;
}
// TODO: get index from Env
Index = Part->GetGroupIndex(GroupId);
return &*Index;
}

private:
const TPart* const Part;
const TGroupId GroupId;
std::optional<TIndex> Index;
TIter Iter;
TRowId EndRowId;
};

}
Loading

0 comments on commit 66a3bbb

Please sign in to comment.