aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspuchin <spuchin@ydb.tech>2023-06-09 23:16:43 +0300
committerspuchin <spuchin@ydb.tech>2023-06-09 23:16:43 +0300
commit41e40901a93e04955628042e75367b2662a81542 (patch)
tree49a5dcb6988f6b1d54a2fc692e2f5c0555432b9a
parent2e5e931acb261a6558b4b3762d0a9028ec242670 (diff)
downloadydb-41e40901a93e04955628042e75367b2662a81542.tar.gz
Add syntax selection support to ExecuteQuery. ()
-rw-r--r--ydb/core/grpc_services/query/rpc_execute_query.cpp145
-rw-r--r--ydb/core/kqp/common/events/query.h8
-rw-r--r--ydb/core/kqp/common/kqp_event_impl.cpp5
-rw-r--r--ydb/core/kqp/common/simple/query_id.cpp10
-rw-r--r--ydb/core/kqp/common/simple/query_id.h9
-rw-r--r--ydb/core/kqp/common/simple/settings.h17
-rw-r--r--ydb/core/kqp/compile_service/kqp_compile_actor.cpp22
-rw-r--r--ydb/core/kqp/host/kqp_host.cpp47
-rw-r--r--ydb/core/kqp/host/kqp_host.h4
-rw-r--r--ydb/core/kqp/session_actor/kqp_query_state.cpp30
-rw-r--r--ydb/core/kqp/session_actor/kqp_query_state.h4
-rw-r--r--ydb/core/kqp/ut/service/CMakeLists.darwin-x86_64.txt2
-rw-r--r--ydb/core/kqp/ut/service/CMakeLists.linux-aarch64.txt2
-rw-r--r--ydb/core/kqp/ut/service/CMakeLists.linux-x86_64.txt2
-rw-r--r--ydb/core/kqp/ut/service/CMakeLists.windows-x86_64.txt2
-rw-r--r--ydb/core/kqp/ut/service/kqp_query_service_ut.cpp23
-rw-r--r--ydb/core/protos/kqp.proto2
-rw-r--r--ydb/public/sdk/cpp/client/draft/ydb_query/impl/exec_query.cpp1
-rw-r--r--ydb/public/sdk/cpp/client/draft/ydb_query/query.h1
19 files changed, 208 insertions, 128 deletions
diff --git a/ydb/core/grpc_services/query/rpc_execute_query.cpp b/ydb/core/grpc_services/query/rpc_execute_query.cpp
index 41948f9e29..149e6061b8 100644
--- a/ydb/core/grpc_services/query/rpc_execute_query.cpp
+++ b/ydb/core/grpc_services/query/rpc_execute_query.cpp
@@ -65,24 +65,6 @@ private:
ui64 TotalResponsesSize_ = 0;
};
-bool FillQueryContent(const Ydb::Query::ExecuteQueryRequest& req, NKikimrKqp::TEvQueryRequest& kqpRequest,
- NYql::TIssues& issues)
-{
- switch (req.query_case()) {
- case Ydb::Query::ExecuteQueryRequest::kQueryContent:
- if (!CheckQuery(req.query_content().text(), issues)) {
- return false;
- }
-
- kqpRequest.MutableRequest()->SetQuery(req.query_content().text());
- return true;
-
- default:
- issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, "Unexpected query option"));
- return false;
- }
-}
-
bool FillTxSettings(const Ydb::Query::TransactionSettings& from, Ydb::Table::TransactionSettings& to,
NYql::TIssues& issues)
{
@@ -146,65 +128,65 @@ Ydb::Table::QueryStatsCollection::Mode GetCollectStatsMode(Ydb::Query::StatsMode
}
}
-bool NeedReportStats(const Ydb::Query::ExecuteQueryRequest& req) {
+bool ParseQueryAction(const Ydb::Query::ExecuteQueryRequest& req, NKikimrKqp::EQueryAction& queryAction,
+ NYql::TIssues& issues)
+{
switch (req.exec_mode()) {
+ case Ydb::Query::EXEC_MODE_VALIDATE:
+ queryAction = NKikimrKqp::QUERY_ACTION_VALIDATE;
+ return true;
+
case Ydb::Query::EXEC_MODE_EXPLAIN:
+ queryAction = NKikimrKqp::QUERY_ACTION_EXPLAIN;
return true;
case Ydb::Query::EXEC_MODE_EXECUTE:
- switch (req.stats_mode()) {
- case Ydb::Query::StatsMode::STATS_MODE_BASIC:
- case Ydb::Query::StatsMode::STATS_MODE_FULL:
- case Ydb::Query::StatsMode::STATS_MODE_PROFILE:
- return true;
- default:
- return false;
- }
+ queryAction = NKikimrKqp::QUERY_ACTION_EXECUTE;
+ return true;
default:
+ issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, "Unexpected query mode"));
return false;
}
}
-std::tuple<Ydb::StatusIds::StatusCode, NYql::TIssues> FillKqpRequest(
- const Ydb::Query::ExecuteQueryRequest& req, NKikimrKqp::TEvQueryRequest& kqpRequest)
+bool ParseQueryContent(const Ydb::Query::ExecuteQueryRequest& req, TString& query, Ydb::Query::Syntax& syntax,
+ NYql::TIssues& issues)
{
- kqpRequest.MutableRequest()->MutableYdbParameters()->insert(req.parameters().begin(), req.parameters().end());
- switch (req.exec_mode()) {
- case Ydb::Query::EXEC_MODE_VALIDATE:
- kqpRequest.MutableRequest()->SetAction(NKikimrKqp::QUERY_ACTION_VALIDATE);
- break;
- case Ydb::Query::EXEC_MODE_EXPLAIN:
- kqpRequest.MutableRequest()->SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN);
- break;
- case Ydb::Query::EXEC_MODE_EXECUTE:
- kqpRequest.MutableRequest()->SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE);
- break;
- default: {
- NYql::TIssues issues;
- issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, "Unexpected query mode"));
- return {Ydb::StatusIds::BAD_REQUEST, std::move(issues)};
- }
- }
+ switch (req.query_case()) {
+ case Ydb::Query::ExecuteQueryRequest::kQueryContent:
+ if (!CheckQuery(req.query_content().text(), issues)) {
+ return false;
+ }
- kqpRequest.MutableRequest()->SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
- kqpRequest.MutableRequest()->SetKeepSession(false);
+ query = req.query_content().text();
+ syntax = req.query_content().syntax();
+ return true;
- if (req.has_tx_control()) {
- NYql::TIssues issues;
- if (!FillTxControl(req.tx_control(), *kqpRequest.MutableRequest()->MutableTxControl(), issues)) {
- return {Ydb::StatusIds::BAD_REQUEST, std::move(issues)};
- }
+ default:
+ issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, "Unexpected query option"));
+ return false;
}
+}
- NYql::TIssues issues;
- if (!FillQueryContent(req, kqpRequest, issues)) {
- return {Ydb::StatusIds::BAD_REQUEST, std::move(issues)};
- }
+bool NeedReportStats(const Ydb::Query::ExecuteQueryRequest& req) {
+ switch (req.exec_mode()) {
+ case Ydb::Query::EXEC_MODE_EXPLAIN:
+ return true;
- kqpRequest.MutableRequest()->SetCollectStats(GetCollectStatsMode(req.stats_mode()));
+ case Ydb::Query::EXEC_MODE_EXECUTE:
+ switch (req.stats_mode()) {
+ case Ydb::Query::StatsMode::STATS_MODE_BASIC:
+ case Ydb::Query::StatsMode::STATS_MODE_FULL:
+ case Ydb::Query::StatsMode::STATS_MODE_PROFILE:
+ return true;
+ default:
+ return false;
+ }
- return {Ydb::StatusIds::SUCCESS, {}};
+ default:
+ return false;
+ }
}
class TExecuteQueryRPC : public TActorBootstrapped<TExecuteQueryRPC> {
@@ -255,22 +237,43 @@ private:
const auto req = Request_->GetProtoRequest();
const auto traceId = Request_->GetTraceId();
- auto ev = MakeHolder<NKqp::TEvKqp::TEvQueryRequest>();
- SetAuthToken(ev, *Request_);
- SetDatabase(ev, *Request_);
- SetRlPath(ev, *Request_);
-
- if (traceId) {
- ev->Record.SetTraceId(traceId.GetRef());
+ NYql::TIssues issues;
+ NKikimrKqp::EQueryAction queryAction;
+ if (!ParseQueryAction(*req, queryAction, issues)) {
+ return ReplyFinishStream(Ydb::StatusIds::BAD_REQUEST, std::move(issues));
}
- ActorIdToProto(this->SelfId(), ev->Record.MutableRequestActorId());
+ TString query;
+ Ydb::Query::Syntax syntax;
+ if (!ParseQueryContent(*req, query, syntax, issues)) {
+ return ReplyFinishStream(Ydb::StatusIds::BAD_REQUEST, std::move(issues));
+ }
- auto [fillStatus, fillIssues] = FillKqpRequest(*req, ev->Record);
- if (fillStatus != Ydb::StatusIds::SUCCESS) {
- return ReplyFinishStream(fillStatus, std::move(fillIssues));
+ Ydb::Table::TransactionControl* txControl = nullptr;
+ if (req->has_tx_control()) {
+ txControl = google::protobuf::Arena::CreateMessage<Ydb::Table::TransactionControl>(Request_->GetArena());
+ if (!FillTxControl(req->tx_control(), *txControl, issues)) {
+ return ReplyFinishStream(Ydb::StatusIds::BAD_REQUEST, std::move(issues));
+ }
}
+ auto ev = MakeHolder<NKqp::TEvKqp::TEvQueryRequest>(
+ queryAction,
+ NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY,
+ SelfId(),
+ Request_,
+ "", // sessionId
+ std::move(query),
+ "", // queryId
+ txControl,
+ &req->parameters(),
+ GetCollectStatsMode(req->stats_mode()),
+ nullptr, // queryCachePolicy
+ nullptr, // operationParams
+ false, // keepSession
+ false, // useCancelAfter
+ syntax);
+
if (!ctx.Send(NKqp::MakeKqpProxyID(ctx.SelfID.NodeId()), ev.Release())) {
NYql::TIssues issues;
issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, "Internal error"));
@@ -445,7 +448,7 @@ private:
};
private:
- std::unique_ptr<TEvExecuteQueryRequest> Request_;
+ std::shared_ptr<TEvExecuteQueryRequest> Request_;
TRpcFlowControlState FlowControl_;
TMap<TActorId, TProducerState> StreamProducers_;
diff --git a/ydb/core/kqp/common/events/query.h b/ydb/core/kqp/common/events/query.h
index 7aca7f6fb1..b9e101f262 100644
--- a/ydb/core/kqp/common/events/query.h
+++ b/ydb/core/kqp/common/events/query.h
@@ -32,7 +32,8 @@ public:
const ::Ydb::Table::QueryCachePolicy* queryCachePolicy,
const ::Ydb::Operations::OperationParams* operationParams,
bool keepSession = false,
- bool useCancelAfter = true);
+ bool useCancelAfter = true,
+ const ::Ydb::Query::Syntax syntax = Ydb::Query::Syntax::SYNTAX_UNSPECIFIED);
TEvQueryRequest() = default;
@@ -98,6 +99,10 @@ public:
return RequestCtx ? QueryType : Record.GetRequest().GetType();
}
+ Ydb::Query::Syntax GetSyntax() const {
+ return RequestCtx ? Syntax : Record.GetRequest().GetSyntax();
+ }
+
bool HasPreparedQuery() const {
return RequestCtx ? QueryId.size() > 0 : Record.GetRequest().HasPreparedQuery();
}
@@ -286,6 +291,7 @@ private:
bool KeepSession = false;
TDuration OperationTimeout;
TDuration CancelAfter;
+ const ::Ydb::Query::Syntax Syntax = Ydb::Query::Syntax::SYNTAX_UNSPECIFIED;
};
struct TEvDataQueryStreamPart: public TEventPB<TEvDataQueryStreamPart,
diff --git a/ydb/core/kqp/common/kqp_event_impl.cpp b/ydb/core/kqp/common/kqp_event_impl.cpp
index 4c70e55e92..9c94ee51a2 100644
--- a/ydb/core/kqp/common/kqp_event_impl.cpp
+++ b/ydb/core/kqp/common/kqp_event_impl.cpp
@@ -19,7 +19,8 @@ TEvKqp::TEvQueryRequest::TEvQueryRequest(
const ::Ydb::Table::QueryCachePolicy* queryCachePolicy,
const ::Ydb::Operations::OperationParams* operationParams,
bool keepSession,
- bool useCancelAfter)
+ bool useCancelAfter,
+ const ::Ydb::Query::Syntax syntax)
: RequestCtx(ctx)
, RequestActorId(requestActorId)
, Database(CanonizePath(ctx->GetDatabaseName().GetOrElse("")))
@@ -34,6 +35,7 @@ TEvKqp::TEvQueryRequest::TEvQueryRequest(
, QueryCachePolicy(queryCachePolicy)
, HasOperationParams(operationParams)
, KeepSession(keepSession)
+ , Syntax(syntax)
{
if (HasOperationParams) {
OperationTimeout = GetDuration(operationParams->operation_timeout());
@@ -88,6 +90,7 @@ void TEvKqp::TEvQueryRequest::PrepareRemote() const {
Record.MutableRequest()->SetSessionId(SessionId);
Record.MutableRequest()->SetAction(QueryAction);
Record.MutableRequest()->SetType(QueryType);
+ Record.MutableRequest()->SetSyntax(Syntax);
if (HasOperationParams) {
Record.MutableRequest()->SetCancelAfterMs(CancelAfter.MilliSeconds());
Record.MutableRequest()->SetTimeoutMs(OperationTimeout.MilliSeconds());
diff --git a/ydb/core/kqp/common/simple/query_id.cpp b/ydb/core/kqp/common/simple/query_id.cpp
index 8ec1ace922..a05d22e71f 100644
--- a/ydb/core/kqp/common/simple/query_id.cpp
+++ b/ydb/core/kqp/common/simple/query_id.cpp
@@ -11,14 +11,15 @@
namespace NKikimr::NKqp {
-TKqpQueryId::TKqpQueryId(const TString& cluster, const TString& database, const TString& text, NKikimrKqp::EQueryType type, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameterTypes)
+TKqpQueryId::TKqpQueryId(const TString& cluster, const TString& database, const TString& text,
+ const TKqpQuerySettings& settings, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameterTypes)
: Cluster(cluster)
, Database(database)
, Text(text)
- , QueryType(type)
+ , Settings(settings)
, QueryParameterTypes(queryParameterTypes)
{
- switch (QueryType) {
+ switch (Settings.QueryType) {
case NKikimrKqp::QUERY_TYPE_SQL_DML:
case NKikimrKqp::QUERY_TYPE_SQL_SCAN:
case NKikimrKqp::QUERY_TYPE_AST_DML:
@@ -33,7 +34,7 @@ TKqpQueryId::TKqpQueryId(const TString& cluster, const TString& database, const
}
bool TKqpQueryId::IsSql() const {
- return IsSqlQuery(QueryType);
+ return IsSqlQuery(Settings.QueryType);
}
bool TKqpQueryId::operator==(const TKqpQueryId& other) const {
@@ -42,7 +43,6 @@ bool TKqpQueryId::operator==(const TKqpQueryId& other) const {
UserSid == other.UserSid &&
Text == other.Text &&
Settings == other.Settings &&
- QueryType == other.QueryType &&
!QueryParameterTypes == !other.QueryParameterTypes)) {
return false;
}
diff --git a/ydb/core/kqp/common/simple/query_id.h b/ydb/core/kqp/common/simple/query_id.h
index 9d96672577..41e36b2a0d 100644
--- a/ydb/core/kqp/common/simple/query_id.h
+++ b/ydb/core/kqp/common/simple/query_id.h
@@ -1,6 +1,5 @@
#pragma once
#include "settings.h"
-#include <ydb/core/protos/kqp.pb.h>
#include <ydb/public/api/protos/ydb_value.pb.h>
#include <util/generic/string.h>
@@ -16,11 +15,12 @@ struct TKqpQueryId {
TString UserSid;
TString Text;
TKqpQuerySettings Settings;
- NKikimrKqp::EQueryType QueryType;
+
std::shared_ptr<std::map<TString, Ydb::Type>> QueryParameterTypes;
public:
- TKqpQueryId(const TString& cluster, const TString& database, const TString& text, NKikimrKqp::EQueryType type, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameterTypes);
+ TKqpQueryId(const TString& cluster, const TString& database, const TString& text,
+ const TKqpQuerySettings& settings, std::shared_ptr<std::map<TString, Ydb::Type>> queryParameterTypes);
bool IsSql() const;
@@ -36,7 +36,8 @@ public:
bool operator>=(const TKqpQueryId&) = delete;
size_t GetHash() const noexcept {
- auto tuple = std::make_tuple(Cluster, Database, UserSid, Text, Settings, QueryType, QueryParameterTypes ? QueryParameterTypes->size() : 0u);
+ auto tuple = std::make_tuple(Cluster, Database, UserSid, Text, Settings,
+ QueryParameterTypes ? QueryParameterTypes->size() : 0u);
return THash<decltype(tuple)>()(tuple);
}
};
diff --git a/ydb/core/kqp/common/simple/settings.h b/ydb/core/kqp/common/simple/settings.h
index 2882c736dc..cee8a624cb 100644
--- a/ydb/core/kqp/common/simple/settings.h
+++ b/ydb/core/kqp/common/simple/settings.h
@@ -1,17 +1,28 @@
#pragma once
-#include <tuple>
+
+#include <ydb/core/protos/kqp.pb.h>
+
#include <util/str_stl.h>
+#include <tuple>
+
namespace NKikimr::NKqp {
struct TKqpQuerySettings {
bool DocumentApiRestricted = true;
bool IsInternalCall = false;
+ NKikimrKqp::EQueryType QueryType = NKikimrKqp::EQueryType::QUERY_TYPE_UNDEFINED;
+ Ydb::Query::Syntax Syntax = Ydb::Query::Syntax::SYNTAX_UNSPECIFIED;
+
+ explicit TKqpQuerySettings(NKikimrKqp::EQueryType queryType)
+ : QueryType(queryType) {}
bool operator==(const TKqpQuerySettings& other) const {
return
DocumentApiRestricted == other.DocumentApiRestricted &&
- IsInternalCall == other.IsInternalCall;
+ IsInternalCall == other.IsInternalCall &&
+ QueryType == other.QueryType &&
+ Syntax == other.Syntax;
}
bool operator!=(const TKqpQuerySettings& other) {
@@ -24,7 +35,7 @@ struct TKqpQuerySettings {
bool operator>=(const TKqpQuerySettings&) = delete;
size_t GetHash() const noexcept {
- auto tuple = std::make_tuple(DocumentApiRestricted, IsInternalCall);
+ auto tuple = std::make_tuple(DocumentApiRestricted, IsInternalCall, QueryType, Syntax);
return THash<decltype(tuple)>()(tuple);
}
};
diff --git a/ydb/core/kqp/compile_service/kqp_compile_actor.cpp b/ydb/core/kqp/compile_service/kqp_compile_actor.cpp
index a1fedcc1cd..7b1697daa8 100644
--- a/ydb/core/kqp/compile_service/kqp_compile_actor.cpp
+++ b/ydb/core/kqp/compile_service/kqp_compile_actor.cpp
@@ -110,9 +110,23 @@ public:
prepareSettings.DocumentApiRestricted = QueryId.Settings.DocumentApiRestricted;
prepareSettings.IsInternalCall = QueryId.Settings.IsInternalCall;
+ switch (QueryId.Settings.Syntax) {
+ case Ydb::Query::Syntax::SYNTAX_YQL_V1:
+ prepareSettings.UsePgParser = false;
+ prepareSettings.SyntaxVersion = 1;
+ break;
+
+ case Ydb::Query::Syntax::SYNTAX_PG:
+ prepareSettings.UsePgParser = true;
+ break;
+
+ default:
+ break;
+ }
+
NCpuTime::TCpuTimer timer(CompileCpuTime);
- switch (QueryId.QueryType) {
+ switch (QueryId.Settings.QueryType) {
case NKikimrKqp::QUERY_TYPE_SQL_DML:
AsyncCompileResult = KqpHost->PrepareDataQuery(QueryRef, prepareSettings);
break;
@@ -135,7 +149,7 @@ public:
break;
default:
- YQL_ENSURE(false, "Unexpected query type: " << QueryId.QueryType);
+ YQL_ENSURE(false, "Unexpected query type: " << QueryId.Settings.QueryType);
}
Continue(ctx);
@@ -202,7 +216,7 @@ private:
replayMessage.InsertValue("query_database", QueryId.Database);
replayMessage.InsertValue("query_cluster", QueryId.Cluster);
replayMessage.InsertValue("query_plan", queryPlan);
- replayMessage.InsertValue("query_type", ToString(QueryId.QueryType));
+ replayMessage.InsertValue("query_type", ToString(QueryId.Settings.QueryType));
TString message(NJson::WriteJson(replayMessage, /*formatOutput*/ false));
LOG_DEBUG_S(*TlsActivationContext, NKikimrServices::KQP_COMPILE_ACTOR, "[" << SelfId() << "]: "
<< "Built the replay message " << message);
@@ -283,7 +297,7 @@ private:
ETableReadType maxReadType = ExtractMostHeavyReadType(kqpResult.QueryPlan);
- auto queryType = QueryId.QueryType;
+ auto queryType = QueryId.Settings.QueryType;
KqpCompileResult = TKqpCompileResult::Make(Uid, std::move(QueryId), status, kqpResult.Issues(), maxReadType);
diff --git a/ydb/core/kqp/host/kqp_host.cpp b/ydb/core/kqp/host/kqp_host.cpp
index e094aab28d..05ac8c6e20 100644
--- a/ydb/core/kqp/host/kqp_host.cpp
+++ b/ydb/core/kqp/host/kqp_host.cpp
@@ -34,8 +34,6 @@ using namespace NYql::NCommon;
using namespace NYql::NNodes;
using namespace NThreading;
-using TSqlVersion = ui16;
-
namespace {
void AddQueryStats(NKqpProto::TKqpStatsQuery& total, NKqpProto::TKqpStatsQuery&& stats) {
@@ -1050,11 +1048,14 @@ public:
private:
TExprNode::TPtr CompileQuery(const TKqpQueryRef& query, bool isSql, bool sqlAutoCommit, TExprContext& ctx,
- TMaybe<TSqlVersion>& sqlVersion) const
+ TMaybe<TSqlVersion>& sqlVersion, const TMaybe<bool>& usePgParser) const
{
TAstParseResult astRes;
if (isSql) {
NSQLTranslation::TTranslationSettings settings{};
+ if (usePgParser) {
+ settings.PgParser = *usePgParser;
+ }
if (sqlVersion) {
settings.SyntaxVersion = *sqlVersion;
@@ -1137,9 +1138,9 @@ private:
}
TExprNode::TPtr CompileYqlQuery(const TKqpQueryRef& query, bool isSql, bool sqlAutoCommit, TExprContext& ctx,
- TMaybe<TSqlVersion>& sqlVersion) const
+ TMaybe<TSqlVersion>& sqlVersion, const TMaybe<bool>& usePgParser) const
{
- auto queryExpr = CompileQuery(query, isSql, sqlAutoCommit, ctx, sqlVersion);
+ auto queryExpr = CompileQuery(query, isSql, sqlAutoCommit, ctx, sqlVersion, usePgParser);
if (!queryExpr) {
return nullptr;
}
@@ -1211,7 +1212,7 @@ private:
}
TMaybe<TSqlVersion> sqlVersion;
- auto queryExpr = CompileYqlQuery(query, isSql, false, ctx, sqlVersion);
+ auto queryExpr = CompileYqlQuery(query, isSql, false, ctx, sqlVersion, {});
if (!queryExpr) {
return nullptr;
}
@@ -1265,7 +1266,7 @@ private:
}
TMaybe<TSqlVersion> sqlVersion;
- auto queryExpr = CompileYqlQuery(query, /* isSql */ true, /* sqlAutoCommit */ false, ctx, sqlVersion);
+ auto queryExpr = CompileYqlQuery(query, /* isSql */ true, /* sqlAutoCommit */ false, ctx, sqlVersion, {});
if (!queryExpr) {
return nullptr;
}
@@ -1290,7 +1291,7 @@ private:
}
TMaybe<TSqlVersion> sqlVersion;
- auto queryExpr = CompileYqlQuery(queryAst, false, false, ctx, sqlVersion);
+ auto queryExpr = CompileYqlQuery(queryAst, false, false, ctx, sqlVersion, {});
if (!queryExpr) {
return nullptr;
}
@@ -1301,8 +1302,8 @@ private:
SessionCtx, *ExecuteCtx);
}
- IAsyncQueryResultPtr PrepareQueryInternal(const TKqpQueryRef& query, EKikimrQueryType queryType, const TPrepareSettings& settings,
- TExprContext& ctx)
+ IAsyncQueryResultPtr PrepareQueryInternal(const TKqpQueryRef& query, EKikimrQueryType queryType,
+ const TPrepareSettings& settings, TExprContext& ctx)
{
SetupYqlTransformer(queryType);
@@ -1315,9 +1316,13 @@ private:
SessionCtx->Query().IsInternalCall = *settings.IsInternalCall;
}
- // TODO: Support PG
- TMaybe<TSqlVersion> sqlVersion = 1;
- auto queryExpr = CompileYqlQuery(query, /* isSql */ true, /* sqlAutoCommit */ false, ctx, sqlVersion);
+ TMaybe<TSqlVersion> sqlVersion = settings.SyntaxVersion;
+ if (!sqlVersion) {
+ sqlVersion = 1;
+ }
+
+ auto queryExpr = CompileYqlQuery(query, /* isSql */ true, /* sqlAutoCommit */ false, ctx, sqlVersion,
+ settings.UsePgParser);
if (!queryExpr) {
return nullptr;
}
@@ -1334,7 +1339,9 @@ private:
: PrepareScanQueryAstInternal(query, ctx);
}
- IAsyncQueryResultPtr PrepareScanQueryInternal(const TKqpQueryRef& query, TExprContext& ctx, EKikimrStatsMode statsMode = EKikimrStatsMode::None) {
+ IAsyncQueryResultPtr PrepareScanQueryInternal(const TKqpQueryRef& query, TExprContext& ctx,
+ EKikimrStatsMode statsMode = EKikimrStatsMode::None)
+ {
SetupYqlTransformer(EKikimrQueryType::Scan);
SessionCtx->Query().PrepareOnly = true;
@@ -1342,7 +1349,7 @@ private:
SessionCtx->Query().PreparingQuery = std::make_unique<NKikimrKqp::TPreparedQuery>();
TMaybe<TSqlVersion> sqlVersion = 1;
- auto queryExpr = CompileYqlQuery(query, true, false, ctx, sqlVersion);
+ auto queryExpr = CompileYqlQuery(query, true, false, ctx, sqlVersion, {});
if (!queryExpr) {
return nullptr;
}
@@ -1359,7 +1366,7 @@ private:
SessionCtx->Query().PreparingQuery = std::make_unique<NKikimrKqp::TPreparedQuery>();
TMaybe<TSqlVersion> sqlVersion;
- auto queryExpr = CompileYqlQuery(queryAst, false, false, ctx, sqlVersion);
+ auto queryExpr = CompileYqlQuery(queryAst, false, false, ctx, sqlVersion, {});
if (!queryExpr) {
return nullptr;
}
@@ -1381,7 +1388,7 @@ private:
SessionCtx->Query().PreparedQuery.reset();
TMaybe<TSqlVersion> sqlVersion;
- auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion);
+ auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion, {});
if (!scriptExpr) {
return nullptr;
}
@@ -1407,7 +1414,7 @@ private:
SessionCtx->Query().PreparedQuery.reset();
TMaybe<TSqlVersion> sqlVersion;
- auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion);
+ auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion, {});
if (!scriptExpr) {
return nullptr;
}
@@ -1429,7 +1436,7 @@ private:
SessionCtx->Query().PreparedQuery.reset();
TMaybe<TSqlVersion> sqlVersion;
- auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion);
+ auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion, {});
if (!scriptExpr) {
return nullptr;
}
@@ -1453,7 +1460,7 @@ private:
SessionCtx->Query().PreparingQuery = std::make_unique<NKikimrKqp::TPreparedQuery>();
TMaybe<TSqlVersion> sqlVersion;
- auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion);
+ auto scriptExpr = CompileYqlQuery(script, true, true, ctx, sqlVersion, {});
if (!scriptExpr) {
return nullptr;
}
diff --git a/ydb/core/kqp/host/kqp_host.h b/ydb/core/kqp/host/kqp_host.h
index a599f88178..799c929bd5 100644
--- a/ydb/core/kqp/host/kqp_host.h
+++ b/ydb/core/kqp/host/kqp_host.h
@@ -10,6 +10,8 @@ namespace NKqp {
struct TKqpQueryRef;
+using TSqlVersion = ui16;
+
class IKqpHost : public TThrRefBase {
public:
using TQueryResult = IKqpGateway::TQueryResult;
@@ -29,6 +31,8 @@ public:
struct TPrepareSettings: public TExecSettings {
TMaybe<bool> IsInternalCall;
+ TMaybe<bool> UsePgParser;
+ TMaybe<TSqlVersion> SyntaxVersion;
TString ToString() const {
return TStringBuilder() << "TPrepareSettings{ DocumentApiRestricted: " << DocumentApiRestricted << " IsInternalCall: " << IsInternalCall << " }";
diff --git a/ydb/core/kqp/session_actor/kqp_query_state.cpp b/ydb/core/kqp/session_actor/kqp_query_state.cpp
index d2499049f7..855ffb15fe 100644
--- a/ydb/core/kqp/session_actor/kqp_query_state.cpp
+++ b/ydb/core/kqp/session_actor/kqp_query_state.cpp
@@ -124,15 +124,20 @@ std::unique_ptr<TEvKqp::TEvCompileRequest> TKqpQueryState::BuildCompileRequest()
TMaybe<TKqpQueryId> query;
TMaybe<TString> uid;
+ TKqpQuerySettings settings(GetType());
+ settings.DocumentApiRestricted = IsDocumentApiRestricted_;
+ settings.IsInternalCall = IsInternalCall();
+ settings.Syntax = GetSyntax();
+
bool keepInCache = false;
switch (GetAction()) {
case NKikimrKqp::QUERY_ACTION_EXECUTE:
- query = TKqpQueryId(Cluster, Database, GetQuery(), GetType(), GetQueryParameterTypes());
+ query = TKqpQueryId(Cluster, Database, GetQuery(), settings, GetQueryParameterTypes());
keepInCache = GetQueryKeepInCache() && query->IsSql();
break;
case NKikimrKqp::QUERY_ACTION_PREPARE:
- query = TKqpQueryId(Cluster, Database, GetQuery(), GetType(), GetQueryParameterTypes());
+ query = TKqpQueryId(Cluster, Database, GetQuery(), settings, GetQueryParameterTypes());
keepInCache = query->IsSql();
break;
@@ -142,7 +147,7 @@ std::unique_ptr<TEvKqp::TEvCompileRequest> TKqpQueryState::BuildCompileRequest()
break;
case NKikimrKqp::QUERY_ACTION_EXPLAIN:
- query = TKqpQueryId(Cluster, Database, GetQuery(), GetType(), GetQueryParameterTypes());
+ query = TKqpQueryId(Cluster, Database, GetQuery(), settings, GetQueryParameterTypes());
keepInCache = false;
break;
@@ -150,11 +155,6 @@ std::unique_ptr<TEvKqp::TEvCompileRequest> TKqpQueryState::BuildCompileRequest()
YQL_ENSURE(false);
}
- if (query) {
- query->Settings.DocumentApiRestricted = IsDocumentApiRestricted_;
- query->Settings.IsInternalCall = IsInternalCall();
- }
-
auto compileDeadline = QueryDeadlines.TimeoutAt;
if (QueryDeadlines.CancelAt) {
compileDeadline = Min(compileDeadline, QueryDeadlines.CancelAt);
@@ -169,13 +169,18 @@ std::unique_ptr<TEvKqp::TEvRecompileRequest> TKqpQueryState::BuildReCompileReque
TMaybe<TKqpQueryId> query;
TMaybe<TString> uid;
+ TKqpQuerySettings settings(GetType());
+ settings.DocumentApiRestricted = IsDocumentApiRestricted_;
+ settings.IsInternalCall = IsInternalCall();
+ settings.Syntax = GetSyntax();
+
switch (GetAction()) {
case NKikimrKqp::QUERY_ACTION_EXECUTE:
- query = TKqpQueryId(Cluster, Database, GetQuery(), GetType(), GetQueryParameterTypes());
+ query = TKqpQueryId(Cluster, Database, GetQuery(), settings, GetQueryParameterTypes());
break;
case NKikimrKqp::QUERY_ACTION_PREPARE:
- query = TKqpQueryId(Cluster, Database, GetQuery(), GetType(), GetQueryParameterTypes());
+ query = TKqpQueryId(Cluster, Database, GetQuery(), settings, GetQueryParameterTypes());
break;
case NKikimrKqp::QUERY_ACTION_EXECUTE_PREPARED:
@@ -186,11 +191,6 @@ std::unique_ptr<TEvKqp::TEvRecompileRequest> TKqpQueryState::BuildReCompileReque
YQL_ENSURE(false);
}
- if (query) {
- query->Settings.DocumentApiRestricted = IsDocumentApiRestricted_;
- query->Settings.IsInternalCall = IsInternalCall();
- }
-
auto compileDeadline = QueryDeadlines.TimeoutAt;
if (QueryDeadlines.CancelAt) {
compileDeadline = Min(compileDeadline, QueryDeadlines.CancelAt);
diff --git a/ydb/core/kqp/session_actor/kqp_query_state.h b/ydb/core/kqp/session_actor/kqp_query_state.h
index 630f6e0a08..d086bc3c2d 100644
--- a/ydb/core/kqp/session_actor/kqp_query_state.h
+++ b/ydb/core/kqp/session_actor/kqp_query_state.h
@@ -128,6 +128,10 @@ public:
return RequestEv->GetType();
}
+ Ydb::Query::Syntax GetSyntax() const {
+ return RequestEv->GetSyntax();
+ }
+
std::shared_ptr<std::map<TString, Ydb::Type>> GetQueryParameterTypes() const {
return QueryParameterTypes;
}
diff --git a/ydb/core/kqp/ut/service/CMakeLists.darwin-x86_64.txt b/ydb/core/kqp/ut/service/CMakeLists.darwin-x86_64.txt
index 5b38139270..4ccaedc03a 100644
--- a/ydb/core/kqp/ut/service/CMakeLists.darwin-x86_64.txt
+++ b/ydb/core/kqp/ut/service/CMakeLists.darwin-x86_64.txt
@@ -22,7 +22,7 @@ target_link_libraries(ydb-core-kqp-ut-service PUBLIC
ydb-core-kqp
cpp-threading-local_executor
kqp-ut-common
- yql-sql-pg_dummy
+ yql-sql-pg
cpp-client-ydb_operation
client-ydb_types-operation
)
diff --git a/ydb/core/kqp/ut/service/CMakeLists.linux-aarch64.txt b/ydb/core/kqp/ut/service/CMakeLists.linux-aarch64.txt
index 82dc731331..2dbc0e745e 100644
--- a/ydb/core/kqp/ut/service/CMakeLists.linux-aarch64.txt
+++ b/ydb/core/kqp/ut/service/CMakeLists.linux-aarch64.txt
@@ -22,7 +22,7 @@ target_link_libraries(ydb-core-kqp-ut-service PUBLIC
ydb-core-kqp
cpp-threading-local_executor
kqp-ut-common
- yql-sql-pg_dummy
+ yql-sql-pg
cpp-client-ydb_operation
client-ydb_types-operation
)
diff --git a/ydb/core/kqp/ut/service/CMakeLists.linux-x86_64.txt b/ydb/core/kqp/ut/service/CMakeLists.linux-x86_64.txt
index fdc9841ec6..2fc3af90dc 100644
--- a/ydb/core/kqp/ut/service/CMakeLists.linux-x86_64.txt
+++ b/ydb/core/kqp/ut/service/CMakeLists.linux-x86_64.txt
@@ -23,7 +23,7 @@ target_link_libraries(ydb-core-kqp-ut-service PUBLIC
ydb-core-kqp
cpp-threading-local_executor
kqp-ut-common
- yql-sql-pg_dummy
+ yql-sql-pg
cpp-client-ydb_operation
client-ydb_types-operation
)
diff --git a/ydb/core/kqp/ut/service/CMakeLists.windows-x86_64.txt b/ydb/core/kqp/ut/service/CMakeLists.windows-x86_64.txt
index b994d19665..4cb934efc3 100644
--- a/ydb/core/kqp/ut/service/CMakeLists.windows-x86_64.txt
+++ b/ydb/core/kqp/ut/service/CMakeLists.windows-x86_64.txt
@@ -22,7 +22,7 @@ target_link_libraries(ydb-core-kqp-ut-service PUBLIC
ydb-core-kqp
cpp-threading-local_executor
kqp-ut-common
- yql-sql-pg_dummy
+ yql-sql-pg
cpp-client-ydb_operation
client-ydb_types-operation
)
diff --git a/ydb/core/kqp/ut/service/kqp_query_service_ut.cpp b/ydb/core/kqp/ut/service/kqp_query_service_ut.cpp
index 75719c99f5..86b597ba16 100644
--- a/ydb/core/kqp/ut/service/kqp_query_service_ut.cpp
+++ b/ydb/core/kqp/ut/service/kqp_query_service_ut.cpp
@@ -97,6 +97,29 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
])", FormatResultSetYson(result.GetResultSet(0)));
}
+ Y_UNIT_TEST(ExecuteQueryPg) {
+ auto kikimr = DefaultKikimrRunner();
+ auto db = kikimr.GetQueryClient();
+
+ auto settings = TExecuteQuerySettings()
+ .Syntax(ESyntax::Pg);
+
+ auto result = db.ExecuteQuery(R"(
+ SELECT * FROM (VALUES
+ (1::int8, 'one'),
+ (2::int8, 'two'),
+ (3::int8, 'three')
+ ) AS t;
+ )", TTxControl::BeginTx().CommitTx(), settings).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
+
+ CompareYson(R"([
+ ["1";"one"];
+ ["2";"two"];
+ ["3";"three"]
+ ])", FormatResultSetYson(result.GetResultSet(0)));
+ }
+
Y_UNIT_TEST(ExecuteQueryScalar) {
auto kikimr = DefaultKikimrRunner();
auto db = kikimr.GetQueryClient();
diff --git a/ydb/core/protos/kqp.proto b/ydb/core/protos/kqp.proto
index 6b29828fec..876d6de11b 100644
--- a/ydb/core/protos/kqp.proto
+++ b/ydb/core/protos/kqp.proto
@@ -12,6 +12,7 @@ import "ydb/public/api/protos/ydb_table.proto";
import "ydb/public/api/protos/ydb_value.proto";
import "ydb/public/api/protos/ydb_issue_message.proto";
import "ydb/public/api/protos/ydb_topic.proto";
+import "ydb/public/api/protos/draft/ydb_query.proto";
import "ydb/library/mkql_proto/protos/minikql.proto";
import "ydb/library/yql/dq/actors/protos/dq_events.proto";
import "ydb/library/yql/dq/actors/protos/dq_stats.proto";
@@ -99,6 +100,7 @@ message TQueryRequest {
optional bool UsePublicResponseDataFormat = 23;
map<string, Ydb.TypedValue> YdbParameters = 24;
optional bool IsInternalCall = 25;
+ optional Ydb.Query.Syntax Syntax = 26;
}
message TKqpPathIdProto {
diff --git a/ydb/public/sdk/cpp/client/draft/ydb_query/impl/exec_query.cpp b/ydb/public/sdk/cpp/client/draft/ydb_query/impl/exec_query.cpp
index 357c60ed12..8cb5e7e60f 100644
--- a/ydb/public/sdk/cpp/client/draft/ydb_query/impl/exec_query.cpp
+++ b/ydb/public/sdk/cpp/client/draft/ydb_query/impl/exec_query.cpp
@@ -188,6 +188,7 @@ TFuture<std::pair<TPlainStatus, TExecuteQueryProcessorPtr>> StreamExecuteQueryIm
request.set_exec_mode(::Ydb::Query::ExecMode(settings.ExecMode_));
request.set_stats_mode(::Ydb::Query::StatsMode(settings.StatsMode_));
request.mutable_query_content()->set_text(query);
+ request.mutable_query_content()->set_syntax(::Ydb::Query::Syntax(settings.Syntax_));
if (txControl.HasTx()) {
auto requestTxControl = request.mutable_tx_control();
diff --git a/ydb/public/sdk/cpp/client/draft/ydb_query/query.h b/ydb/public/sdk/cpp/client/draft/ydb_query/query.h
index 6e1a925ba1..790157bde2 100644
--- a/ydb/public/sdk/cpp/client/draft/ydb_query/query.h
+++ b/ydb/public/sdk/cpp/client/draft/ydb_query/query.h
@@ -95,6 +95,7 @@ private:
using TAsyncExecuteQueryIterator = NThreading::TFuture<TExecuteQueryIterator>;
struct TExecuteQuerySettings : public TRequestSettings<TExecuteQuerySettings> {
+ FLUENT_SETTING_DEFAULT(ESyntax, Syntax, ESyntax::YqlV1);
FLUENT_SETTING_DEFAULT(EExecMode, ExecMode, EExecMode::Execute);
FLUENT_SETTING_DEFAULT(EStatsMode, StatsMode, EStatsMode::None);
};