Browse Source

Restoring authorship annotation for <v-mak33v@yandex-team.ru>. Commit 2 of 2.

v-mak33v 3 years ago
parent
commit
fd57eb4948

+ 16 - 16
library/cpp/hyperloglog/hyperloglog.cpp

@@ -87,12 +87,12 @@ namespace {
         }
     }
 
-    double RawEstimate(const ui8* counts, size_t size) { 
+    double RawEstimate(const ui8* counts, size_t size) {
         double sum = {};
-        for (size_t i = 0; i < size; ++i) { 
-            sum += std::pow(2.0, -counts[i]); 
+        for (size_t i = 0; i < size; ++i) {
+            sum += std::pow(2.0, -counts[i]);
         }
-        return EmpiricAlpha(size) * size * size / sum; 
+        return EmpiricAlpha(size) * size * size / sum;
     }
 
     double LinearCounting(size_t registers, size_t zeroed) {
@@ -100,38 +100,38 @@ namespace {
     }
 }
 
-THyperLogLogBase::THyperLogLogBase(unsigned precision) 
-    : Precision(precision) { 
+THyperLogLogBase::THyperLogLogBase(unsigned precision)
+    : Precision(precision) {
     Y_ENSURE(precision >= PRECISION_MIN && precision <= PRECISION_MAX);
 }
 
-void THyperLogLogBase::Update(ui64 hash) { 
+void THyperLogLogBase::Update(ui64 hash) {
     const unsigned subHashBits = 8 * sizeof(hash) - Precision;
     const auto subHash = hash & MaskLowerBits(subHashBits);
     const auto leadingZeroes = subHash ? (subHashBits - GetValueBitCount(subHash)) : subHashBits;
     const ui8 weight = static_cast<ui8>(leadingZeroes + 1);
 
     const size_t reg = static_cast<size_t>(hash >> subHashBits);
-    RegistersRef[reg] = std::max(RegistersRef[reg], weight); 
+    RegistersRef[reg] = std::max(RegistersRef[reg], weight);
 }
 
-void THyperLogLogBase::Merge(const THyperLogLogBase& rh) { 
+void THyperLogLogBase::Merge(const THyperLogLogBase& rh) {
     Y_ENSURE(Precision == rh.Precision);
 
-    std::transform(RegistersRef.begin(), RegistersRef.end(), rh.RegistersRef.begin(), RegistersRef.begin(), [](ui8 l, ui8 r) { return std::max(l, r); }); 
+    std::transform(RegistersRef.begin(), RegistersRef.end(), rh.RegistersRef.begin(), RegistersRef.begin(), [](ui8 l, ui8 r) { return std::max(l, r); });
 }
 
-ui64 THyperLogLogBase::Estimate() const { 
-    const auto m = RegistersRef.size(); 
-    const auto e = RawEstimate(RegistersRef.data(), m); 
+ui64 THyperLogLogBase::Estimate() const {
+    const auto m = RegistersRef.size();
+    const auto e = RawEstimate(RegistersRef.data(), m);
 
     const auto e_ = e <= 5 * m ? (e - EstimateBias(e, Precision)) : e;
-    const auto v = std::count(RegistersRef.begin(), RegistersRef.end(), ui8(0)); 
+    const auto v = std::count(RegistersRef.begin(), RegistersRef.end(), ui8(0));
     const auto h = v != 0 ? LinearCounting(m, v) : e_;
     return h <= GetThreshold(Precision) ? h : e_;
 }
 
-void THyperLogLogBase::Save(IOutputStream& out) const { 
+void THyperLogLogBase::Save(IOutputStream& out) const {
     out.Write(static_cast<char>(Precision));
-    out.Write(RegistersRef.data(), RegistersRef.size() * sizeof(RegistersRef.front())); 
+    out.Write(RegistersRef.data(), RegistersRef.size() * sizeof(RegistersRef.front()));
 }

+ 40 - 40
library/cpp/hyperloglog/hyperloglog.h

@@ -1,64 +1,64 @@
 #pragma once
 
 #include <util/system/types.h>
-#include <util/stream/input.h> 
-#include <util/generic/array_ref.h> 
+#include <util/stream/input.h>
+#include <util/generic/array_ref.h>
 
 #include <vector>
 
 class IOutputStream;
 
-class THyperLogLogBase { 
-protected: 
-    explicit THyperLogLogBase(unsigned precision); 
+class THyperLogLogBase {
+protected:
+    explicit THyperLogLogBase(unsigned precision);
 
 public:
     static const constexpr unsigned PRECISION_MIN = 4;
- 
+
     static const constexpr unsigned PRECISION_MAX = 18;
 
     void Update(ui64 hash);
 
-    void Merge(const THyperLogLogBase& rh); 
+    void Merge(const THyperLogLogBase& rh);
 
     ui64 Estimate() const;
 
     void Save(IOutputStream& out) const;
 
-protected: 
-    unsigned Precision; 
- 
-    TArrayRef<ui8> RegistersRef; 
-}; 
- 
-template <typename Alloc> 
-class THyperLogLogWithAlloc : public THyperLogLogBase { 
-private: 
-    explicit THyperLogLogWithAlloc(unsigned precision) 
-        : THyperLogLogBase(precision) { 
-        Registers.resize(1u << precision); 
-        RegistersRef = MakeArrayRef(Registers); 
+protected:
+    unsigned Precision;
+
+    TArrayRef<ui8> RegistersRef;
+};
+
+template <typename Alloc>
+class THyperLogLogWithAlloc : public THyperLogLogBase {
+private:
+    explicit THyperLogLogWithAlloc(unsigned precision)
+        : THyperLogLogBase(precision) {
+        Registers.resize(1u << precision);
+        RegistersRef = MakeArrayRef(Registers);
+    }
+
+public:
+    THyperLogLogWithAlloc(THyperLogLogWithAlloc&&) = default;
+
+    THyperLogLogWithAlloc& operator=(THyperLogLogWithAlloc&&) = default;
+
+    static THyperLogLogWithAlloc Create(unsigned precision) {
+        return THyperLogLogWithAlloc(precision);
+    }
+
+    static THyperLogLogWithAlloc Load(IInputStream& in) {
+        char precision = {};
+        Y_ENSURE(in.ReadChar(precision));
+        auto res = Create(precision);
+        in.LoadOrFail(res.Registers.data(), res.Registers.size() * sizeof(res.Registers.front()));
+        return res;
     }
 
-public: 
-    THyperLogLogWithAlloc(THyperLogLogWithAlloc&&) = default; 
-
-    THyperLogLogWithAlloc& operator=(THyperLogLogWithAlloc&&) = default; 
- 
-    static THyperLogLogWithAlloc Create(unsigned precision) { 
-        return THyperLogLogWithAlloc(precision); 
-    } 
- 
-    static THyperLogLogWithAlloc Load(IInputStream& in) { 
-        char precision = {}; 
-        Y_ENSURE(in.ReadChar(precision)); 
-        auto res = Create(precision); 
-        in.LoadOrFail(res.Registers.data(), res.Registers.size() * sizeof(res.Registers.front())); 
-        return res; 
-    } 
- 
 private:
-    std::vector<ui8, Alloc> Registers; 
+    std::vector<ui8, Alloc> Registers;
 };
- 
-using THyperLogLog = THyperLogLogWithAlloc<std::allocator<ui8>>; 
+
+using THyperLogLog = THyperLogLogWithAlloc<std::allocator<ui8>>;

+ 24 - 24
ydb/library/yql/core/facade/yql_facade.cpp

@@ -1120,29 +1120,29 @@ TMaybe<TString> TProgram::GetTasksInfo() {
 }
 
 TMaybe<TString> TProgram::GetStatistics(bool totalOnly) {
-    if (!TypeCtx_) { 
-        return Nothing(); 
-    } 
- 
-    TStringStream out; 
+    if (!TypeCtx_) {
+        return Nothing();
+    }
+
+    TStringStream out;
     NYson::TYsonWriter writer(&out);
     // Header
-    writer.OnBeginMap(); 
-    writer.OnKeyedItem("ExecutionStatistics"); 
-    writer.OnBeginMap(); 
- 
+    writer.OnBeginMap();
+    writer.OnKeyedItem("ExecutionStatistics");
+    writer.OnBeginMap();
+
     // Providers
-    bool hasStatistics = false; 
-    for (auto& datasink : TypeCtx_->DataSinks) { 
+    bool hasStatistics = false;
+    for (auto& datasink : TypeCtx_->DataSinks) {
         TStringStream providerOut;
         NYson::TYsonWriter providerWriter(&providerOut);
         if (datasink->CollectStatistics(providerWriter, totalOnly)) {
-            writer.OnKeyedItem(datasink->GetName()); 
+            writer.OnKeyedItem(datasink->GetName());
             writer.OnRaw(providerOut.Str());
             hasStatistics = true;
-        } 
-    } 
- 
+        }
+    }
+
     auto rusage = TRusage::Get();
     // System stats
     writer.OnKeyedItem("system");
@@ -1161,14 +1161,14 @@ TMaybe<TString> TProgram::GetStatistics(bool totalOnly) {
     writer.OnEndMap(); // system
 
     // Footer
-    writer.OnEndMap(); 
-    writer.OnEndMap(); 
-    if (hasStatistics) { 
-        return out.Str(); 
-    } 
-    return Nothing(); 
+    writer.OnEndMap();
+    writer.OnEndMap();
+    if (hasStatistics) {
+        return out.Str();
+    }
+    return Nothing();
 }
- 
+
 TMaybe<TString> TProgram::GetDiscoveredData() {
     if (!TypeCtx_) {
         return Nothing();
@@ -1187,8 +1187,8 @@ TMaybe<TString> TProgram::GetDiscoveredData() {
     }
     writer.OnEndMap();
     return out.Str();
-} 
- 
+}
+
 TProgram::TFutureStatus TProgram::ContinueAsync() {
     YQL_LOG_CTX_ROOT_SCOPE(GetSessionId());
     return AsyncTransformWithFallback(true);

+ 3 - 3
ydb/library/yql/core/facade/yql_facade.h

@@ -218,7 +218,7 @@ public:
     TMaybe<TString> GetTasksInfo();
 
     TMaybe<TString> GetStatistics(bool totalOnly = false);
- 
+
     TMaybe<TString> GetDiscoveredData();
 
     TString ResultsAsString() const;
@@ -290,8 +290,8 @@ public:
         SupportsResultPosition_ = true;
     }
 
-    IPlanBuilder& GetPlanBuilder(); 
- 
+    IPlanBuilder& GetPlanBuilder();
+
 private:
     TProgram(
         const NKikimr::NMiniKQL::IFunctionRegistry* functionRegistry,

+ 4 - 4
ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp

@@ -5960,12 +5960,12 @@ THolder<IGraphTransformer> MakePeepholeOptimization(TTypeAnnotationContextPtr ty
     peepholeSettings.CommonConfig = peepholeSettings.FinalConfig = config;
     auto commonTransformer = CreatePeepHoleCommonStageTransformer<true>(*typeAnnotationContext, nullptr, peepholeSettings);
     auto finalTransformer = CreatePeepHoleFinalStageTransformer<true>(*typeAnnotationContext, nullptr, nullptr, peepholeSettings);
-    return CreateFunctorTransformer( 
+    return CreateFunctorTransformer(
             [common = std::move(commonTransformer), final = std::move(finalTransformer)](TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) -> IGraphTransformer::TStatus {
                 return DoPeepHoleOptimizeNode(input, output, ctx, *common, *final);
-            }); 
+            });
 }
- 
+
 template IGraphTransformer::TStatus PeepHoleOptimizeNode<true>(const TExprNode::TPtr& input, TExprNode::TPtr& output,
     TExprContext& ctx, TTypeAnnotationContext& types, IGraphTransformer* typeAnnotator,
     bool& hasNonDeterministicFunctions, const TPeepholeSettings& peepholeSettings);
@@ -5973,4 +5973,4 @@ template IGraphTransformer::TStatus PeepHoleOptimizeNode<true>(const TExprNode::
 template IGraphTransformer::TStatus PeepHoleOptimizeNode<false>(const TExprNode::TPtr& input, TExprNode::TPtr& output,
     TExprContext& ctx, TTypeAnnotationContext& types, IGraphTransformer* typeAnnotator,
     bool& hasNonDeterministicFunctions, const TPeepholeSettings& peepholeSettings);
-} 
+}

+ 2 - 2
ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.h

@@ -18,7 +18,7 @@ template <bool EnableNewOptimizers>
 IGraphTransformer::TStatus PeepHoleOptimizeNode(const TExprNode::TPtr& input, TExprNode::TPtr& output,
     TExprContext& ctx, TTypeAnnotationContext& types, IGraphTransformer* typeAnnotator,
     bool& hasNonDeterministicFunctions, const TPeepholeSettings& peepholeSettings = {});
- 
+
 THolder<IGraphTransformer> MakePeepholeOptimization(TTypeAnnotationContextPtr typeAnnotationContext, const IPipelineConfigurator* config = nullptr);
- 
+
 }

+ 2 - 2
ydb/library/yql/core/services/ya.make

@@ -11,8 +11,8 @@ SRCS(
     yql_eval_expr.h
     yql_eval_params.cpp
     yql_eval_params.h
-    yql_out_transformers.cpp 
-    yql_out_transformers.h 
+    yql_out_transformers.cpp
+    yql_out_transformers.h
     yql_plan.cpp
     yql_plan.h
     yql_transform_pipeline.cpp

+ 43 - 43
ydb/library/yql/core/services/yql_out_transformers.cpp

@@ -1,52 +1,52 @@
-#include "yql_out_transformers.h" 
- 
+#include "yql_out_transformers.h"
+
 #include <ydb/library/yql/ast/yql_expr.h>
- 
+
 #include <library/cpp/yson/writer.h>
- 
-#include <util/stream/null.h> 
+
+#include <util/stream/null.h>
 #include <util/stream/str.h>
- 
-namespace NYql { 
- 
-IGraphTransformer::TStatus TExprOutputTransformer::operator()( 
-    const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) 
-{ 
-    Y_UNUSED(ctx); 
-    output = input; 
-    if (!ExprRoot_) { 
-        return IGraphTransformer::TStatus::Ok; 
-    } 
- 
+
+namespace NYql {
+
+IGraphTransformer::TStatus TExprOutputTransformer::operator()(
+    const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx)
+{
+    Y_UNUSED(ctx);
+    output = input;
+    if (!ExprRoot_) {
+        return IGraphTransformer::TStatus::Ok;
+    }
+
     auto ast = ConvertToAst(*ExprRoot_, ctx, WithTypes_ ? TExprAnnotationFlags::Types : TExprAnnotationFlags::None, true);
-    ui32 prettyFlags = TAstPrintFlags::ShortQuote; 
-    if (!WithTypes_) { 
-        prettyFlags |= TAstPrintFlags::PerLine; 
-    } 
- 
-    if (DirectOut_) { 
-        ast.Root->PrettyPrintTo(*DirectOut_, prettyFlags); 
-    } 
-    return IGraphTransformer::TStatus::Ok; 
-} 
- 
-IGraphTransformer::TStatus TPlanOutputTransformer::operator()( 
-    const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) 
-{ 
-    Y_UNUSED(ctx); 
-    output = input; 
-    if (DirectOut_) { 
+    ui32 prettyFlags = TAstPrintFlags::ShortQuote;
+    if (!WithTypes_) {
+        prettyFlags |= TAstPrintFlags::PerLine;
+    }
+
+    if (DirectOut_) {
+        ast.Root->PrettyPrintTo(*DirectOut_, prettyFlags);
+    }
+    return IGraphTransformer::TStatus::Ok;
+}
+
+IGraphTransformer::TStatus TPlanOutputTransformer::operator()(
+    const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx)
+{
+    Y_UNUSED(ctx);
+    output = input;
+    if (DirectOut_) {
         NYson::TYsonWriter writer(DirectOut_, OutputFormat_);
-        Builder_.WritePlan(writer, input); 
-    } else { 
-        TNullOutput null; 
+        Builder_.WritePlan(writer, input);
+    } else {
+        TNullOutput null;
         NYson::TYsonWriter writer(&null, OutputFormat_);
-        Builder_.WritePlan(writer, input); 
-    } 
- 
-    return IGraphTransformer::TStatus::Ok; 
-} 
- 
+        Builder_.WritePlan(writer, input);
+    }
+
+    return IGraphTransformer::TStatus::Ok;
+}
+
 IGraphTransformer::TStatus TExprLogTransformer::operator()(
     const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx)
 {

+ 51 - 51
ydb/library/yql/core/services/yql_out_transformers.h

@@ -1,69 +1,69 @@
-#pragma once 
- 
+#pragma once
+
 #include <ydb/library/yql/core/services/yql_transform_pipeline.h>
 #include <ydb/library/yql/core/services/yql_plan.h>
 #include <ydb/library/yql/utils/log/log.h>
 #include <ydb/library/yql/core/yql_type_annotation.h>
 #include <ydb/library/yql/core/yql_graph_transformer.h>
- 
+
 #include <library/cpp/yson/public.h>
- 
-#include <util/stream/output.h> 
-#include <util/generic/ptr.h> 
- 
-namespace NYql { 
- 
-class TExprOutputTransformer { 
-public: 
-    TExprOutputTransformer(const TExprNode::TPtr& exprRoot, IOutputStream* directOut, bool withTypes) 
-        : ExprRoot_(exprRoot), DirectOut_(directOut), WithTypes_(withTypes) 
-    { 
-    } 
- 
-    IGraphTransformer::TStatus operator()(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx); 
- 
-    static TAutoPtr<IGraphTransformer> Sync( 
-        const TExprNode::TPtr& exprRoot, 
-        IOutputStream* directOut, 
-        bool withTypes = false) 
-    { 
-        return directOut ? CreateFunctorTransformer(TExprOutputTransformer(exprRoot, directOut, withTypes)) : nullptr; 
-    } 
- 
-private: 
-    const TExprNode::TPtr &ExprRoot_; 
-    IOutputStream *DirectOut_; 
-    bool WithTypes_; 
-}; 
- 
-class TPlanOutputTransformer { 
-public: 
-    TPlanOutputTransformer( 
+
+#include <util/stream/output.h>
+#include <util/generic/ptr.h>
+
+namespace NYql {
+
+class TExprOutputTransformer {
+public:
+    TExprOutputTransformer(const TExprNode::TPtr& exprRoot, IOutputStream* directOut, bool withTypes)
+        : ExprRoot_(exprRoot), DirectOut_(directOut), WithTypes_(withTypes)
+    {
+    }
+
+    IGraphTransformer::TStatus operator()(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx);
+
+    static TAutoPtr<IGraphTransformer> Sync(
+        const TExprNode::TPtr& exprRoot,
+        IOutputStream* directOut,
+        bool withTypes = false)
+    {
+        return directOut ? CreateFunctorTransformer(TExprOutputTransformer(exprRoot, directOut, withTypes)) : nullptr;
+    }
+
+private:
+    const TExprNode::TPtr &ExprRoot_;
+    IOutputStream *DirectOut_;
+    bool WithTypes_;
+};
+
+class TPlanOutputTransformer {
+public:
+    TPlanOutputTransformer(
         IOutputStream* directOut,
-        IPlanBuilder& builder, 
+        IPlanBuilder& builder,
         NYson::EYsonFormat outputFormat)
         : DirectOut_(directOut)
-        , Builder_(builder) 
-        , OutputFormat_(outputFormat) 
-    { 
-    } 
- 
-    IGraphTransformer::TStatus operator()(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx); 
- 
-    static TAutoPtr <IGraphTransformer> Sync( 
+        , Builder_(builder)
+        , OutputFormat_(outputFormat)
+    {
+    }
+
+    IGraphTransformer::TStatus operator()(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx);
+
+    static TAutoPtr <IGraphTransformer> Sync(
             IOutputStream* directOut,
             IPlanBuilder& builder,
             NYson::EYsonFormat outputFormat)
-    { 
+    {
         return CreateFunctorTransformer(TPlanOutputTransformer(directOut, builder, outputFormat));
-    } 
- 
-private: 
+    }
+
+private:
     IOutputStream* DirectOut_;
-    IPlanBuilder& Builder_; 
+    IPlanBuilder& Builder_;
     NYson::EYsonFormat OutputFormat_;
-}; 
- 
+};
+
 class TExprLogTransformer {
 public:
     TExprLogTransformer(const TString& description, NYql::NLog::EComponent component, NYql::NLog::ELevel level)

+ 5 - 5
ydb/library/yql/core/services/yql_transform_pipeline.cpp

@@ -235,9 +235,9 @@ TAutoPtr<IGraphTransformer> TTransformationPipeline::BuildWithNoArgChecks(bool u
     return CreateCompositeGraphTransformerWithNoArgChecks(Transformers_, useIssueScopes);
 }
 
-TIntrusivePtr<TTypeAnnotationContext> TTransformationPipeline::GetTypeAnnotationContext() const { 
-    return TypeAnnotationContext_; 
-} 
- 
- 
+TIntrusivePtr<TTypeAnnotationContext> TTransformationPipeline::GetTypeAnnotationContext() const {
+    return TypeAnnotationContext_;
+}
+
+
 } // namespace NYql

Some files were not shown because too many files changed in this diff