259300 {
259301 auto &lfstate = sink.local_state.Cast<WindowFillLocalState>();
259302 auto &cursor = *lfstate.cursor;
259303
259304
259305 WindowFillCopy(cursor, result, count, row_idx, 0);
259306
259307
259308 UnifiedVectorFormat arg_data;
259309 result.ToUnifiedFormat(count, arg_data);
259310 if (arg_data.validity.AllValid()) {
259311 return;
259312 }
259313
259314
259315 auto &gfstate = sink.global_state.Cast<WindowFillGlobalState>();
259316 auto partition_begin = FlatVector::GetData<const idx_t>(lfstate.bounds.data[PARTITION_BEGIN]);
259317 auto partition_end = FlatVector::GetData<const idx_t>(lfstate.bounds.data[PARTITION_END]);
259318
259321
259322 auto interpolate_func = GetFillInterpolateFunction(wexpr.children[0]->return_type);
259323 auto value_func = GetFillValueFunction(wexpr.children[0]->return_type);
259324
259325
259326 if (gfstate.value_tree) {
259327
259328
259329 auto &order_cursor = *lfstate.order_cursor;
259330 auto slope_func = GetFillSlopeFunction(wexpr.arg_orders[0].expression->return_type);
259331 auto order_value_func = GetFillValueFunction(wexpr.arg_orders[0].expression->return_type);
259332 auto &frames = lfstate.frames;
259333 frames.resize(1);
259334 auto &frame = frames[0];
259335 for (
idx_t i = 0; i < count; ++i, ++row_idx) {
259336
259337 const auto idx = arg_data.sel->get_index(i);
259338 if (arg_data.validity.RowIsValid(idx)) {
259339 continue;
259340 }
259341
259342
259343 frame = {partition_begin[i], partition_end[i]};
259344 const auto frame_width = frame.end - frame.start;
259345 D_ASSERT(frame.end != frame.start);
259346
259347
259348 if (!order_value_func(row_idx, order_cursor)) {
259349 continue;
259350 }
259351
259352
259353 const auto own_row = gfstate.row_tree->Rank(frame.start, frame.end, row_idx) - 1;
259354
259355
259356
259359 for (
idx_t n = own_row; n-- > 0;) {
259360 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259361 if (!order_value_func(j, order_cursor)) {
259362 break;
259363 }
259364 if (value_func(j, cursor)) {
259365 prev_valid = j;
259366 prev_n = n;
259367 break;
259368 }
259369 }
259370
259371
259373 for (
idx_t n = own_row + 1; n < frame_width; ++n) {
259374 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259375 if (!order_value_func(j, order_cursor)) {
259376 break;
259377 }
259378 if (value_func(j, cursor)) {
259379 prev_valid = j;
259380 prev_n = n;
259381 break;
259382 }
259383 }
259384 }
259385
259386
259388
259389 i += partition_end[i] - row_idx - 1;
259390 if (i >= count) {
259391 return;
259392 }
259393 row_idx = partition_end[i] - 1;
259394 continue;
259395 }
259396
259397
259399 for (
idx_t n = prev_n + 1; n < frame_width; ++n) {
259400 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259401 if (!order_value_func(j, order_cursor)) {
259402 break;
259403 }
259404 if (value_func(j, cursor)) {
259405 next_valid = j;
259406 break;
259407 }
259408 }
259409
259410
259412 for (
idx_t n = prev_n; n-- > 0;) {
259413 auto j = gfstate.value_tree->SelectNth(frames, n).first;
259414 if (!order_value_func(j, order_cursor)) {
259415 break;
259416 }
259417 if (value_func(j, cursor)) {
259418 next_valid = j;
259419
259420 std::swap(prev_valid, next_valid);
259421 break;
259422 }
259423 }
259424 }
259425
259426
259428 cursor.CopyCell(0, prev_valid, result, i);
259429 continue;
259430 }
259431
259432
259433
259434 const auto slope = slope_func(order_cursor, row_idx, prev_valid, next_valid);
259435 interpolate_func(result, i, cursor, prev_valid, next_valid, slope);
259436 }
259437 return;
259438 }
259439
259440 auto valid_begin = FlatVector::GetData<const idx_t>(lfstate.bounds.data[VALID_BEGIN]);
259441 auto valid_end = FlatVector::GetData<const idx_t>(lfstate.bounds.data[VALID_END]);
259442 auto &order_cursor = *lfstate.range_cursor;
259444 auto slope_func = GetFillSlopeFunction(wexpr.orders[0].expression->return_type);
259445 auto order_value_func = GetFillValueFunction(wexpr.orders[0].expression->return_type);
259446
259447 for (
idx_t i = 0; i < count; ++i, ++row_idx) {
259448
259449 if (prev_partition != partition_begin[i]) {
259450 prev_partition = partition_begin[i];
259453 }
259454
259455
259456 if (row_idx < valid_begin[i] || valid_end[i] <= row_idx || !order_value_func(row_idx, order_cursor)) {
259457 continue;
259458 }
259459
259460
259461 const auto idx = arg_data.sel->get_index(i);
259462 if (arg_data.validity.RowIsValid(idx)) {
259463
259464 if (value_func(row_idx, cursor)) {
259465 prev_valid = row_idx;
259466 }
259467 continue;
259468 }
259469
259470
259471
259472
259474 for (
idx_t j = row_idx; j-- > valid_begin[i];) {
259475 if (!order_value_func(j, order_cursor)) {
259476 break;
259477 }
259478 if (value_func(j, cursor)) {
259479 prev_valid = j;
259480 break;
259481 }
259482 }
259483 }
259484
259485
259487 for (
idx_t j = row_idx + 1; j < valid_end[i]; ++j) {
259488 if (!order_value_func(j, order_cursor)) {
259489 break;
259490 }
259491 if (value_func(j, cursor)) {
259492 prev_valid = j;
259493 break;
259494 }
259495 }
259496 }
259497
259498
259500
259501 i += partition_end[i] - row_idx - 1;
259502 if (i >= count) {
259503 break;
259504 }
259505 row_idx = partition_end[i] - 1;
259506 continue;
259507 }
259508
259509
259511 for (
idx_t j = prev_valid + 1; j < valid_end[i]; ++j) {
259512 if (!order_value_func(j, order_cursor)) {
259513 break;
259514 }
259515 if (value_func(j, cursor)) {
259516 next_valid = j;
259517 break;
259518 }
259519 }
259520
259521
259523 for (
idx_t j = prev_valid; j-- > valid_begin[i];) {
259524 if (!order_value_func(j, order_cursor)) {
259525 break;
259526 }
259527 if (value_func(j, cursor)) {
259528 next_valid = j;
259529
259530 std::swap(prev_valid, next_valid);
259531 break;
259532 }
259533 }
259534 }
259535
259536
259538 cursor.CopyCell(0, prev_valid, result, i);
259539 continue;
259540 }
259541
259542
259543
259544 const auto slope = slope_func(order_cursor, row_idx, prev_valid, next_valid);
259545 interpolate_func(result, i, cursor, prev_valid, next_valid, slope);
259546 }
259547}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117