Skip to content

Commit 0601201

Browse files
authored
feat(planner): suport SET GLOBAL|SESSIOIN statement (#1364)
close #1361
1 parent 62b5157 commit 0601201

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

cases/plan/cmd.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,30 @@ cases:
478478
+-expr[primary]
479479
+-value: yyyy
480480
+-type: string
481+
- id: set global to int
482+
sql: SET GLOBAL var1 = 100;
483+
expect:
484+
node_tree_str: |
485+
+-node[kSetStmt]
486+
+-scope: GlobalSystemVariable
487+
+-key: var1
488+
+-value:
489+
+-expr[primary]
490+
+-value: 100
491+
+-type: int32
492+
493+
- id: set session to string
494+
sql: SET SESSION var2 = '100';
495+
expect:
496+
node_tree_str: |
497+
+-node[kSetStmt]
498+
+-scope: SessionSystemVariable
499+
+-key: var2
500+
+-value:
501+
+-expr[primary]
502+
+-value: 100
503+
+-type: string
504+
481505
- id: show_variables
482506
sql: SHOW VARIABLES;
483507
expect:

cases/plan/error_unsupport_sql.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ cases:
7575
- id: set_statement
7676
desc: unsupported value type
7777
sql: SET SELECT_MODE = 1 + 2;
78+
- id: set_global_to_expr
79+
desc: unsupported value type
80+
sql: SET GLOBAL xxx = 1 + 1;
7881
- id: group_complex_expression
7982
desc: SELECT GROUP BY complex expression is unsupport
8083
sql: SELECT COL1+COL2 FROM t1 group by COL1+COL2;

hybridse/src/planv2/ast_node_converter.cc

+20-4
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node
645645
/// support system variable setting and showing in OpenMLDB since v0.4.0
646646
/// non-support local variable setting in v0.4.0
647647
const auto ast_system_variable_assign = statement->GetAsOrNull<zetasql::ASTSystemVariableAssignment>();
648-
CHECK_TRUE(nullptr != ast_system_variable_assign, common::kSqlAstError, "not an "
649-
"ASTSystemVariableAssignment");
648+
CHECK_TRUE(nullptr != ast_system_variable_assign, common::kSqlAstError,
649+
"not an ASTSystemVariableAssignment");
650650
std::vector<std::string> path;
651651
CHECK_STATUS(AstPathExpressionToStringList(ast_system_variable_assign->system_variable()->path(), path));
652652
CHECK_TRUE(!path.empty(), common::kSqlAstError, "Non-support empty variable");
@@ -669,8 +669,7 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node
669669
dynamic_cast<node::ConstNode*>(value));
670670
} else {
671671
FAIL_STATUS(common::kSqlAstError, "Non-support system variable under ", path[0],
672-
" scope, try "
673-
"@@global or @@session scope");
672+
" scope, try @@global or @@session scope");
674673
}
675674
} else {
676675
FAIL_STATUS(common::kSqlAstError,
@@ -679,6 +678,23 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node
679678
}
680679
break;
681680
}
681+
case zetasql::AST_SCOPED_VARIABLE_ASSIGNMENT: {
682+
auto stmt = statement->GetAsOrNull<zetasql::ASTScopedVariableAssignment>();
683+
CHECK_TRUE(stmt != nullptr, common::kSqlAstError, "not an ASTScopedVariableAssignment");
684+
node::ExprNode* value = nullptr;
685+
CHECK_STATUS(ConvertExprNode(stmt->expression(), node_manager, &value));
686+
const node::ConstNode* const_value = dynamic_cast<node::ConstNode*>(value);
687+
CHECK_TRUE(const_value != nullptr && const_value->GetExprType() == node::kExprPrimary, common::kSqlAstError,
688+
"Unsupported Set value other than const type");
689+
690+
const std::string& identifier = stmt->variable()->GetAsString();
691+
auto scope = node::VariableScope::kSessionSystemVariable;
692+
if (stmt->scope() == zetasql::ASTScopedVariableAssignment::Scope::GLOBAL) {
693+
scope = node::VariableScope::kGlobalSystemVariable;
694+
}
695+
*output = node_manager->MakeSetNode(scope, identifier, const_value);
696+
break;
697+
}
682698
case zetasql::AST_LOAD_DATA_STATEMENT: {
683699
const auto load_data_stmt = statement->GetAsOrNull<zetasql::ASTLoadDataStatement>();
684700
CHECK_TRUE(load_data_stmt != nullptr, common::kSqlAstError, "not an ASTLoadDataStatement");

third-party/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if(NOT BUILD_BUNDLED)
111111

112112
message(STATUS "Download pre-compiled hybridsql assert from ${HYBRIDSQL_ASSERTS_URL}")
113113
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)")
114-
message(WARNING pre-compiled hybridsql aseerts for arm64 may out-of-date, consider build from source by '-DBUILD_BUNDLED_HYBRIDSQL_ASSERTS=ON')
114+
message(WARNING pre-compiled hybridsql aseerts for arm64 may out-of-date, consider build from source by '-DBUILD_BUNDLED=ON')
115115
endif()
116116
ExternalProject_Add(
117117
hybridsql-asserts

third-party/cmake/FetchZetasql.cmake

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
set(ZETASQL_HOME https://github.com/4paradigm/zetasql)
16-
set(ZETASQL_VERSION 0.2.8)
16+
set(ZETASQL_VERSION 0.2.9)
1717
set(ZETASQL_TAG 2e548a0e656d050d2b0fb97b3caab122cb3a6ea6) # the commit hash for v0.2.7
1818

1919
function(init_zetasql_urls)
@@ -22,6 +22,7 @@ function(init_zetasql_urls)
2222

2323
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)|(AARCH64)")
2424
# there is experimental build for centos7 on aarch64, for others zetasql need compile from source
25+
message(WARNING "pre-compiled zetasql for arm64 may out-of-date, consider build from source by -DBUILD_BUNDLED_ZETASQL=ON")
2526
if (LSB_RELEASE_ID_SHORT STREQUAL "centos")
2627
set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-aarch64-centos.tar.gz" PARENT_SCOPE)
2728
set(ZETASQL_HASH d504ade9973f28507154aa88bf0565939fbf14b4114040f4133c217cdebc93ed PARENT_SCOPE)
@@ -32,16 +33,16 @@ function(init_zetasql_urls)
3233

3334
if (LSB_RELEASE_ID_SHORT STREQUAL "centos")
3435
set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-x86_64-centos.tar.gz" PARENT_SCOPE)
35-
set(ZETASQL_HASH a00c4359b8a1a1bdfbbdd0606f66e0b480d6abb4dcdde731899cfcc808a8f30e PARENT_SCOPE)
36+
set(ZETASQL_HASH 32c70da94a1a7c9379c85ac80b2c07ea2654d5b65513824746fe6d81cf353c7d PARENT_SCOPE)
3637
elseif(LSB_RELEASE_ID_SHORT STREQUAL "ubuntu")
3738
set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-linux-gnu-x86_64-ubuntu.tar.gz" PARENT_SCOPE)
38-
set(ZETASQL_HASH 875f809f3e0e98fe0ac8397a5f4e7a61400b3e79a656ce7ac5d31280e47397ac PARENT_SCOPE)
39+
set(ZETASQL_HASH cb7a752d3a0df92e71d5b3876abde99ce8997c2111cefb2f400b7b312a867942 PARENT_SCOPE)
3940
else()
4041
message(FATAL_ERROR "no pre-compiled zetasql for ${LSB_RELEASE_ID_SHORT}, try compile zetasql from source with '-DBUILD_BUNDLED_ZETASQL=ON'")
4142
endif()
4243
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
4344
set(ZETASQL_URL "${ZETASQL_HOME}/releases/download/v${ZETASQL_VERSION}/libzetasql-${ZETASQL_VERSION}-darwin-x86_64.tar.gz" PARENT_SCOPE)
44-
set(ZETASQL_HASH e4d9d7d0393bb308e82864e2064a31b324e217991f2834dab71ec103c4d2660d PARENT_SCOPE)
45+
set(ZETASQL_HASH 5ce0904cb947b9e83b33513d3a1a908d03fb52011e3f702ec193cedc76e37a84 PARENT_SCOPE)
4546
endif()
4647
endfunction()
4748

0 commit comments

Comments
 (0)