Browse Source

DebugString methods for debug prints (#1198)

ivanmorozov333 1 year ago
parent
commit
5d10402412

+ 40 - 0
ydb/core/formats/arrow/program.h

@@ -62,6 +62,10 @@ private:
     }
 
 public:
+    TString DebugString() const {
+        return TStringBuilder() << (GeneratedFlag ? "G:" : "") << ColumnName;
+    }
+
     static TColumnInfo Generated(const ui32 columnId, const std::string& columnName) {
         return TColumnInfo(columnId, columnName, true);
     }
@@ -233,6 +237,12 @@ public:
     const arrow::compute::FunctionOptions* GetOptions() const { return FuncOpts.get(); }
 
     IStepFunction<TAssign>::TPtr GetFunction(arrow::compute::ExecContext* ctx) const;
+    TString DebugString() const {
+        return TStringBuilder() <<
+            "{op=" << Operation << ";column=" << Column.DebugString() << ";" << (Constant ? "const=" + Constant->ToString() + ";" : "NO;")
+            << (KernelFunction ? ("kernel=" + KernelFunction->name() + ";") : "NO;")
+            << "}";
+    }
 private:
     const TColumnInfo Column;
     EOperation Operation{EOperation::Unspecified};
@@ -312,6 +322,27 @@ private:
 public:
     using TDatumBatch = TDatumBatch;
 
+    TString DebugString() const {
+        TStringBuilder sb;
+        sb << "{";
+        sb << "assignes=[";
+        for (auto&& i : Assignes) {
+            sb << i.DebugString() << ";";
+        }
+        sb << "];";
+        sb << "group_by_count = " << GroupBy.size() << "; ";
+        sb << "group_by_keys_count=" << GroupByKeys.size() << ";";
+
+        sb << "projections=[";
+        for (auto&& i : Projection) {
+            sb << i.DebugString() << ";";
+        }
+        sb << "];";
+
+        sb << "}";
+        return sb;
+    }
+
     std::set<std::string> GetColumnsInUsage() const;
 
     const std::set<ui32>& GetFilterOriginalColumnIds() const;
@@ -391,6 +422,15 @@ struct TProgram {
     std::set<std::string> GetEarlyFilterColumns() const;
     std::set<std::string> GetProcessingColumns() const;
     std::shared_ptr<NArrow::TColumnFilter> ApplyEarlyFilter(std::shared_ptr<arrow::Table>& batch, const bool useFilter) const;
+    TString DebugString() const {
+        TStringBuilder sb;
+        sb << "[";
+        for (auto&& i : Steps) {
+            sb << i->DebugString() << ";";
+        }
+        sb << "]";
+        return sb;
+    }
 };
 
 inline arrow::Status ApplyProgram(

+ 27 - 0
ydb/core/tx/columnshard/splitter/stats.h

@@ -30,6 +30,14 @@ public:
         Y_ABORT_UNLESS(RawBytes);
     }
 
+    TString DebugString() const {
+        return TStringBuilder() << "{"
+            << "serialized_bytes=" << SerializedBytes << ";"
+            << "records=" << RecordsCount << ";"
+            << "raw_bytes=" << RawBytes << ";"
+            << "}";
+    }
+
     double GetSerializedBytesPerRecord() const {
         AFL_VERIFY(RecordsCount);
         return 1.0 * SerializedBytes / RecordsCount;
@@ -77,6 +85,10 @@ public:
         RawBytesPerRecord = 1.0 * rawBytes / recordsCount;
     }
 
+    TString DebugString() const {
+        return TStringBuilder() << "{sbpr=" << SerializedBytesPerRecord << ";rbpr=" << RawBytesPerRecord << "}";
+    }
+
     TBatchSerializationStat(const TSimpleSerializationStat& simple) {
         SerializedBytesPerRecord = simple.GetSerializedBytesPerRecord();
         RawBytesPerRecord = simple.GetRawBytesPerRecord();
@@ -114,6 +126,7 @@ public:
 
 class TColumnSerializationStat: public TSimpleSerializationStat {
 private:
+    using TBase = TSimpleSerializationStat;
     YDB_READONLY(ui32, ColumnId, 0);
     YDB_READONLY_DEF(std::string, ColumnName);
 public:
@@ -133,6 +146,10 @@ public:
         return result;
     }
 
+    TString DebugString() const {
+        return TStringBuilder() << "{id=" << ColumnId << ";name=" << ColumnName << ";details=" << TBase::DebugString() << "}";
+    }
+
     void Merge(const TSimpleSerializationStat& item) {
         SerializedBytes += item.GetSerializedBytes();
         RawBytes += item.GetRawBytes();
@@ -146,6 +163,16 @@ private:
     std::map<ui32, TColumnSerializationStat*> StatsByColumnId;
     std::map<std::string, TColumnSerializationStat*> StatsByColumnName;
 public:
+    TString DebugString() const {
+        TStringBuilder sb;
+        sb << "{columns=";
+        for (auto&& i : ColumnStat) {
+            sb << i.DebugString();
+        }
+        sb << ";}";
+        return sb;
+    }
+
     void Merge(const TSerializationStats& item) {
         for (auto&& i : item.ColumnStat) {
             AddStat(i);

+ 1 - 0
ydb/core/tx/program/program.cpp

@@ -475,6 +475,7 @@ bool TProgramContainer::Init(const IColumnResolver& columnResolver, NKikimrSchem
             return false;
     }
 
+    ProgramProto = programProto;
     if (IS_DEBUG_LOG_ENABLED(NKikimrServices::TX_COLUMNSHARD)) {
         TString out;
         ::google::protobuf::TextFormat::PrintToString(programProto, &out);

+ 9 - 2
ydb/core/tx/program/program.h

@@ -21,12 +21,21 @@ public:
 
 class TProgramContainer {
 private:
+    NKikimrSSA::TProgram ProgramProto;
     std::shared_ptr<NSsa::TProgram> Program;
     std::shared_ptr<arrow::RecordBatch> ProgramParameters; // TODO
     TKernelsRegistry KernelsRegistry;
     std::optional<std::set<std::string>> OverrideProcessingColumnsSet;
     std::optional<std::vector<TString>> OverrideProcessingColumnsVector;
 public:
+    TString ProtoDebugString() const {
+        return ProgramProto.DebugString();
+    }
+
+    TString DebugString() const {
+        return Program ? Program->DebugString() : "NO_PROGRAM";
+    }
+
     bool HasOverridenProcessingColumnIds() const {
         return !!OverrideProcessingColumnsVector;
     }
@@ -75,8 +84,6 @@ public:
 
     std::set<std::string> GetEarlyFilterColumns() const;
     std::set<std::string> GetProcessingColumns() const;
-
-    bool HasEarlyFilterOnly() const;
 private:
     bool ParseProgram(const IColumnResolver& columnResolver, const NKikimrSSA::TProgram& program, TString& error);
 };