Skip to content

Commit

Permalink
YT-23579: Support composite types in versioned lookup
Browse files Browse the repository at this point in the history
commit_hash:2ea886d62893b829278657d4adf55a7845a3b0aa
  • Loading branch information
AlexeyLukyanchikov committed Nov 20, 2024
1 parent 4b3fa86 commit 6933e3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 26 additions & 2 deletions yt/yt/client/formats/versioned_writer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "versioned_writer.h"
#include "config.h"

#include <yt/yt/client/table_client/logical_type.h>
#include <yt/yt/client/table_client/name_table.h>

#include <yt/yt/core/concurrency/async_stream.h>

namespace NYT::NFormats {

using namespace NComplexTypes;
using namespace NConcurrency;
using namespace NYson;
using namespace NTableClient;
Expand All @@ -18,7 +22,20 @@ TVersionedWriter::TVersionedWriter(
: Stream_(std::move(stream))
, Schema_(std::move(schema))
, Consumer_(consumerBuilder(&Buffer_))
{ }
{
auto nameTable = TNameTable::FromSchema(*Schema_);

for (const auto& column : Schema_->Columns()) {
if (IsV3Composite(column.LogicalType())) {
auto id = nameTable->GetIdOrThrow(column.Name());
TComplexTypeFieldDescriptor descriptor(column.Name(), column.LogicalType());
auto converter = CreateYsonServerToClientConverter(descriptor, /*config*/ {});
if (converter) {
ColumnConverters_.emplace(id, std::move(converter));
}
}
}
}

TFuture<void> TVersionedWriter::Close()
{
Expand Down Expand Up @@ -52,7 +69,14 @@ bool TVersionedWriter::Write(TRange<TVersionedRow> rows)
case EValueType::Any:
Consumer_->OnRaw(value.AsStringBuf(), EYsonType::Node);
return;
case EValueType::Composite:
case EValueType::Composite: {
if (auto it = ColumnConverters_.find(value.Id); it != ColumnConverters_.end()) {
it->second(value, Consumer_.get());
} else {
Consumer_->OnRaw(value.AsStringBuf(), EYsonType::Node);
}
return;
}
case EValueType::Min:
case EValueType::Max:
case EValueType::TheBottom:
Expand Down
4 changes: 4 additions & 0 deletions yt/yt/client/formats/versioned_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <yt/yt/client/formats/public.h>

#include <yt/yt/client/complex_types/yson_format_conversion.h>

#include <yt/yt/client/table_client/versioned_writer.h>
#include <yt/yt/client/table_client/schema.h>

Expand Down Expand Up @@ -40,6 +42,8 @@ class TVersionedWriter
TFuture<void> Result_;

const std::unique_ptr<NYson::IFlushableYsonConsumer> Consumer_;

THashMap<int, NComplexTypes::TYsonServerToClientConverter> ColumnConverters_;
};

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 6933e3c

Please sign in to comment.