Skip to content

Explicit SQL translators in KQP #14611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ydb/core/kqp/host/kqp_translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <ydb/core/kqp/provider/yql_kikimr_results.h>
#include <yql/essentials/sql/sql.h>
#include <yql/essentials/sql/v0/sql.h>
#include <yql/essentials/sql/v1/sql.h>
#include <yql/essentials/parser/pg_wrapper/interface/parser.h>
#include <ydb/public/api/protos/ydb_query.pb.h>


Expand Down Expand Up @@ -288,7 +291,14 @@ NYql::TAstParseResult ParseQuery(const TString& queryText, bool isSql, TMaybe<ui
TKqpAutoParamBuilderFactory autoParamBuilderFactory;
settings.AutoParamBuilderFactory = &autoParamBuilderFactory;
NYql::TStmtParseInfo stmtParseInfo;
auto ast = NSQLTranslation::SqlToYql(queryText, settings, nullptr, &stmtParseInfo, effectiveSettings);

NSQLTranslation::TTranslators translators(
NSQLTranslationV0::MakeTranslator(),
NSQLTranslationV1::MakeTranslator(),
NSQLTranslationPG::MakeTranslator()
);

auto ast = NSQLTranslation::SqlToYql(translators, queryText, settings, nullptr, &stmtParseInfo, effectiveSettings);
deprecatedSQL = (ast.ActualSyntaxType == NYql::ESyntaxType::YQLv0);
sqlVersion = ast.ActualSyntaxType == NYql::ESyntaxType::YQLv1 ? 1 : 0;
keepInCache = stmtParseInfo.KeepInCache;
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/kqp/host/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ PEERDIR(
yql/essentials/core/services
yql/essentials/minikql/invoke_builtins
yql/essentials/sql
yql/essentials/sql/v0
yql/essentials/sql/v1
yql/essentials/parser/pg_wrapper/interface
yql/essentials/core
yql/essentials/providers/common/codec
ydb/library/yql/dq/opt
Expand Down
9 changes: 8 additions & 1 deletion ydb/core/kqp/provider/rewrite_io_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <yql/essentials/providers/common/provider/yql_provider.h>
#include <yql/essentials/providers/common/provider/yql_provider_names.h>
#include <yql/essentials/sql/sql.h>
#include <yql/essentials/sql/v1/sql.h>
#include <yql/essentials/utils/log/log.h>

namespace NYql {
Expand All @@ -26,8 +27,14 @@ TExprNode::TPtr CompileViewQuery(
translationSettings.Mode = NSQLTranslation::ESqlMode::LIMITED_VIEW;
NSQLTranslation::Deserialize(viewData.CapturedContext, translationSettings);

NSQLTranslation::TTranslators translators(
nullptr,
NSQLTranslationV1::MakeTranslator(),
nullptr
);

TAstParseResult queryAst;
queryAst = NSQLTranslation::SqlToYql(viewData.QueryText, translationSettings);
queryAst = NSQLTranslation::SqlToYql(translators, viewData.QueryText, translationSettings);

ctx.IssueManager.AddIssues(queryAst.Issues);
if (!queryAst.IsOk()) {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/provider/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PEERDIR(
yql/essentials/providers/result/expr_nodes
yql/essentials/providers/result/provider
yql/essentials/sql
yql/essentials/sql/v1
ydb/library/ydb_issue/proto
yql/essentials/public/issue
yql/essentials/utils/log
Expand Down
9 changes: 8 additions & 1 deletion ydb/core/kqp/ut/view/view_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
#include <yql/essentials/sql/sql.h>
#include <yql/essentials/sql/v1/sql.h>
#include <yql/essentials/utils/log/log.h>
#include <ydb-cpp-sdk/client/proto/accessor.h>

Expand Down Expand Up @@ -198,7 +199,13 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
SELECT "foo" / "bar"
)";

const auto parsedAst = NSQLTranslation::SqlToYql(queryInView, {});
NSQLTranslation::TTranslators translators(
nullptr,
NSQLTranslationV1::MakeTranslator(),
nullptr
);

const auto parsedAst = NSQLTranslation::SqlToYql(translators, queryInView, {});
UNIT_ASSERT_C(parsedAst.IsOk(), parsedAst.Issues.ToString());

const TString creationQuery = std::format(R"(
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/ut/view/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SRCS(
PEERDIR(
ydb/core/kqp/ut/common
yql/essentials/sql
yql/essentials/sql/v1
yql/essentials/utils/log

ydb/core/testlib/basics/default
Expand Down
Loading