diff options
author | dcherednik <dcherednik@ydb.tech> | 2023-06-19 14:51:28 +0300 |
---|---|---|
committer | dcherednik <dcherednik@ydb.tech> | 2023-06-19 14:51:28 +0300 |
commit | c165426e54ead1cafbeddc8b2e0eb56755bd402a (patch) | |
tree | 6bb57ecf9aef19afc900365b3a33478b399c627d | |
parent | ae3b073bf18da0b90a7c933e688f56d09cd1fd12 (diff) | |
download | ydb-c165426e54ead1cafbeddc8b2e0eb56755bd402a.tar.gz |
Add ydb column meta info (type, name) in to TQueryResponse.
-rw-r--r-- | ydb/core/kqp/host/kqp_host.cpp | 5 | ||||
-rw-r--r-- | ydb/core/kqp/host/kqp_runner.cpp | 2 | ||||
-rw-r--r-- | ydb/core/kqp/host/kqp_transform.h | 7 | ||||
-rw-r--r-- | ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp | 1 | ||||
-rw-r--r-- | ydb/core/kqp/provider/yql_kikimr_gateway.h | 1 | ||||
-rw-r--r-- | ydb/core/kqp/query_compiler/kqp_query_compiler.cpp | 16 | ||||
-rw-r--r-- | ydb/core/protos/kqp_physical.proto | 6 |
7 files changed, 31 insertions, 7 deletions
diff --git a/ydb/core/kqp/host/kqp_host.cpp b/ydb/core/kqp/host/kqp_host.cpp index 05ac8c6e20..bfe6f2347b 100644 --- a/ydb/core/kqp/host/kqp_host.cpp +++ b/ydb/core/kqp/host/kqp_host.cpp @@ -294,6 +294,11 @@ public: YQL_ENSURE(ExecuteCtx.QueryResults.size() == 1); queryResult = std::move(ExecuteCtx.QueryResults[0]); queryResult.QueryPlan = queryResult.PreparingQuery->GetPhysicalQuery().GetQueryPlan(); + auto& bindings = queryResult.PreparingQuery->GetPhysicalQuery().GetResultBindings(); + for (const auto& binding: bindings) { + auto meta = queryResult.ResultSetsMeta.Add(); + meta->CopyFrom(binding.GetResultSetMeta()); + } } private: diff --git a/ydb/core/kqp/host/kqp_runner.cpp b/ydb/core/kqp/host/kqp_runner.cpp index 02c4378e05..5f3cfbca78 100644 --- a/ydb/core/kqp/host/kqp_runner.cpp +++ b/ydb/core/kqp/host/kqp_runner.cpp @@ -308,12 +308,14 @@ private: auto& preparedQuery = *TransformCtx->QueryCtx->PreparingQuery; TKqpPhysicalQuery physicalQuery(transformedQuery); + auto compiler = CreateKqpQueryCompiler(Cluster, OptimizeCtx->Tables, FuncRegistry, TypesCtx); auto ret = compiler->CompilePhysicalQuery(physicalQuery, dataQueryBlocks, *preparedQuery.MutablePhysicalQuery(), ctx); if (!ret) { ctx.AddError(TIssue(ctx.GetPosition(query->Pos()), "Failed to compile physical query.")); return MakeKikimrResultHolder(ResultFromErrors<IKqpHost::TQueryResult>(ctx.IssueManager.GetIssues())); } + preparedQuery.SetVersion(NKikimrKqp::TPreparedQuery::VERSION_PHYSICAL_V1); // TODO(sk): only on stats mode or if explain-only PreparedExplainTransformer->Rewind(); diff --git a/ydb/core/kqp/host/kqp_transform.h b/ydb/core/kqp/host/kqp_transform.h index 0dc73d353c..604f3761b4 100644 --- a/ydb/core/kqp/host/kqp_transform.h +++ b/ydb/core/kqp/host/kqp_transform.h @@ -1,17 +1,10 @@ #pragma once -#include <ydb/core/kqp/expr_nodes/kqp_expr_nodes.h> - -#include <ydb/core/kqp/gateway/kqp_gateway.h> #include <ydb/core/kqp/common/kqp_tx_info.h> -#include <ydb/core/kqp/topics/kqp_topics.h> #include <ydb/core/kqp/provider/yql_kikimr_expr_nodes.h> #include <ydb/core/kqp/provider/yql_kikimr_provider.h> -#include <ydb/core/tx/long_tx_service/public/lock_handle.h> - -#include <ydb/library/yql/dq/common/dq_value.h> #include <ydb/library/yql/utils/log/log.h> namespace NKikimr { diff --git a/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp b/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp index cea798116c..d8a3a07da1 100644 --- a/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp +++ b/ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp @@ -2,6 +2,7 @@ #include "kqp_opt_peephole_rules.h" #include <ydb/core/kqp/common/kqp_yql.h> +#include <ydb/core/kqp/gateway/kqp_gateway.h> #include <ydb/core/kqp/host/kqp_transform.h> #include <ydb/core/kqp/opt/kqp_opt_impl.h> #include <ydb/library/naming_conventions/naming_conventions.h> diff --git a/ydb/core/kqp/provider/yql_kikimr_gateway.h b/ydb/core/kqp/provider/yql_kikimr_gateway.h index b3a4db8669..91a047ae92 100644 --- a/ydb/core/kqp/provider/yql_kikimr_gateway.h +++ b/ydb/core/kqp/provider/yql_kikimr_gateway.h @@ -672,6 +672,7 @@ public: TString QueryPlan; std::shared_ptr<google::protobuf::Arena> ProtobufArenaPtr; TMaybe<ui16> SqlVersion; + google::protobuf::RepeatedPtrField<NKqpProto::TResultSetMeta> ResultSetsMeta; }; struct TLoadTableMetadataSettings { diff --git a/ydb/core/kqp/query_compiler/kqp_query_compiler.cpp b/ydb/core/kqp/query_compiler/kqp_query_compiler.cpp index 9c4f31b9a1..b921dc630f 100644 --- a/ydb/core/kqp/query_compiler/kqp_query_compiler.cpp +++ b/ydb/core/kqp/query_compiler/kqp_query_compiler.cpp @@ -504,6 +504,22 @@ public: auto& txBindingProto = *queryBindingProto.MutableTxResultBinding(); txBindingProto.SetTxIndex(txIndex); txBindingProto.SetResultIndex(txResultIndex); + + auto type = binding.Ref().GetTypeAnn()->Cast<TListExprType>()->GetItemType()->Cast<TStructExprType>(); + YQL_ENSURE(type); + YQL_ENSURE(type->GetKind() == ETypeAnnotationKind::Struct); + + NKikimrMiniKQL::TType kikimrProto; + + NYql::ExportTypeToKikimrProto(*type, kikimrProto, ctx); + + auto resultMeta = queryBindingProto.MutableResultSetMeta(); + + for (const auto& column : kikimrProto.GetStruct().GetMember()) { + auto columnMeta = resultMeta->add_columns(); + columnMeta->set_name(column.GetName()); + ConvertMiniKQLTypeToYdbType(column.GetType(), *columnMeta->mutable_type()); + } } return true; diff --git a/ydb/core/protos/kqp_physical.proto b/ydb/core/protos/kqp_physical.proto index 3149502895..5d5990a8da 100644 --- a/ydb/core/protos/kqp_physical.proto +++ b/ydb/core/protos/kqp_physical.proto @@ -42,10 +42,15 @@ message TKqpPhyParamBinding { } } +message TResultSetMeta { + repeated Ydb.Column columns = 1; +}; + message TKqpPhyResultBinding { oneof Type { TKqpPhyTxResultBinding TxResultBinding = 1; } + TResultSetMeta ResultSetMeta = 2; } message TKqpPhyColumnId { @@ -384,4 +389,5 @@ message TKqpPhyQuery { repeated TKqpTableOp TableOps = 7; repeated TKqpTableInfo TableInfos = 8; bool HasUncommittedChangesRead = 9; + } |