| 289 | }; // namespace |
| 290 | |
| 291 | Window::WindowFrame Window::createWindowFrame( |
| 292 | const std::shared_ptr<const core::WindowNode>& windowNode, |
| 293 | const core::WindowNode::Frame& frame, |
| 294 | const RowTypePtr& inputType) { |
| 295 | if (frame.type == core::WindowNode::WindowType::kRows) { |
| 296 | checkRowFrameBounds(frame); |
| 297 | } |
| 298 | |
| 299 | if (frame.type == core::WindowNode::WindowType::kRange && |
| 300 | (frame.startValue || frame.endValue)) { |
| 301 | checkKRangeFrameBounds(windowNode, frame, inputType); |
| 302 | } |
| 303 | |
| 304 | auto createFrameChannelArg = |
| 305 | [&](const core::TypedExprPtr& frame) -> std::optional<FrameChannelArg> { |
| 306 | // frame is nullptr for non (kPreceding or kFollowing) frames. |
| 307 | if (frame == nullptr) { |
| 308 | return std::nullopt; |
| 309 | } |
| 310 | auto frameChannel = exprToChannel(frame.get(), inputType); |
| 311 | if (frameChannel == kConstantChannel) { |
| 312 | auto constant = core::TypedExprs::asConstant(frame)->value(); |
| 313 | BOLT_CHECK(!constant.isNull(), "Window frame offset must not be null"); |
| 314 | auto value = VariantConverter::convert(constant, TypeKind::BIGINT) |
| 315 | .value<int64_t>(); |
| 316 | BOLT_USER_CHECK_GE( |
| 317 | value, 0, "Window frame {} offset must not be negative", value); |
| 318 | return std::make_optional( |
| 319 | FrameChannelArg{kConstantChannel, nullptr, value}); |
| 320 | } else { |
| 321 | return std::make_optional(FrameChannelArg{ |
| 322 | frameChannel, |
| 323 | BaseVector::create(frame->type(), 0, pool()), |
| 324 | std::nullopt}); |
| 325 | } |
| 326 | }; |
| 327 | |
| 328 | auto startFrameArg = createFrameChannelArg(frame.startValue); |
| 329 | auto endFrameArg = createFrameChannelArg(frame.endValue); |
| 330 | return WindowFrame( |
| 331 | {frame.type, |
| 332 | frame.startType, |
| 333 | frame.endType, |
| 334 | std::move(startFrameArg), |
| 335 | std::move(endFrameArg)}); |
| 336 | } |
| 337 | |
| 338 | void Window::createWindowFunctions() { |
| 339 | BOLT_CHECK_NOT_NULL(windowNode_); |
nothing calls this directly
no test coverage detected