From dcba0eae4490eae80dc58122d1f339fb83711b7d Mon Sep 17 00:00:00 2001 From: aceforeverd Date: Wed, 2 Mar 2022 21:00:29 +0800 Subject: [PATCH] feat(planner): suport `SET GLOBAL|SESSIOIN ` statement close #1361 --- cases/plan/cmd.yaml | 24 +++++++++++++++++++++++ cases/plan/error_unsupport_sql.yaml | 3 +++ hybridse/src/planv2/ast_node_converter.cc | 24 +++++++++++++++++++---- third-party/CMakeLists.txt | 2 +- third-party/cmake/FetchZetasql.cmake | 9 +++++---- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/cases/plan/cmd.yaml b/cases/plan/cmd.yaml index d7cf6b447b8..94c31e8bb4b 100644 --- a/cases/plan/cmd.yaml +++ b/cases/plan/cmd.yaml @@ -478,6 +478,30 @@ cases: +-expr[primary] +-value: yyyy +-type: string + - id: set global to int + sql: SET GLOBAL var1 = 100; + expect: + node_tree_str: | + +-node[kSetStmt] + +-scope: GlobalSystemVariable + +-key: var1 + +-value: + +-expr[primary] + +-value: 100 + +-type: int32 + + - id: set session to string + sql: SET SESSION var2 = '100'; + expect: + node_tree_str: | + +-node[kSetStmt] + +-scope: SessionSystemVariable + +-key: var2 + +-value: + +-expr[primary] + +-value: 100 + +-type: string + - id: show_variables sql: SHOW VARIABLES; expect: diff --git a/cases/plan/error_unsupport_sql.yaml b/cases/plan/error_unsupport_sql.yaml index e5a4460e3e8..8bda40ec851 100644 --- a/cases/plan/error_unsupport_sql.yaml +++ b/cases/plan/error_unsupport_sql.yaml @@ -75,6 +75,9 @@ cases: - id: set_statement desc: unsupported value type sql: SET SELECT_MODE = 1 + 2; + - id: set_global_to_expr + desc: unsupported value type + sql: SET GLOBAL xxx = 1 + 1; - id: group_complex_expression desc: SELECT GROUP BY complex expression is unsupport sql: SELECT COL1+COL2 FROM t1 group by COL1+COL2; diff --git a/hybridse/src/planv2/ast_node_converter.cc b/hybridse/src/planv2/ast_node_converter.cc index cf4b47f76a7..b77f3c45766 100644 --- a/hybridse/src/planv2/ast_node_converter.cc +++ b/hybridse/src/planv2/ast_node_converter.cc @@ -645,8 +645,8 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node /// support system variable setting and showing in OpenMLDB since v0.4.0 /// non-support local variable setting in v0.4.0 const auto ast_system_variable_assign = statement->GetAsOrNull(); - CHECK_TRUE(nullptr != ast_system_variable_assign, common::kSqlAstError, "not an " - "ASTSystemVariableAssignment"); + CHECK_TRUE(nullptr != ast_system_variable_assign, common::kSqlAstError, + "not an ASTSystemVariableAssignment"); std::vector path; CHECK_STATUS(AstPathExpressionToStringList(ast_system_variable_assign->system_variable()->path(), path)); CHECK_TRUE(!path.empty(), common::kSqlAstError, "Non-support empty variable"); @@ -669,8 +669,7 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node dynamic_cast(value)); } else { FAIL_STATUS(common::kSqlAstError, "Non-support system variable under ", path[0], - " scope, try " - "@@global or @@session scope"); + " scope, try @@global or @@session scope"); } } else { FAIL_STATUS(common::kSqlAstError, @@ -679,6 +678,23 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node } break; } + case zetasql::AST_SCOPED_VARIABLE_ASSIGNMENT: { + auto stmt = statement->GetAsOrNull(); + CHECK_TRUE(stmt != nullptr, common::kSqlAstError, "not an ASTScopedVariableAssignment"); + node::ExprNode* value = nullptr; + CHECK_STATUS(ConvertExprNode(stmt->expression(), node_manager, &value)); + const node::ConstNode* const_value = dynamic_cast(value); + CHECK_TRUE(const_value != nullptr && const_value->GetExprType() == node::kExprPrimary, common::kSqlAstError, + "Unsupported Set value other than const type"); + + const std::string& identifier = stmt->variable()->GetAsString(); + auto scope = node::VariableScope::kSessionSystemVariable; + if (stmt->scope() == zetasql::ASTScopedVariableAssignment::Scope::GLOBAL) { + scope = node::VariableScope::kGlobalSystemVariable; + } + *output = node_manager->MakeSetNode(scope, identifier, const_value); + break; + } case zetasql::AST_LOAD_DATA_STATEMENT: { const auto load_data_stmt = statement->GetAsOrNull(); CHECK_TRUE(load_data_stmt != nullptr, common::kSqlAstError, "not an ASTLoadDataStatement"); diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index a807d7cc790..0f3f41d2d83 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -111,7 +111,7 @@ if(NOT BUILD_BUNDLED) message(STATUS "Download pre-compiled hybridsql assert from ${HYBRIDSQL_ASSERTS_URL}") if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)") - message(WARNING pre-compiled hybridsql aseerts for arm64 may out-of-date, consider build from source by '-DBUILD_BUNDLED_HYBRIDSQL_ASSERTS=ON') + message(WARNING pre-compiled hybridsql aseerts for arm64 may out-of-date, consider build from source by '-DBUILD_BUNDLED=ON') endif() ExternalProject_Add( hybridsql-asserts diff --git a/third-party/cmake/FetchZetasql.cmake b/third-party/cmake/FetchZetasql.cmake index 82d4120a7c4..880f5b56e5e 100644 --- a/third-party/cmake/FetchZetasql.cmake +++ b/third-party/cmake/FetchZetasql.cmake @@ -13,7 +13,7 @@ # limitations under the License. set(ZETASQL_HOME https://github.com/4paradigm/zetasql) -set(ZETASQL_VERSION 0.2.8) +set(ZETASQL_VERSION 0.2.9) set(ZETASQL_TAG 2e548a0e656d050d2b0fb97b3caab122cb3a6ea6) # the commit hash for v0.2.7 function(init_zetasql_urls) @@ -22,6 +22,7 @@ function(init_zetasql_urls) if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)") # there is experimental build for centos7 on aarch64, for others zetasql need compile from source + message(WARNING "pre-compiled zetasql for arm64 may out-of-date, consider build from source by -DBUILD_BUNDLED_ZETASQL=ON") if (LSB_RELEASE_ID_SHORT STREQUAL "centos") set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-aarch64-centos.tar.gz" PARENT_SCOPE) set(ZETASQL_HASH d504ade9973f28507154aa88bf0565939fbf14b4114040f4133c217cdebc93ed PARENT_SCOPE) @@ -32,16 +33,16 @@ function(init_zetasql_urls) if (LSB_RELEASE_ID_SHORT STREQUAL "centos") set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-x86_64-centos.tar.gz" PARENT_SCOPE) - set(ZETASQL_HASH a00c4359b8a1a1bdfbbdd0606f66e0b480d6abb4dcdde731899cfcc808a8f30e PARENT_SCOPE) + set(ZETASQL_HASH 32c70da94a1a7c9379c85ac80b2c07ea2654d5b65513824746fe6d81cf353c7d PARENT_SCOPE) elseif(LSB_RELEASE_ID_SHORT STREQUAL "ubuntu") set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-x86_64-ubuntu.tar.gz" PARENT_SCOPE) - set(ZETASQL_HASH 875f809f3e0e98fe0ac8397a5f4e7a61400b3e79a656ce7ac5d31280e47397ac PARENT_SCOPE) + set(ZETASQL_HASH cb7a752d3a0df92e71d5b3876abde99ce8997c2111cefb2f400b7b312a867942 PARENT_SCOPE) else() message(FATAL_ERROR "no pre-compiled zetasql for ${LSB_RELEASE_ID_SHORT}, try compile zetasql from source with '-DBUILD_BUNDLED_ZETASQL=ON'") endif() elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-darwin-x86_64.tar.gz" PARENT_SCOPE) - set(ZETASQL_HASH e4d9d7d0393bb308e82864e2064a31b324e217991f2834dab71ec103c4d2660d PARENT_SCOPE) + set(ZETASQL_HASH 5ce0904cb947b9e83b33513d3a1a908d03fb52011e3f702ec193cedc76e37a84 PARENT_SCOPE) endif() endfunction()