diff options
author | max42 <max42@yandex-team.com> | 2023-06-30 03:37:03 +0300 |
---|---|---|
committer | max42 <max42@yandex-team.com> | 2023-06-30 03:37:03 +0300 |
commit | fac2bd72b4b31ec3238292caf8fb2a8aaa6d6c4a (patch) | |
tree | b8cbc1deb00309c7f1a7ab6df520a76cf0b5c6d7 /library/cpp/skiff/skiff_schema.cpp | |
parent | 7bf166b1a7ed0af927f230022b245af618e998c1 (diff) | |
download | ydb-fac2bd72b4b31ec3238292caf8fb2a8aaa6d6c4a.tar.gz |
YT-19324: move YT provider to ydb/library/yql
This commit is formed by the following script: https://paste.yandex-team.ru/6f92e4b8-efc5-4d34-948b-15ee2accd7e7/text.
This commit has zero effect on all projects that depend on YQL.
The summary of changes:
- `yql/providers/yt -> ydb/library/yql/providers/yt `- the whole implementation of YT provider is moved into YDB code base for further export as a part of YT YQL plugin shared library;
- `yql/providers/stat/{expr_nodes,uploader} -> ydb/library/yql/providers/stat/{expr_nodes,uploader}` - a small interface without implementation and the description of stat expr nodes;
- `yql/core/extract_predicate/ut -> ydb/library/yql/core/extract_predicate/ut`;
- `yql/core/{ut,ut_common} -> ydb/library/yql/core/{ut,ut_common}`;
- `yql/core` is gone;
- `yql/library/url_preprocessing -> ydb/library/yql/core/url_preprocessing`.
**NB**: all new targets inside `ydb/` are under `IF (NOT CMAKE_EXPORT)` clause which disables them from open-source cmake generation and ya make build. They will be enabled in the subsequent commits.
Diffstat (limited to 'library/cpp/skiff/skiff_schema.cpp')
-rw-r--r-- | library/cpp/skiff/skiff_schema.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/library/cpp/skiff/skiff_schema.cpp b/library/cpp/skiff/skiff_schema.cpp new file mode 100644 index 00000000000..c762896ad02 --- /dev/null +++ b/library/cpp/skiff/skiff_schema.cpp @@ -0,0 +1,164 @@ +#include "skiff_schema.h" + +#include "skiff.h" + +#include <util/generic/hash.h> + +namespace NSkiff { + +//////////////////////////////////////////////////////////////////////////////// + +bool operator==(const TSkiffSchema& lhs, const TSkiffSchema& rhs) +{ + if (lhs.GetWireType() != rhs.GetWireType() || lhs.GetName() != rhs.GetName()) { + return false; + } + const auto& lhsChildren = lhs.GetChildren(); + const auto& rhsChildren = rhs.GetChildren(); + return std::equal( + std::begin(lhsChildren), + std::end(lhsChildren), + std::begin(rhsChildren), + std::end(rhsChildren), + TSkiffSchemaPtrEqual()); +} + +bool operator!=(const TSkiffSchema& lhs, const TSkiffSchema& rhs) +{ + return !(lhs == rhs); +} + +//////////////////////////////////////////////////////////////////////////////// + +void PrintShortDebugString(const std::shared_ptr<const TSkiffSchema>& schema, IOutputStream* out) +{ + (*out) << ToString(schema->GetWireType()); + if (!IsSimpleType(schema->GetWireType())) { + auto children = schema->GetChildren(); + if (!children.empty()) { + (*out) << '<'; + for (const auto& child : children) { + PrintShortDebugString(child, out); + (*out) << ';'; + } + (*out) << '>'; + } + } +} + +TString GetShortDebugString(const std::shared_ptr<const TSkiffSchema>& schema) +{ + TStringStream out; + PrintShortDebugString(schema, &out); + return out.Str(); +} + +std::shared_ptr<TSimpleTypeSchema> CreateSimpleTypeSchema(EWireType type) +{ + return std::make_shared<TSimpleTypeSchema>(type); +} + +static void VerifyNonemptyChildren(const TSkiffSchemaList& children, EWireType wireType) +{ + if (children.empty()) { + ythrow TSkiffException() << "\"" << ToString(wireType) << "\" must have at least one child"; + } +} + +std::shared_ptr<TTupleSchema> CreateTupleSchema(TSkiffSchemaList children) +{ + return std::make_shared<TTupleSchema>(std::move(children)); +} + +std::shared_ptr<TVariant8Schema> CreateVariant8Schema(TSkiffSchemaList children) +{ + VerifyNonemptyChildren(children, EWireType::Variant8); + return std::make_shared<TVariant8Schema>(std::move(children)); +} + +std::shared_ptr<TVariant16Schema> CreateVariant16Schema(TSkiffSchemaList children) +{ + VerifyNonemptyChildren(children, EWireType::Variant16); + return std::make_shared<TVariant16Schema>(std::move(children)); +} + +std::shared_ptr<TRepeatedVariant8Schema> CreateRepeatedVariant8Schema(TSkiffSchemaList children) +{ + VerifyNonemptyChildren(children, EWireType::RepeatedVariant8); + return std::make_shared<TRepeatedVariant8Schema>(std::move(children)); +} + +std::shared_ptr<TRepeatedVariant16Schema> CreateRepeatedVariant16Schema(TSkiffSchemaList children) +{ + VerifyNonemptyChildren(children, EWireType::RepeatedVariant16); + return std::make_shared<TRepeatedVariant16Schema>(std::move(children)); +} + +//////////////////////////////////////////////////////////////////////////////// + +TSkiffSchema::TSkiffSchema(EWireType type) + : Type_(type) +{ } + +EWireType TSkiffSchema::GetWireType() const +{ + return Type_; +} + +std::shared_ptr<TSkiffSchema> TSkiffSchema::SetName(TString name) +{ + Name_ = std::move(name); + return shared_from_this(); +} + +const TString& TSkiffSchema::GetName() const +{ + return Name_; +} + +const TSkiffSchemaList& TSkiffSchema::GetChildren() const +{ + static const TSkiffSchemaList children; + return children; +} + +//////////////////////////////////////////////////////////////////////////////// + +TSimpleTypeSchema::TSimpleTypeSchema(EWireType type) + : TSkiffSchema(type) +{ + Y_VERIFY(IsSimpleType(type)); +} + +//////////////////////////////////////////////////////////////////////////////// + +size_t TSkiffSchemaPtrHasher::operator()(const std::shared_ptr<TSkiffSchema>& schema) const +{ + return THash<NSkiff::TSkiffSchema>()(*schema); +} + +size_t TSkiffSchemaPtrEqual::operator()( + const std::shared_ptr<TSkiffSchema>& lhs, + const std::shared_ptr<TSkiffSchema>& rhs) const +{ + return *lhs == *rhs; +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NSkiff + +//////////////////////////////////////////////////////////////////////////////// + +size_t THash<NSkiff::TSkiffSchema>::operator()(const NSkiff::TSkiffSchema &schema) const +{ + auto hash = CombineHashes( + THash<TString>()(schema.GetName()), + static_cast<size_t>(schema.GetWireType())); + for (const auto& child : schema.GetChildren()) { + hash = CombineHashes(hash, (*this)(*child)); + } + return hash; +} + +//////////////////////////////////////////////////////////////////////////////// |