diff options
author | vvvv <vvvv@yandex-team.com> | 2024-12-16 15:24:51 +0300 |
---|---|---|
committer | vvvv <vvvv@yandex-team.com> | 2024-12-16 15:58:22 +0300 |
commit | 05a59c8fb1147ca56cd24c4bb9114d45fd31dd96 (patch) | |
tree | d62cdedd282ccd8294b3119562fddd2b19029255 /yql | |
parent | c5ab007dbc3c15c63e5fa7ed62b3fc0324225830 (diff) | |
download | ydb-05a59c8fb1147ca56cd24c4bb9114d45fd31dd96.tar.gz |
Show used suffixes in the module resolver
commit_hash:669bc907a7f0df443d37a6259bd1435a1696356a
Diffstat (limited to 'yql')
-rw-r--r-- | yql/essentials/ast/yql_expr.h | 2 | ||||
-rw-r--r-- | yql/essentials/core/facade/yql_facade.cpp | 16 | ||||
-rw-r--r-- | yql/essentials/core/yql_type_annotation.cpp | 7 | ||||
-rw-r--r-- | yql/essentials/core/yql_type_annotation.h | 2 |
4 files changed, 19 insertions, 8 deletions
diff --git a/yql/essentials/ast/yql_expr.h b/yql/essentials/ast/yql_expr.h index a903c0022b..476399cbcf 100644 --- a/yql/essentials/ast/yql_expr.h +++ b/yql/essentials/ast/yql_expr.h @@ -14,6 +14,7 @@ #include <yql/essentials/public/udf/udf_data_type.h> #include <library/cpp/yson/node/node.h> +#include <library/cpp/yson/writer.h> #include <library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h> #include <library/cpp/enumbitset/enumbitset.h> @@ -2262,6 +2263,7 @@ public: virtual void RegisterPackage(const TString& package) = 0; virtual bool SetPackageDefaultVersion(const TString& package, ui32 version) = 0; virtual const TExportTable* GetModule(const TString& module) const = 0; + virtual void WriteStatistics(NYson::TYsonWriter& writer) = 0; /* Create new resolver which will use already collected modules in readonly manner. Parent resolver should be alive while using child due to raw data sharing. diff --git a/yql/essentials/core/facade/yql_facade.cpp b/yql/essentials/core/facade/yql_facade.cpp index a0b07e469f..7846d13e09 100644 --- a/yql/essentials/core/facade/yql_facade.cpp +++ b/yql/essentials/core/facade/yql_facade.cpp @@ -1605,7 +1605,6 @@ TMaybe<TString> TProgram::GetStatistics(bool totalOnly, THashMap<TString, TStrin writer.OnBeginMap(); // Providers - bool hasStatistics = false; THashSet<TStringBuf> processed; for (auto& datasink : TypeCtx_->DataSinks) { TStringStream providerOut; @@ -1613,7 +1612,6 @@ TMaybe<TString> TProgram::GetStatistics(bool totalOnly, THashMap<TString, TStrin if (datasink->CollectStatistics(providerWriter, totalOnly)) { writer.OnKeyedItem(datasink->GetName()); writer.OnRaw(providerOut.Str()); - hasStatistics = true; processed.insert(datasink->GetName()); } } @@ -1624,7 +1622,6 @@ TMaybe<TString> TProgram::GetStatistics(bool totalOnly, THashMap<TString, TStrin if (datasource->CollectStatistics(providerWriter, totalOnly)) { writer.OnKeyedItem(datasource->GetName()); writer.OnRaw(providerOut.Str()); - hasStatistics = true; } } } @@ -1655,20 +1652,23 @@ TMaybe<TString> TProgram::GetStatistics(bool totalOnly, THashMap<TString, TStrin writer.OnEndMap(); // system + if (TypeCtx_->Modules) { + writer.OnKeyedItem("moduleResolver"); + writer.OnBeginMap(); + TypeCtx_->Modules->WriteStatistics(writer); + writer.OnEndMap(); + } + // extra for (const auto &[k, extraYson] : extraYsons) { writer.OnKeyedItem(k); writer.OnRaw(extraYson); - hasStatistics = true; } // Footer writer.OnEndMap(); writer.OnEndMap(); - if (hasStatistics) { - return out.Str(); - } - return Nothing(); + return out.Str(); } TMaybe<TString> TProgram::GetDiscoveredData() { diff --git a/yql/essentials/core/yql_type_annotation.cpp b/yql/essentials/core/yql_type_annotation.cpp index 0c627df404..214d7602dc 100644 --- a/yql/essentials/core/yql_type_annotation.cpp +++ b/yql/essentials/core/yql_type_annotation.cpp @@ -372,6 +372,11 @@ const TExportTable* TModuleResolver::GetModule(const TString& module) const { return Modules.FindPtr(normalizedModuleName); } +void TModuleResolver::WriteStatistics(NYson::TYsonWriter& writer) { + writer.OnKeyedItem("UsedSuffixes"); + writer.OnStringScalar(JoinRange(",", UsedSuffixes.begin(), UsedSuffixes.end())); +} + bool TModuleResolver::AddFromUrl(const std::string_view& file, const std::string_view& url, const std::string_view& tokenName, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos) { if (!UserData) { ctx.AddError(TIssue(pos, "Loading libraries is prohibited")); @@ -415,6 +420,7 @@ bool TModuleResolver::AddFromFile(const std::string_view& file, TExprContext& ct return false; } + UsedSuffixes.insert(TString(file.substr(1 + file.rfind('.')))); const TUserDataBlock* block = UserData->FindUserDataBlock(fullName); if (!block) { @@ -473,6 +479,7 @@ bool TModuleResolver::AddFromMemory(const std::string_view& file, const TString& return false; } + UsedSuffixes.insert(TString(file.substr(1 + file.rfind('.')))); moduleName = TModuleResolver::NormalizeModuleName(TString(file)); if (GetModule(moduleName) || Libs.contains(moduleName)) { auto it = Libs.find(moduleName); diff --git a/yql/essentials/core/yql_type_annotation.h b/yql/essentials/core/yql_type_annotation.h index 05ede6e897..b508dc6778 100644 --- a/yql/essentials/core/yql_type_annotation.h +++ b/yql/essentials/core/yql_type_annotation.h @@ -92,6 +92,7 @@ public: void RegisterPackage(const TString& package) override; bool SetPackageDefaultVersion(const TString& package, ui32 version) override; const TExportTable* GetModule(const TString& module) const override; + void WriteStatistics(NYson::TYsonWriter& writer) override; bool AddFromFile(const std::string_view& file, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos) final; bool AddFromUrl(const std::string_view& file, const std::string_view& url, const std::string_view& tokenName, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos) final; bool AddFromMemory(const std::string_view& file, const TString& body, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos) final; @@ -127,6 +128,7 @@ private: const bool OptimizeLibraries; THolder<TExprContext::TFreezeGuard> FreezeGuard; TString FileAliasPrefix; + TSet<TString> UsedSuffixes; }; bool SplitUdfName(TStringBuf name, TStringBuf& moduleName, TStringBuf& funcName); |