aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <vvvv@yandex-team.com>2024-12-13 12:05:30 +0300
committervvvv <vvvv@yandex-team.com>2024-12-13 12:33:42 +0300
commitfab10ff25473117c056fd8c4ec06e7cbc4783cbd (patch)
tree83c4b5467943f86cb658522169649dfe5c3f8835
parentc51abdbd596f06b9580e928ce0d44015f2fa2fcc (diff)
downloadydb-fab10ff25473117c056fd8c4ec06e7cbc4783cbd.tar.gz
yqls library suffix
commit_hash:145c28ad6f2af01a89393fb186a5934394d6f9a0
-rw-r--r--yql/essentials/core/yql_type_annotation.cpp24
-rw-r--r--yql/essentials/core/yql_type_annotation.h2
-rw-r--r--yql/essentials/tests/sql/sql2yql/canondata/result.json12
-rw-r--r--yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_library-library_yqls_/formatted.sql7
-rw-r--r--yql/essentials/tests/sql/suites/library/lib1.yqls.txt4
-rw-r--r--yql/essentials/tests/sql/suites/library/library_yqls.cfg1
-rw-r--r--yql/essentials/tests/sql/suites/library/library_yqls.sql4
7 files changed, 44 insertions, 10 deletions
diff --git a/yql/essentials/core/yql_type_annotation.cpp b/yql/essentials/core/yql_type_annotation.cpp
index 9d8ed5648a..0c627df404 100644
--- a/yql/essentials/core/yql_type_annotation.cpp
+++ b/yql/essentials/core/yql_type_annotation.cpp
@@ -227,7 +227,7 @@ TString FormatColumnOrder(const TMaybe<TColumnOrder>& columnOrder, TMaybe<size_t
ss << "[";
size_t i = 0;
for (auto& [e, gen_e]: *columnOrder) {
-
+
ss << "(" << e << "->" << gen_e << ")";
if (++i != columnOrder->Size()) {
ss << ", ";
@@ -341,6 +341,10 @@ TString TModuleResolver::NormalizeModuleName(const TString& path) {
return path.substr(0, path.size() - 4);
}
+ if (path.EndsWith(".yqls")) {
+ return path.substr(0, path.size() - 5);
+ }
+
return path;
}
@@ -405,8 +409,9 @@ bool TModuleResolver::AddFromFile(const std::string_view& file, TExprContext& ct
const auto fullName = TUserDataStorage::MakeFullName(file);
const bool isSql = file.ends_with(".sql");
const bool isYql = file.ends_with(".yql");
- if (!isSql && !isYql) {
- ctx.AddError(TIssue(pos, TStringBuilder() << "Unsupported syntax of library file, expected one of (.sql, .yql): " << file));
+ const bool isYqls = file.ends_with(".yqls");
+ if (!isSql && !isYql && !isYqls) {
+ ctx.AddError(TIssue(pos, TStringBuilder() << "Unsupported syntax of library file, expected one of (.sql, .yql, .yqls): " << file));
return false;
}
@@ -450,7 +455,7 @@ bool TModuleResolver::AddFromFile(const std::string_view& file, TExprContext& ct
}
}
- return AddFromMemory(fullName, moduleName, isYql, body, ctx, syntaxVersion, packageVersion, pos);
+ return AddFromMemory(fullName, moduleName, isYql || isYqls, body, ctx, syntaxVersion, packageVersion, pos);
}
bool TModuleResolver::AddFromMemory(const std::string_view& file, const TString& body, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos) {
@@ -462,8 +467,9 @@ bool TModuleResolver::AddFromMemory(const std::string_view& file, const TString&
const auto fullName = TUserDataStorage::MakeFullName(file);
const bool isSql = file.ends_with(".sql");
const bool isYql = file.ends_with(".yql");
- if (!isSql && !isYql) {
- ctx.AddError(TIssue(pos, TStringBuilder() << "Unsupported syntax of library file, expected one of (.sql, .yql): " << file));
+ const bool isYqls = file.ends_with(".yqls");
+ if (!isSql && !isYql && !isYqls) {
+ ctx.AddError(TIssue(pos, TStringBuilder() << "Unsupported syntax of library file, expected one of (.sql, .yql, .yqls): " << file));
return false;
}
@@ -477,10 +483,10 @@ bool TModuleResolver::AddFromMemory(const std::string_view& file, const TString&
}
}
- return AddFromMemory(fullName, moduleName, isYql, body, ctx, syntaxVersion, packageVersion, pos, exports, imports);
+ return AddFromMemory(fullName, moduleName, isYql || isYqls, body, ctx, syntaxVersion, packageVersion, pos, exports, imports);
}
-bool TModuleResolver::AddFromMemory(const TString& fullName, const TString& moduleName, bool isYql, const TString& body, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos, std::vector<TString>* exports, std::vector<TString>* imports) {
+bool TModuleResolver::AddFromMemory(const TString& fullName, const TString& moduleName, bool sExpr, const TString& body, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos, std::vector<TString>* exports, std::vector<TString>* imports) {
auto query = body;
if (QContext.CanRead()) {
auto item = QContext.GetReader()->Get({ModuleResolverComponent, fullName}).GetValueSync();
@@ -501,7 +507,7 @@ bool TModuleResolver::AddFromMemory(const TString& fullName, const TString& modu
};
TAstParseResult astRes;
- if (isYql) {
+ if (sExpr) {
astRes = ParseAst(query, nullptr, fullName);
if (!astRes.IsOk()) {
ctx.AddError(addSubIssues(TIssue(pos, TStringBuilder() << "Failed to parse YQL: " << fullName), astRes.Issues));
diff --git a/yql/essentials/core/yql_type_annotation.h b/yql/essentials/core/yql_type_annotation.h
index 7275801c6c..05ede6e897 100644
--- a/yql/essentials/core/yql_type_annotation.h
+++ b/yql/essentials/core/yql_type_annotation.h
@@ -104,7 +104,7 @@ public:
TString GetFileAliasPrefix() const override;
private:
- bool AddFromMemory(const TString& fullName, const TString& moduleName, bool isYql, const TString& body, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos, std::vector<TString>* exports = nullptr, std::vector<TString>* imports = nullptr);
+ bool AddFromMemory(const TString& fullName, const TString& moduleName, bool sExpr, const TString& body, TExprContext& ctx, ui16 syntaxVersion, ui32 packageVersion, TPosition pos, std::vector<TString>* exports = nullptr, std::vector<TString>* imports = nullptr);
THashMap<TString, TLibraryCohesion> FilterLibsByVersion() const;
static TString ExtractPackageNameFromModule(TStringBuf moduleName);
TString SubstParameters(const TString& str);
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/result.json b/yql/essentials/tests/sql/sql2yql/canondata/result.json
index 817b47972c..ab345774f4 100644
--- a/yql/essentials/tests/sql/sql2yql/canondata/result.json
+++ b/yql/essentials/tests/sql/sql2yql/canondata/result.json
@@ -10653,6 +10653,13 @@
"uri": "https://{canondata_backend}/1937429/434276f26b2857be3c5ad3fdbbf877d2bf775ac5/resource.tar.gz#test_sql2yql.test_library-library_via_http_/sql.yql"
}
],
+ "test_sql2yql.test[library-library_yqls]": [
+ {
+ "checksum": "da2872b19c48276062e74b52d7310e26",
+ "size": 1082,
+ "uri": "https://{canondata_backend}/1937001/cf140a1b2b53c08f9746ee7c7b322863316889f0/resource.tar.gz#test_sql2yql.test_library-library_yqls_/sql.yql"
+ }
+ ],
"test_sql2yql.test[library-package]": [
{
"checksum": "106486465eec39d06f2253ff07547c25",
@@ -27580,6 +27587,11 @@
"uri": "file://test_sql_format.test_library-library_via_http_/formatted.sql"
}
],
+ "test_sql_format.test[library-library_yqls]": [
+ {
+ "uri": "file://test_sql_format.test_library-library_yqls_/formatted.sql"
+ }
+ ],
"test_sql_format.test[library-package]": [
{
"uri": "file://test_sql_format.test_library-package_/formatted.sql"
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_library-library_yqls_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_library-library_yqls_/formatted.sql
new file mode 100644
index 0000000000..84fd1a4451
--- /dev/null
+++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_library-library_yqls_/formatted.sql
@@ -0,0 +1,7 @@
+PRAGMA library("lib1.yqls");
+
+IMPORT lib1 SYMBOLS $sqr;
+
+SELECT
+ $sqr(10)
+;
diff --git a/yql/essentials/tests/sql/suites/library/lib1.yqls.txt b/yql/essentials/tests/sql/suites/library/lib1.yqls.txt
new file mode 100644
index 0000000000..c53ec8e756
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/library/lib1.yqls.txt
@@ -0,0 +1,4 @@
+(
+(let $sqr (lambda '($x) (* $x $x)))
+(export $sqr)
+)
diff --git a/yql/essentials/tests/sql/suites/library/library_yqls.cfg b/yql/essentials/tests/sql/suites/library/library_yqls.cfg
new file mode 100644
index 0000000000..d66b4537ea
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/library/library_yqls.cfg
@@ -0,0 +1 @@
+file lib1.yqls lib1.yqls.txt
diff --git a/yql/essentials/tests/sql/suites/library/library_yqls.sql b/yql/essentials/tests/sql/suites/library/library_yqls.sql
new file mode 100644
index 0000000000..393249f217
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/library/library_yqls.sql
@@ -0,0 +1,4 @@
+pragma library("lib1.yqls");
+import lib1 symbols $sqr;
+select $sqr(10);
+