Skip to content

Commit

Permalink
fix(hybridse): handling nullptr after converting FrameBound in Conver…
Browse files Browse the repository at this point in the history
…tFrameBound of ast_node_converter.cc (#4015)

Signed-off-by: shouren <[email protected]>
  • Loading branch information
Shouren authored Jan 9, 2025
1 parent 76d9020 commit 0e3b58c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions hybridse/src/planv2/ast_node_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ base::Status ConvertExprNodeList(const absl::Span<const zetasql::ASTExpression*
*output = expr_list;
return base::Status::OK();
}

base::Status ConvertFrameBound(const zetasql::ASTWindowFrameExpr* window_frame_expr, node::NodeManager* node_manager,
node::FrameBound** output) {
if (nullptr == window_frame_expr) {
Expand Down Expand Up @@ -1042,12 +1043,14 @@ base::Status ConvertFrameBound(const zetasql::ASTWindowFrameExpr* window_frame_e
}
return base::Status::OK();
}

base::Status ConvertFrameNode(const zetasql::ASTWindowFrame* window_frame, node::NodeManager* node_manager,
node::FrameNode** output) {
if (nullptr == window_frame) {
*output = nullptr;
return base::Status::OK();
}

base::Status status;
node::FrameType frame_type;
switch (window_frame->frame_unit()) {
Expand All @@ -1069,19 +1072,24 @@ base::Status ConvertFrameNode(const zetasql::ASTWindowFrame* window_frame, node:
return status;
}
}

node::FrameBound* start = nullptr;
node::FrameBound* end = nullptr;
CHECK_TRUE(nullptr != window_frame->start_expr(), common::kSqlAstError, "Un-support window frame with null start")
CHECK_TRUE(nullptr != window_frame->end_expr(), common::kSqlAstError, "Un-support window frame with null end")
CHECK_STATUS(ConvertFrameBound(window_frame->start_expr(), node_manager, &start))
CHECK_STATUS(ConvertFrameBound(window_frame->end_expr(), node_manager, &end))
CHECK_TRUE(nullptr != start, common::kSqlAstError)
CHECK_TRUE(nullptr != end, common::kSqlAstError)
auto* frame_ext = node_manager->MakeFrameExtent(start, end);
CHECK_TRUE(frame_ext->Valid(), common::kSqlAstError,
"The lower bound of a window frame must be less than or equal to the upper bound");

node::ExprNode* frame_max_size = nullptr;
if (nullptr != window_frame->max_size()) {
CHECK_STATUS(ConvertExprNode(window_frame->max_size()->max_size(), node_manager, &frame_max_size))
}
auto* frame_ext = node_manager->MakeFrameExtent(start, end);
CHECK_TRUE(frame_ext->Valid(), common::kSqlAstError,
"The lower bound of a window frame must be less than or equal to the upper bound");

*output = node_manager->MakeFrameNode(frame_type, frame_ext, frame_max_size);
return base::Status::OK();
}
Expand Down

0 comments on commit 0e3b58c

Please sign in to comment.