Просмотр исходного кода

refactor SQL translators YQL-19594
commit_hash:401d21dd23ee9bb7ee52b2fc42e596cb3e4bdda7

vvvv 3 недель назад
Родитель
Сommit
802da2736b

+ 8 - 1
yql/essentials/core/extract_predicate/ut/extract_predicate_ut.cpp

@@ -6,6 +6,7 @@
 #include <yql/essentials/providers/common/provider/yql_provider_names.h>
 #include <yql/essentials/sql/settings/translation_settings.h>
 #include <yql/essentials/sql/sql.h>
+#include <yql/essentials/sql/v1/sql.h>
 #include <yql/essentials/ast/yql_ast_annotation.h>
 #include <yql/essentials/ast/yql_expr.h>
 #include <yql/essentials/core/cbo/simple/cbo_simple.h>
@@ -53,7 +54,13 @@ Y_UNIT_TEST_SUITE(TYqlExtractPredicate) {
         NSQLTranslation::TTranslationSettings settings;
         settings.SyntaxVersion = 1;
 
-        TAstParseResult astRes = SqlToYql(program, settings);
+        NSQLTranslation::TTranslators translators(
+            nullptr,
+            NSQLTranslationV1::MakeTranslator(),
+            nullptr
+        );
+
+        TAstParseResult astRes = SqlToYql(translators, program, settings);
         UNIT_ASSERT(astRes.IsOk());
         TExprNode::TPtr exprRoot;
         UNIT_ASSERT(CompileExpr(*astRes.Root, exprRoot, exprCtx, nullptr, nullptr));

+ 2 - 0
yql/essentials/core/extract_predicate/ut/ya.make

@@ -21,6 +21,8 @@ PEERDIR(
     yql/essentials/minikql/invoke_builtins/llvm16
     yql/essentials/sql/pg
     yql/essentials/parser/pg_wrapper
+    yql/essentials/sql
+    yql/essentials/sql/v1
 )
 
 YQL_LAST_ABI_VERSION()

+ 2 - 0
yql/essentials/core/facade/ya.make

@@ -21,6 +21,8 @@ PEERDIR(
     yql/essentials/core/qplayer/storage/interface
     yql/essentials/core/qplayer/udf_resolver
     yql/essentials/sql
+    yql/essentials/sql/v1
+    yql/essentials/parser/pg_wrapper/interface
     yql/essentials/utils/log
     yql/essentials/core
     yql/essentials/core/type_ann

+ 10 - 1
yql/essentials/core/facade/yql_facade.cpp

@@ -10,6 +10,9 @@
 #include <yql/essentials/core/type_ann/type_ann_expr.h>
 #include <yql/essentials/core/services/yql_plan.h>
 #include <yql/essentials/core/services/yql_eval_params.h>
+#include <yql/essentials/sql/sql.h>
+#include <yql/essentials/sql/v1/sql.h>
+#include <yql/essentials/parser/pg_wrapper/interface/parser.h>
 #include <yql/essentials/utils/log/context.h>
 #include <yql/essentials/utils/log/profile.h>
 #include <yql/essentials/utils/limiting_allocator.h>
@@ -728,7 +731,13 @@ bool TProgram::ParseSql(const NSQLTranslation::TTranslationSettings& settings)
     }
 
     currentSettings->EmitReadsForExists = true;
-    return FillParseResult(SqlToYql(sourceCode, *currentSettings, &warningRules), &warningRules);
+    NSQLTranslation::TTranslators translators(
+        nullptr,
+        NSQLTranslationV1::MakeTranslator(),
+        NSQLTranslationPG::MakeTranslator()
+    );
+
+    return FillParseResult(SqlToYql(translators, sourceCode, *currentSettings, &warningRules), &warningRules);
 }
 
 bool TProgram::Compile(const TString& username, bool skipLibraries) {

+ 2 - 0
yql/essentials/core/services/mounts/ya.make

@@ -10,6 +10,8 @@ PEERDIR(
     yql/essentials/core/user_data
     yql/essentials/core
     yql/essentials/utils/log
+    yql/essentials/sql
+    yql/essentials/sql/v1
 )
 
 YQL_LAST_ABI_VERSION()

+ 10 - 2
yql/essentials/core/services/mounts/yql_mounts.cpp

@@ -1,6 +1,8 @@
 #include "yql_mounts.h"
 
 #include <yql/essentials/core/yql_library_compiler.h>
+#include <yql/essentials/sql/sql.h>
+#include <yql/essentials/sql/v1/sql.h>
 #include <yql/essentials/utils/log/profile.h>
 
 #include <library/cpp/resource/resource.h>
@@ -124,8 +126,14 @@ namespace NYql {
         TUserDataTable mounts;
         LoadYqlDefaultMounts(mounts);
 
+        NSQLTranslation::TTranslators translators(
+            nullptr,
+            NSQLTranslationV1::MakeTranslator(),
+            nullptr
+        );
+
         TModulesTable modulesTable;
-        if (!CompileLibraries(mounts, *ctx, modulesTable, optimizeLibraries)) {
+        if (!CompileLibraries(translators, mounts, *ctx, modulesTable, optimizeLibraries)) {
             return {};
         }
 
@@ -133,7 +141,7 @@ namespace NYql {
             AddUserDataToTable(mounts, item);
         }
 
-        moduleResolver = std::make_shared<TModuleResolver>(std::move(modulesTable), ctx->NextUniqueId,
+        moduleResolver = std::make_shared<TModuleResolver>(translators, std::move(modulesTable), ctx->NextUniqueId,
             clusterMapping, sqlFlags, optimizeLibraries, std::move(ownedCtx));
         return mounts;
     }

+ 2 - 0
yql/essentials/core/ut/ya.make

@@ -32,6 +32,8 @@ PEERDIR(
     yql/essentials/minikql/invoke_builtins/llvm16
     yql/essentials/parser/pg_wrapper
     yql/essentials/sql/pg
+    yql/essentials/sql
+    yql/essentials/sql/v1
     yql/essentials/udfs/common/string
 )
 

+ 24 - 3
yql/essentials/core/ut/yql_library_compiler_ut.cpp

@@ -2,6 +2,9 @@
 
 #include "yql_library_compiler.h"
 
+#include <yql/essentials/sql/sql.h>
+#include <yql/essentials/sql/v1/sql.h>
+
 namespace NYql {
 
 Y_UNIT_TEST_SUITE(TLibraryCompilerTests) {
@@ -9,9 +12,15 @@ Y_UNIT_TEST_SUITE(TLibraryCompilerTests) {
     static const char* alias = "/lib/ut.yql";
 
     static bool CompileAndLink(const THashMap<TString, TString>& libs, TExprContext& ctx) {
+        NSQLTranslation::TTranslators translators(
+            nullptr,
+            NSQLTranslationV1::MakeTranslator(),
+            nullptr
+        );
+
         THashMap<TString, TLibraryCohesion> compiled;
         for (const auto& lib : libs)
-            if (!CompileLibrary(alias, lib.second, ctx, compiled[lib.first]))
+            if (!CompileLibrary(translators, alias, lib.second, ctx, compiled[lib.first]))
                 return false;
 
         return LinkLibraries(compiled, ctx, ctx);
@@ -25,9 +34,15 @@ Y_UNIT_TEST_SUITE(TLibraryCompilerTests) {
             "(export X)\n"
             ")\n";
 
+        NSQLTranslation::TTranslators translators(
+            nullptr,
+            NSQLTranslationV1::MakeTranslator(),
+            nullptr
+        );
+
         TExprContext ctx;
         TLibraryCohesion cohesion;
-        UNIT_ASSERT(CompileLibrary(alias, s, ctx, cohesion));
+        UNIT_ASSERT(CompileLibrary(translators, alias, s, ctx, cohesion));
         UNIT_ASSERT_VALUES_EQUAL(2, cohesion.Exports.Symbols().size());
         UNIT_ASSERT(cohesion.Imports.empty());
     }
@@ -41,9 +56,15 @@ Y_UNIT_TEST_SUITE(TLibraryCompilerTests) {
             "(export ex)\n"
             ")\n";
 
+        NSQLTranslation::TTranslators translators(
+            nullptr,
+            NSQLTranslationV1::MakeTranslator(),
+            nullptr
+        );
+
         TExprContext ctx;
         TLibraryCohesion cohesion;
-        UNIT_ASSERT(CompileLibrary(alias, s, ctx, cohesion));
+        UNIT_ASSERT(CompileLibrary(translators, alias, s, ctx, cohesion));
         UNIT_ASSERT_VALUES_EQUAL(1, cohesion.Exports.Symbols().size());
         UNIT_ASSERT_VALUES_EQUAL(2, cohesion.Imports.size());
     }

+ 10 - 4
yql/essentials/core/yql_library_compiler.cpp

@@ -89,14 +89,15 @@ bool OptimizeLibrary(TLibraryCohesion& cohesion, TExprContext& ctx) {
     return true;
 }
 
-bool CompileLibrary(const TString& alias, const TString& script, TExprContext& ctx, TLibraryCohesion& cohesion, bool optimize)
+bool CompileLibrary(const NSQLTranslation::TTranslators& translators, const TString& alias,
+    const TString& script, TExprContext& ctx, TLibraryCohesion& cohesion, bool optimize)
 {
     TAstParseResult res;
     if (alias.EndsWith(".sql")) {
         NSQLTranslation::TTranslationSettings translationSettings;
         translationSettings.SyntaxVersion = 1;
         translationSettings.Mode = NSQLTranslation::ESqlMode::LIBRARY;
-        res = NSQLTranslation::SqlToYql(script, translationSettings);
+        res = NSQLTranslation::SqlToYql(translators, script, translationSettings);
     } else {
         res = ParseAst(script, nullptr, alias);
     }
@@ -198,7 +199,8 @@ bool LinkLibraries(THashMap<TString, TLibraryCohesion>& libs, TExprContext& ctx,
     return true;
 }
 
-bool CompileLibraries(const TUserDataTable& userData, TExprContext& ctx, TModulesTable& modules, bool optimize)
+bool CompileLibraries(const NSQLTranslation::TTranslators& translators, const TUserDataTable& userData,
+    TExprContext& ctx, TModulesTable& modules, bool optimize)
 {
     THashMap<TString, TLibraryCohesion> libs;
     for (const auto& data : userData) {
@@ -212,7 +214,7 @@ bool CompileLibraries(const TUserDataTable& userData, TExprContext& ctx, TModule
             }
 
             if (!libraryData.empty()) {
-                if (CompileLibrary(alias, libraryData, ctx, libs[alias], optimize))
+                if (CompileLibrary(translators, alias, libraryData, ctx, libs[alias], optimize))
                     modules[TModuleResolver::NormalizeModuleName(alias)] = libs[alias].Exports;
                 else
                     return false;
@@ -223,4 +225,8 @@ bool CompileLibraries(const TUserDataTable& userData, TExprContext& ctx, TModule
     return LinkLibraries(libs, ctx, ctx);
 }
 
+bool CompileLibraries(const TUserDataTable& userData, TExprContext& ctx, TModulesTable& modules, bool optimize) {
+    return CompileLibraries(NSQLTranslation::MakeAllTranslators(), userData, ctx, modules, optimize);
+}
+
 }

+ 6 - 1
yql/essentials/core/yql_library_compiler.h

@@ -2,14 +2,19 @@
 
 #include <yql/essentials/ast/yql_expr.h>
 #include "yql_type_annotation.h"
+#include <yql/essentials/sql/sql.h>
 
 namespace NYql {
 
 bool OptimizeLibrary(TLibraryCohesion& cohesion, TExprContext& ctx);
-bool CompileLibrary(const TString& alias, const TString& script, TExprContext& ctx, TLibraryCohesion& cohesion, bool optimize = true);
+bool CompileLibrary(const NSQLTranslation::TTranslators& translators, const TString& alias,
+    const TString& script, TExprContext& ctx, TLibraryCohesion& cohesion, bool optimize = true);
 
 bool LinkLibraries(THashMap<TString, TLibraryCohesion>& libs, TExprContext& ctx, TExprContext& ctxToClone, const std::function<const TExportTable*(const TString&)>& module2ExportTable);
 bool LinkLibraries(THashMap<TString, TLibraryCohesion>& libs, TExprContext& ctx, TExprContext& ctxToClone, const TModulesTable* loadedModules = nullptr);
 
+bool CompileLibraries(const NSQLTranslation::TTranslators& translators, const TUserDataTable& userData,
+    TExprContext& ctx, TModulesTable& modules, bool optimize = true);
+//FIXME remove
 bool CompileLibraries(const TUserDataTable& userData, TExprContext& ctx, TModulesTable& modules, bool optimize = true);
 }

Некоторые файлы не были показаны из-за большого количества измененных файлов