Skip to content

Commit fb8ddf6

Browse files
shnikdGazizonoki
authored andcommitted
Support QueryMeta and diagnostics (#11371)
1 parent bc8fa34 commit fb8ddf6

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

include/ydb-cpp-sdk/client/query/stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TExecStats {
2929

3030
std::optional<std::string> GetPlan() const;
3131
std::optional<std::string> GetAst() const;
32+
std::optional<std::string> GetMeta() const;
3233

3334
TDuration GetTotalDuration() const;
3435
TDuration GetTotalCpuTime() const;

include/ydb-cpp-sdk/client/table/query_stats/stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace NTable {
3030
enum class ECollectQueryStatsMode {
3131
None = 0, // Stats collection is disabled
3232
Basic = 1, // Aggregated stats of reads, updates and deletes per table
33-
Full = 2, // Add per-stage execution profile and query plan on top of Basic mode
33+
Full = 2, // Add per-stage execution profile, query plan and query meta on top of Basic mode
3434
Profile = 3 // Detailed execution stats including stats for individual tasks and channels
3535
};
3636

include/ydb-cpp-sdk/client/table/table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ struct TStreamExecScanQuerySettings : public TRequestSettings<TStreamExecScanQue
11641164
// Collect runtime statistics with a given detalization mode
11651165
FLUENT_SETTING_DEFAULT(ECollectQueryStatsMode, CollectQueryStats, ECollectQueryStatsMode::None);
11661166

1167+
// Deprecated. Use CollectQueryStats >= ECollectQueryStatsMode::Full to get QueryMeta in QueryStats
11671168
// Collect full query compilation diagnostics
11681169
FLUENT_SETTING_DEFAULT(bool, CollectFullDiagnostics, false);
11691170
};
@@ -2109,6 +2110,7 @@ class TScanQueryPart : public TStreamPartStatus {
21092110
const TQueryStats& GetQueryStats() const { return *QueryStats_; }
21102111
TQueryStats ExtractQueryStats() { return std::move(*QueryStats_); }
21112112

2113+
// Deprecated. Use GetMeta() of TQueryStats
21122114
bool HasDiagnostics() const { return Diagnostics_.has_value(); }
21132115
const std::string& GetDiagnostics() const { return *Diagnostics_; }
21142116
std::string&& ExtractDiagnostics() { return std::move(*Diagnostics_); }

src/api/protos/ydb_query_stats.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ message QueryStats {
4343
string query_ast = 5;
4444
uint64 total_duration_us = 6;
4545
uint64 total_cpu_time_us = 7;
46+
// will be filled only in MODE_EXPLAIN or in MODE_EXEC with QueryStatsCollection.Mode >= STATS_COLLECTION_FULL,
47+
// collects additional meta about query compilation, including table metadata
48+
string query_meta = 8;
4649
}

src/api/protos/ydb_table.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ message ExecuteScanQueryRequest {
12741274
QueryStatsCollection.Mode collect_stats = 8;
12751275
// works only in mode: MODE_EXPLAIN,
12761276
// collects additional diagnostics about query compilation, including query plan and scheme
1277-
bool collect_full_diagnostics = 9;
1277+
bool collect_full_diagnostics = 9 [deprecated=true];
12781278
}
12791279

12801280
message ExecuteScanQueryPartialResponse {
@@ -1292,7 +1292,7 @@ message ExecuteScanQueryPartialResult {
12921292
Ydb.TableStats.QueryStats query_stats = 6;
12931293
// works only in mode: MODE_EXPLAIN,
12941294
// collects additional diagnostics about query compilation, including query plan and scheme
1295-
string query_full_diagnostics = 7;
1295+
string query_full_diagnostics = 7 [deprecated = true];
12961296
}
12971297

12981298
// Returns information about an external data source with a given path.

src/client/query/stats.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ std::string TExecStats::ToString(bool withPlan) const {
3131
if (!withPlan) {
3232
proto.clear_query_plan();
3333
proto.clear_query_ast();
34+
proto.clear_query_meta();
3435
}
3536

3637
TStringType res;
@@ -58,6 +59,16 @@ std::optional<std::string> TExecStats::GetAst() const {
5859
return proto.query_ast();
5960
}
6061

62+
std::optional<std::string> TExecStats::GetMeta() const {
63+
auto proto = Impl_->Proto;
64+
65+
if (proto.query_meta().empty()) {
66+
return {};
67+
}
68+
69+
return proto.query_meta();
70+
}
71+
6172
TDuration TExecStats::GetTotalDuration() const {
6273
return TDuration::MicroSeconds(Impl_->Proto.total_duration_us());
6374
}

0 commit comments

Comments
 (0)