From 4273ea9d791241502b21c3a2f39f40f905e1acb7 Mon Sep 17 00:00:00 2001 From: Matts966 Date: Sun, 6 Jun 2021 16:28:49 +0900 Subject: [PATCH 1/2] Upgrade ZetaSQL to support pivot functions --- .gitignore | 1 + WORKSPACE | 2 +- alphasql/BUILD | 3 +-- bazel/zetasql.patch | 56 ++++----------------------------------------- 4 files changed, 8 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index a32ed4be..6ee3c30e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bazel-* .vscode +.cache diff --git a/WORKSPACE b/WORKSPACE index d525698f..d5536db0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -22,7 +22,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "com_google_zetasql", - commit = "2020.10.1", + commit = "dd883180de6387ad80bcf7534b5aae8191e66621", remote = "https://github.com/google/zetasql", patches = ["@com_github_Matts966_alphasql//bazel:zetasql.patch"], ) diff --git a/alphasql/BUILD b/alphasql/BUILD index 94af46b3..fcbae16a 100644 --- a/alphasql/BUILD +++ b/alphasql/BUILD @@ -39,7 +39,6 @@ cc_library( "@com_google_zetasql//zetasql/public:analyzer", "@com_google_zetasql//zetasql/public:language_options", "@com_google_zetasql//zetasql/parser:parser", - "@com_google_zetasql//zetasql/analyzer", "@boost//:property_tree", "@com_google_absl//absl/strings", ":table_name_resolver" @@ -106,7 +105,7 @@ cc_library( name = "dag_lib", hdrs = ["dag_lib.h"], deps = [ - "@com_google_zetasql//zetasql/analyzer", + "@com_google_zetasql//zetasql/public:analyzer", "@com_google_zetasql//zetasql/resolved_ast", "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/flags:parse", diff --git a/bazel/zetasql.patch b/bazel/zetasql.patch index 97430e82..dc056d7e 100644 --- a/bazel/zetasql.patch +++ b/bazel/zetasql.patch @@ -1,16 +1,5 @@ ---- zetasql/analyzer/BUILD -+++ zetasql/analyzer/BUILD -@@ -14,7 +14,7 @@ - # limitations under the License. - # - - package( -- default_visibility = ["//zetasql/base:zetasql_implementation"], -+ default_visibility = ["//visibility:public"], - ) - - cc_library( - +diff --git zetasql/base/BUILD zetasql/base/BUILD +index 75c8e3e..7874e07 100644 --- zetasql/base/BUILD +++ zetasql/base/BUILD @@ -17,7 +17,7 @@ @@ -22,19 +11,11 @@ ) package_group( - ---- zetasql/common/BUILD -+++ zetasql/common/BUILD -@@ -14,4 +14,4 @@ - # limitations under the License. - - package( -- default_visibility = ["//zetasql/base:zetasql_implementation"], -+ default_visibility = ["//visibility:public"], - +diff --git zetasql/parser/BUILD zetasql/parser/BUILD +index 5c3c636..5404163 100644 --- zetasql/parser/BUILD +++ zetasql/parser/BUILD -@@ -17,7 +17,7 @@ load("//bazel:bison.bzl", "genyacc") +@@ -20,7 +20,7 @@ load("//bazel:bison.bzl", "genyacc") load("//bazel:flex.bzl", "genlex") package( @@ -43,30 +24,3 @@ ) genrule( - ---- zetasql/public/simple_catalog.h -+++ zetasql/public/simple_catalog.h -@@ -55,6 +55,11 @@ class SimpleTableProto; - // - // This class is thread-safe. - class SimpleCatalog : public EnumerableCatalog { -+ friend void dropOwnedTable(SimpleCatalog* catalog, const std::string& name); -+ friend void dropOwnedTableIfExists(SimpleCatalog* catalog, const std::string& name); -+ friend void dropOwnedFunction(SimpleCatalog* catalog, const std::string& full_name_without_group); -+ -+ - public: - // Construct a Catalog with catalog name . - // - ---- zetasql/resolved_ast/BUILD -+++ zetasql/resolved_ast/BUILD -@@ -16,7 +16,7 @@ - - load("//zetasql/resolved_ast:build_rules.bzl", "gen_resolved_ast_files") - --package(default_visibility = ["//zetasql/base:zetasql_implementation"]) -+package(default_visibility = ["//visibility:public"]) - - py_binary( - name = "gen_resolved_ast", From 910c2c9e859d63242861f3715a3b1cf2079ada43 Mon Sep 17 00:00:00 2001 From: Matts966 Date: Sun, 6 Jun 2021 18:01:33 +0900 Subject: [PATCH 2/2] Fix options --- .bazelrc | 2 +- alphasql/BUILD | 5 ++- bazel/zetasql.patch | 49 +++++++++++++++++++++++-- samples/sample-ci/alphacheck_stdout.txt | 2 +- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/.bazelrc b/.bazelrc index 9cbea588..68ac2a2d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -19,4 +19,4 @@ # c++1z was used prior to c++17 being standardized, and is therefore more # widely accepted by compilers. This may lead to strange behavior or compiler # errors in earlier compilers. -build --cxxopt="-std=c++1z" +build --cxxopt="-std=c++1z" --features=-supports_dynamic_linker diff --git a/alphasql/BUILD b/alphasql/BUILD index fcbae16a..a05a751a 100644 --- a/alphasql/BUILD +++ b/alphasql/BUILD @@ -37,6 +37,8 @@ cc_library( "@com_google_zetasql//zetasql/public:simple_catalog", "@com_google_zetasql//zetasql/public:type", "@com_google_zetasql//zetasql/public:analyzer", + "@com_google_zetasql//zetasql/analyzer:analyzer_impl", + "@com_google_zetasql//zetasql/analyzer:resolver", "@com_google_zetasql//zetasql/public:language_options", "@com_google_zetasql//zetasql/parser:parser", "@boost//:property_tree", @@ -70,6 +72,7 @@ cc_binary( "@com_google_zetasql//zetasql/base:status", "@com_google_zetasql//zetasql/base:statusor", "@com_google_zetasql//zetasql/public:analyzer", + "@com_google_zetasql//zetasql/analyzer:analyzer_impl", "@com_google_zetasql//zetasql/public:catalog", "@com_google_zetasql//zetasql/public:evaluator", "@com_google_zetasql//zetasql/public:evaluator_table_iterator", @@ -105,7 +108,7 @@ cc_library( name = "dag_lib", hdrs = ["dag_lib.h"], deps = [ - "@com_google_zetasql//zetasql/public:analyzer", + "@com_google_zetasql//zetasql/analyzer:analyzer_impl", "@com_google_zetasql//zetasql/resolved_ast", "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/flags:parse", diff --git a/bazel/zetasql.patch b/bazel/zetasql.patch index dc056d7e..de89f0d0 100644 --- a/bazel/zetasql.patch +++ b/bazel/zetasql.patch @@ -1,15 +1,28 @@ +diff --git zetasql/analyzer/BUILD zetasql/analyzer/BUILD +index 91c73c6..57e5609 100644 +--- zetasql/analyzer/BUILD ++++ zetasql/analyzer/BUILD +@@ -18,7 +18,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + load(":builddefs.bzl", "gen_analyzer_test") + + package( +- default_visibility = ["//zetasql/base:zetasql_implementation"], ++ default_visibility = ["//visibility:public"], + ) + + filegroup( diff --git zetasql/base/BUILD zetasql/base/BUILD index 75c8e3e..7874e07 100644 --- zetasql/base/BUILD +++ zetasql/base/BUILD @@ -17,7 +17,7 @@ licenses(["notice"]) # Apache v2.0 - + package( - default_visibility = [":zetasql_implementation"], + default_visibility = ["//visibility:public"], ) - + package_group( diff --git zetasql/parser/BUILD zetasql/parser/BUILD index 5c3c636..5404163 100644 @@ -17,10 +30,38 @@ index 5c3c636..5404163 100644 +++ zetasql/parser/BUILD @@ -20,7 +20,7 @@ load("//bazel:bison.bzl", "genyacc") load("//bazel:flex.bzl", "genlex") - + package( - default_visibility = ["//zetasql/base:zetasql_implementation"], + default_visibility = ["//visibility:public"], ) - + genrule( + +--- zetasql/public/simple_catalog.h ++++ zetasql/public/simple_catalog.h +@@ -55,6 +55,11 @@ class SimpleTableProto; + // + // This class is thread-safe. + class SimpleCatalog : public EnumerableCatalog { ++ friend void dropOwnedTable(SimpleCatalog* catalog, const std::string& name); ++ friend void dropOwnedTableIfExists(SimpleCatalog* catalog, const std::string& name); ++ friend void dropOwnedFunction(SimpleCatalog* catalog, const std::string& full_name_without_group); ++ ++ + public: + // Construct a Catalog with catalog name . + // + +diff --git zetasql/public/sql_formatter.cc zetasql/public/sql_formatter.cc +index 26e52ed..28e8928 100644 +--- zetasql/public/sql_formatter.cc ++++ zetasql/public/sql_formatter.cc +@@ -72,6 +72,7 @@ absl::Status FormatSql(const std::string& sql, std::string* formatted_sql) { + std::vector parse_tokens; + ParseTokenOptions options; + options.stop_at_end_of_statement = true; ++ options.include_comments = true; + const int statement_start = location.byte_position(); + const absl::Status token_status = + GetParseTokens(options, &location, &parse_tokens); diff --git a/samples/sample-ci/alphacheck_stdout.txt b/samples/sample-ci/alphacheck_stdout.txt index 174dc736..1ea0cbdb 100644 --- a/samples/sample-ci/alphacheck_stdout.txt +++ b/samples/sample-ci/alphacheck_stdout.txt @@ -1,6 +1,6 @@ Analyzing "samples/sample-ci/sample/create_datawarehouse3.sql" ERROR: INVALID_ARGUMENT: Table not found: `bigquery-public-data.samples.gsod` [at samples/sample-ci/sample/create_datawarehouse3.sql:5:3] catalog: - dataset.main tablename2 + dataset.main tablename1