Skip to content

Commit

Permalink
feat(planner): suport SET GLOBAL|SESSIOIN statement
Browse files Browse the repository at this point in the history
close #1361
  • Loading branch information
aceforeverd committed Mar 2, 2022
1 parent aac8167 commit dcba0ea
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
24 changes: 24 additions & 0 deletions cases/plan/cmd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions cases/plan/error_unsupport_sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 20 additions & 4 deletions hybridse/src/planv2/ast_node_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<zetasql::ASTSystemVariableAssignment>();
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<std::string> path;
CHECK_STATUS(AstPathExpressionToStringList(ast_system_variable_assign->system_variable()->path(), path));
CHECK_TRUE(!path.empty(), common::kSqlAstError, "Non-support empty variable");
Expand All @@ -669,8 +669,7 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node
dynamic_cast<node::ConstNode*>(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,
Expand All @@ -679,6 +678,23 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node
}
break;
}
case zetasql::AST_SCOPED_VARIABLE_ASSIGNMENT: {
auto stmt = statement->GetAsOrNull<zetasql::ASTScopedVariableAssignment>();
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<node::ConstNode*>(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<zetasql::ASTLoadDataStatement>();
CHECK_TRUE(load_data_stmt != nullptr, common::kSqlAstError, "not an ASTLoadDataStatement");
Expand Down
2 changes: 1 addition & 1 deletion third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions third-party/cmake/FetchZetasql.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()

Expand Down

0 comments on commit dcba0ea

Please sign in to comment.