Skip to content

fix columns normalization for absent #7340

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
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
12 changes: 6 additions & 6 deletions ydb/core/formats/arrow/common/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ TGeneralContainer::TGeneralContainer(
Initialize();
}

TGeneralContainer::TGeneralContainer(const std::shared_ptr<arrow::Table>& table) {
TGeneralContainer::TGeneralContainer(const std::shared_ptr<arrow::Table>& table)
: RecordsCount(TValidator::CheckNotNull(table)->num_rows())
, Schema(std::make_shared<NModifier::TSchema>(TValidator::CheckNotNull(table)->schema())) {
AFL_VERIFY(table);
Schema = std::make_shared<NModifier::TSchema>(table->schema());
RecordsCount = table->num_rows();
for (auto&& i : table->columns()) {
if (i->num_chunks() == 1) {
Columns.emplace_back(std::make_shared<NAccessor::TTrivialArray>(i->chunk(0)));
Expand All @@ -113,10 +113,10 @@ TGeneralContainer::TGeneralContainer(const std::shared_ptr<arrow::Table>& table)
Initialize();
}

TGeneralContainer::TGeneralContainer(const std::shared_ptr<arrow::RecordBatch>& table) {
TGeneralContainer::TGeneralContainer(const std::shared_ptr<arrow::RecordBatch>& table)
: RecordsCount(TValidator::CheckNotNull(table)->num_rows())
, Schema(std::make_shared<NModifier::TSchema>(TValidator::CheckNotNull(table)->schema())) {
AFL_VERIFY(table);
Schema = std::make_shared<NModifier::TSchema>(table->schema());
RecordsCount = table->num_rows();
for (auto&& i : table->columns()) {
Columns.emplace_back(std::make_shared<NAccessor::TTrivialArray>(i));
}
Expand Down
4 changes: 2 additions & 2 deletions ydb/core/formats/arrow/common/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class IFieldsConstructor {

class TGeneralContainer {
private:
YDB_READONLY_DEF(std::optional<ui64>, RecordsCount);
std::optional<ui64> RecordsCount;
YDB_READONLY_DEF(std::shared_ptr<NModifier::TSchema>, Schema);
std::vector<std::shared_ptr<NAccessor::IChunkedArray>> Columns;
void Initialize();
public:
TGeneralContainer(const ui32 recordsCount);

ui32 GetRecordsCountVerified() const {
ui32 GetRecordsCount() const {
AFL_VERIFY(RecordsCount);
return *RecordsCount;
}
Expand Down
1 change: 0 additions & 1 deletion ydb/core/kqp/ut/olap/kqp_olap_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,6 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
}
WriteTestData(kikimr, "/Root/olapStore/olapTable", 1000000, 300000000, 1000);

csController->EnableBackground(NKikimr::NYDBTest::ICSController::EBackground::Indexation);
csController->WaitIndexation(TDuration::Seconds(5));
Expand Down
9 changes: 9 additions & 0 deletions ydb/core/kqp/ut/service/kqp_qs_queries_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
#include <ydb/core/kqp/ut/common/columnshard.h>
#include <ydb/core/testlib/common_helper.h>
#include <ydb/core/tx/columnshard/hooks/abstract/abstract.h>
#include <ydb/core/tx/columnshard/hooks/testing/controller.h>
#include <ydb/public/lib/ut_helpers/ut_helpers_query.h>
#include <ydb/public/sdk/cpp/client/ydb_operation/operation.h>
#include <ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
Expand Down Expand Up @@ -3220,6 +3222,11 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {

auto session = Kikimr->GetTableClient().CreateSession().GetValueSync().GetSession();

auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NYDBTest::NColumnShard::TController>();
csController->SetPeriodicWakeupActivationPeriod(TDuration::Seconds(1));
csController->SetLagForCompactionBeforeTierings(TDuration::Seconds(1));
csController->DisableBackground(NKikimr::NYDBTest::ICSController::EBackground::Indexation);

const TString query = Sprintf(R"(
CREATE TABLE `/Root/DataShard` (
Col1 Uint64 NOT NULL,
Expand All @@ -3235,6 +3242,8 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
UNIT_ASSERT_C(result.GetStatus() == NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
DoExecute();
csController->EnableBackground(NKikimr::NYDBTest::ICSController::EBackground::Indexation);
csController->WaitIndexation(TDuration::Seconds(5));
}

};
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/ut/service/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PEERDIR(
library/cpp/threading/local_executor
ydb/core/kqp
ydb/core/kqp/ut/common
ydb/core/tx/columnshard/hooks/testing
ydb/library/yql/sql/pg
ydb/library/yql/parser/pg_wrapper
ydb/public/lib/ut_helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

namespace NKikimr::NOlap::NCompaction {

void IColumnMerger::Start(const std::vector<std::shared_ptr<NArrow::NAccessor::IChunkedArray>>& input) {
AFL_VERIFY(!Started);
Started = true;
for (auto&& i : input) {
AFL_VERIFY(i->GetDataType()->id() == Context.GetResultField()->type()->id())("input", i->GetDataType()->ToString())(
"result", Context.GetResultField()->ToString());
}
return DoStart(input);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ class IColumnMerger {
}
virtual ~IColumnMerger() = default;

void Start(const std::vector<std::shared_ptr<NArrow::NAccessor::IChunkedArray>>& input) {
AFL_VERIFY(!Started);
Started = true;
return DoStart(input);
}
void Start(const std::vector<std::shared_ptr<NArrow::NAccessor::IChunkedArray>>& input);

std::vector<TColumnPortionResult> Execute(const TChunkMergeContext& context, const std::shared_ptr<arrow::RecordBatch>& remap) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ std::vector<TWritePortionInfoWithBlobsResult> TMerger::Execute(const std::shared

ui32 idx = 0;
for (auto&& batch : Batches) {
AFL_VERIFY(batch->GetColumnsCount() == resultFiltered->GetColumnsCount())("data", batch->GetColumnsCount())(
"schema", resultFiltered->GetColumnsCount());
{
NArrow::NConstruction::IArrayBuilder::TPtr column =
std::make_shared<NArrow::NConstruction::TSimpleArrayConstructor<NArrow::NConstruction::TIntConstFiller<arrow::UInt16Type>>>(
Expand All @@ -55,7 +57,6 @@ std::vector<TWritePortionInfoWithBlobsResult> TMerger::Execute(const std::shared
NActors::TLogContextGuard logGuard(
NActors::TLogContextBuilder::Build()("field_name", resultFiltered->GetIndexInfo().GetColumnName(columnId)));
auto columnInfo = stats->GetColumnInfo(columnId);
auto resultField = resultFiltered->GetIndexInfo().GetColumnFieldVerified(columnId);

TColumnMergeContext commonContext(
columnId, resultFiltered, NSplitter::TSplitSettings().GetExpectedUnpackColumnChunkRawSize(), columnInfo);
Expand All @@ -70,7 +71,6 @@ std::vector<TWritePortionInfoWithBlobsResult> TMerger::Execute(const std::shared
IColumnMerger::TFactory::MakeHolder(commonContext.GetLoader()->GetAccessorConstructor().GetClassName(), commonContext);
AFL_VERIFY(!!merger)("problem", "cannot create merger")(
"class_name", commonContext.GetLoader()->GetAccessorConstructor().GetClassName());
// resultFiltered->BuildColumnMergerVerified(columnId);

{
std::vector<std::shared_ptr<NArrow::NAccessor::IChunkedArray>> parts;
Expand Down
12 changes: 1 addition & 11 deletions ydb/core/tx/columnshard/engines/changes/indexation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,7 @@ TConclusionStatus TInsertColumnEngineChanges::DoConstructBlobs(TConstructionCont
Y_ABORT_UNLESS(!DataToIndex.empty());
Y_ABORT_UNLESS(AppendedPortions.empty());

auto maxSnapshot = TSnapshot::Zero();
for (auto& inserted : DataToIndex) {
TSnapshot insertSnap = inserted.GetSnapshot();
Y_ABORT_UNLESS(insertSnap.Valid());
if (insertSnap > maxSnapshot) {
maxSnapshot = insertSnap;
}
}
Y_ABORT_UNLESS(maxSnapshot.Valid());

auto resultSchema = context.SchemaVersions.GetSchema(maxSnapshot);
auto resultSchema = context.SchemaVersions.GetLastSchema();
Y_ABORT_UNLESS(resultSchema->GetIndexInfo().IsSorted());

TPathesData pathBatches(resultSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ std::set<ui32> ISnapshotSchema::GetPkColumnsIds() const {

TConclusion<std::shared_ptr<NArrow::TGeneralContainer>> ISnapshotSchema::NormalizeBatch(
const ISnapshotSchema& dataSchema, const std::shared_ptr<NArrow::TGeneralContainer>& batch, const std::set<ui32>& restoreColumnIds) const {
AFL_VERIFY(dataSchema.GetSnapshot() <= GetSnapshot());
if (dataSchema.GetSnapshot() == GetSnapshot()) {
return batch;
if (batch->GetColumnsCount() == GetColumnsCount()) {
return batch;
}
}
AFL_VERIFY(dataSchema.GetSnapshot() < GetSnapshot());
const std::shared_ptr<arrow::Schema>& resultArrowSchema = GetSchema();

std::shared_ptr<NArrow::TGeneralContainer> result = std::make_shared<NArrow::TGeneralContainer>(batch->GetRecordsCountVerified());
std::shared_ptr<NArrow::TGeneralContainer> result = std::make_shared<NArrow::TGeneralContainer>(batch->GetRecordsCount());
for (size_t i = 0; i < resultArrowSchema->fields().size(); ++i) {
auto& resultField = resultArrowSchema->fields()[i];
auto columnId = GetIndexInfo().GetColumnId(resultField->name());
Expand Down
Loading