diff options
author | nadya02 <nadya02@yandex-team.com> | 2024-04-02 19:39:01 +0300 |
---|---|---|
committer | nadya02 <nadya02@yandex-team.com> | 2024-04-02 19:49:55 +0300 |
commit | e4b79fd4b66ceebe74b6d66f13bf10bc58938848 (patch) | |
tree | 0c38fefdc5831645875df3186dd7ad61cbb12fb7 /yt/cpp | |
parent | 2225c7ebd1219c2f75eb57f9d07708eca6ec3719 (diff) | |
download | ydb-e4b79fd4b66ceebe74b6d66f13bf10bc58938848.tar.gz |
Cosmetic import_table
mv
6604fca1567d9e8ecae8905f5eaed912cb7c475d
Diffstat (limited to 'yt/cpp')
-rw-r--r-- | yt/cpp/mapreduce/library/table_schema/arrow.cpp | 88 | ||||
-rw-r--r-- | yt/cpp/mapreduce/library/table_schema/arrow.h | 15 | ||||
-rw-r--r-- | yt/cpp/mapreduce/library/table_schema/ya.make | 3 |
3 files changed, 106 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/library/table_schema/arrow.cpp b/yt/cpp/mapreduce/library/table_schema/arrow.cpp new file mode 100644 index 0000000000..73bce9bf19 --- /dev/null +++ b/yt/cpp/mapreduce/library/table_schema/arrow.cpp @@ -0,0 +1,88 @@ +#include "arrow.h" + +#include <yt/yt/core/misc/error.h> + +#include <library/cpp/yt/assert/assert.h> + +#include <contrib/libs/apache/arrow/cpp/src/arrow/api.h> +#include <contrib/libs/apache/arrow/cpp/src/arrow/io/api.h> +#include <contrib/libs/apache/arrow/cpp/src/arrow/io/memory.h> +#include <contrib/libs/apache/arrow/cpp/src/arrow/ipc/api.h> + +namespace NYT { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +NTi::TTypePtr GetYTType(const std::shared_ptr<arrow::DataType>& arrowType) +{ + switch (arrowType->id()) { + case arrow::Type::type::BOOL: + return NTi::Bool(); + + case arrow::Type::type::UINT8: + return NTi::Uint8(); + case arrow::Type::type::UINT16: + return NTi::Uint16(); + case arrow::Type::type::UINT32: + return NTi::Uint32(); + case arrow::Type::type::UINT64: + return NTi::Uint64(); + + case arrow::Type::type::INT8: + return NTi::Int8(); + case arrow::Type::type::INT16: + return NTi::Int16(); + case arrow::Type::type::DATE32: + case arrow::Type::type::TIME32: + case arrow::Type::type::INT32: + return NTi::Int32(); + case arrow::Type::type::DATE64: + case arrow::Type::type::TIMESTAMP: + case arrow::Type::type::INT64: + case arrow::Type::type::TIME64: + return NTi::Int64(); + + case arrow::Type::type::HALF_FLOAT: + case arrow::Type::type::FLOAT: + return NTi::Float(); + case arrow::Type::type::DOUBLE: + return NTi::Double(); + + case arrow::Type::type::STRING: + case arrow::Type::type::BINARY: + case arrow::Type::type::FIXED_SIZE_BINARY: + return NTi::String(); + + case arrow::Type::type::LIST: + return NTi::List( + GetYTType(std::reinterpret_pointer_cast<arrow::ListType>(arrowType)->value_type())); + + case arrow::Type::type::MAP: + return NTi::Dict( + GetYTType(std::reinterpret_pointer_cast<arrow::MapType>(arrowType)->key_type()), + GetYTType(std::reinterpret_pointer_cast<arrow::MapType>(arrowType)->item_type())); + + default: + THROW_ERROR_EXCEPTION("Unsupported arrow type: %v", arrowType->ToString()); + } +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +TTableSchema CreateYTTableSchemaFromArrowSchema(const std::shared_ptr<arrow::Schema>& arrowSchema) +{ + TTableSchema resultSchema; + for (const auto& field : arrowSchema->fields()) { + auto ytType = NTi::Optional(GetYTType(field->type())); + resultSchema.AddColumn(TColumnSchema().Name(TString(field->name())).TypeV3(ytType)); + } + return resultSchema; +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/yt/cpp/mapreduce/library/table_schema/arrow.h b/yt/cpp/mapreduce/library/table_schema/arrow.h new file mode 100644 index 0000000000..bf06ab1f20 --- /dev/null +++ b/yt/cpp/mapreduce/library/table_schema/arrow.h @@ -0,0 +1,15 @@ +#pragma once + +#include <yt/cpp/mapreduce/interface/common.h> + +#include <contrib/libs/apache/arrow/cpp/src/arrow/api.h> + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +TTableSchema CreateYTTableSchemaFromArrowSchema(const std::shared_ptr<arrow::Schema>& arrowSchema); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/yt/cpp/mapreduce/library/table_schema/ya.make b/yt/cpp/mapreduce/library/table_schema/ya.make index 4aebad72dd..06541201b5 100644 --- a/yt/cpp/mapreduce/library/table_schema/ya.make +++ b/yt/cpp/mapreduce/library/table_schema/ya.make @@ -3,12 +3,15 @@ LIBRARY() INCLUDE(${ARCADIA_ROOT}/yt/ya_cpp.make.inc) SRCS( + arrow.cpp protobuf.h protobuf.cpp ) PEERDIR( yt/cpp/mapreduce/interface + + contrib/libs/apache/arrow ) END() |