|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <ydb/library/formats/arrow/protos/accessor.pb.h> |
| 4 | +#include <ydb/library/formats/arrow/accessor/abstract/accessor.h> |
| 5 | +#include <ydb/library/formats/arrow/accessor/common/chunk_data.h> |
| 6 | +#include <ydb/services/bg_tasks/abstract/interface.h> |
| 7 | + |
| 8 | +#include <library/cpp/object_factory/object_factory.h> |
| 9 | + |
| 10 | +namespace NKikimr::NArrow::NAccessor { |
| 11 | + |
| 12 | +class IConstructor { |
| 13 | +public: |
| 14 | + using TFactory = NObjectFactory::TObjectFactory<IConstructor, TString>; |
| 15 | + using TProto = NKikimrArrowAccessorProto::TConstructor; |
| 16 | + |
| 17 | +private: |
| 18 | + virtual TConclusion<std::shared_ptr<NArrow::NAccessor::IChunkedArray>> DoConstruct( |
| 19 | + const std::shared_ptr<arrow::RecordBatch>& originalData, const TChunkConstructionData& externalInfo) const = 0; |
| 20 | + virtual TConclusion<std::shared_ptr<NArrow::NAccessor::IChunkedArray>> DoConstructDefault( |
| 21 | + const TChunkConstructionData& externalInfo) const = 0; |
| 22 | + virtual NKikimrArrowAccessorProto::TConstructor DoSerializeToProto() const = 0; |
| 23 | + virtual bool DoDeserializeFromProto(const NKikimrArrowAccessorProto::TConstructor& proto) = 0; |
| 24 | + virtual std::shared_ptr<arrow::Schema> DoGetExpectedSchema(const std::shared_ptr<arrow::Field>& resultColumn) const = 0; |
| 25 | + virtual TString DoDebugString() const { |
| 26 | + return ""; |
| 27 | + } |
| 28 | + |
| 29 | +public: |
| 30 | + virtual ~IConstructor() = default; |
| 31 | + |
| 32 | + TString DebugString() const { |
| 33 | + return TStringBuilder() << GetClassName() << ":" << DoDebugString(); |
| 34 | + } |
| 35 | + |
| 36 | + TConclusion<std::shared_ptr<NArrow::NAccessor::IChunkedArray>> Construct( |
| 37 | + const std::shared_ptr<arrow::RecordBatch>& originalData, const TChunkConstructionData& externalInfo) const { |
| 38 | + return DoConstruct(originalData, externalInfo); |
| 39 | + } |
| 40 | + |
| 41 | + TConclusion<std::shared_ptr<NArrow::NAccessor::IChunkedArray>> ConstructDefault(const TChunkConstructionData& externalInfo) const { |
| 42 | + return DoConstructDefault(externalInfo); |
| 43 | + } |
| 44 | + |
| 45 | + bool DeserializeFromProto(const NKikimrArrowAccessorProto::TConstructor& proto) { |
| 46 | + return DoDeserializeFromProto(proto); |
| 47 | + } |
| 48 | + |
| 49 | + NKikimrArrowAccessorProto::TConstructor SerializeToProto() const { |
| 50 | + return DoSerializeToProto(); |
| 51 | + } |
| 52 | + |
| 53 | + void SerializeToProto(NKikimrArrowAccessorProto::TConstructor& proto) const { |
| 54 | + proto = DoSerializeToProto(); |
| 55 | + } |
| 56 | + |
| 57 | + std::shared_ptr<arrow::Schema> GetExpectedSchema(const std::shared_ptr<arrow::Field>& resultColumn) const { |
| 58 | + AFL_VERIFY(resultColumn); |
| 59 | + return DoGetExpectedSchema(resultColumn); |
| 60 | + } |
| 61 | + |
| 62 | + virtual TString GetClassName() const = 0; |
| 63 | +}; |
| 64 | + |
| 65 | +class TConstructorContainer: public NBackgroundTasks::TInterfaceProtoContainer<IConstructor> { |
| 66 | +private: |
| 67 | + using TBase = NBackgroundTasks::TInterfaceProtoContainer<IConstructor>; |
| 68 | + |
| 69 | +public: |
| 70 | + using TBase::TBase; |
| 71 | + |
| 72 | + static TConstructorContainer GetDefaultConstructor(); |
| 73 | +}; |
| 74 | + |
| 75 | +} // namespace NKikimr::NArrow::NAccessor |
0 commit comments