MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / writeIntoWindowView

Method writeIntoWindowView

src/Storages/WindowView/StorageWindowView.cpp:1498–1699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1496}
1497
1498void StorageWindowView::writeIntoWindowView(
1499 StorageWindowView & window_view, Block && block, Chunk::ChunkInfoCollection && chunk_infos, ContextPtr local_context)
1500{
1501 window_view.throwIfWindowViewIsDisabled(local_context);
1502 while (window_view.modifying_query)
1503 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1504
1505 const size_t block_rows = block.rows();
1506 if (!window_view.is_proctime && window_view.max_watermark == 0 && block_rows > 0)
1507 {
1508 std::lock_guard lock(window_view.fire_signal_mutex);
1509 const auto & window_column = block.getByName(window_view.timestamp_column_name);
1510 const ColumnUInt32::Container & window_end_data = static_cast<const ColumnUInt32 &>(*window_column.column).getData();
1511 UInt32 first_record_timestamp = window_end_data[0];
1512 window_view.max_watermark = window_view.getWindowUpperBound(first_record_timestamp);
1513
1514 LOG_TRACE(window_view.log, "New max watermark: {}", window_view.max_watermark);
1515 }
1516
1517 Pipe pipe(std::make_shared<SourceFromSingleChunk>(std::make_shared<const Block>(block)));
1518
1519 UInt32 lateness_bound = 0;
1520 UInt32 t_max_watermark = 0;
1521 UInt32 t_max_timestamp = 0;
1522 UInt32 t_max_fired_watermark = 0;
1523 {
1524 std::lock_guard lock(window_view.fire_signal_mutex);
1525 t_max_fired_watermark = window_view.max_fired_watermark;
1526 t_max_watermark = window_view.max_watermark;
1527 t_max_timestamp = window_view.max_timestamp;
1528 }
1529
1530 // Filter outdated data
1531 if (window_view.allowed_lateness && t_max_timestamp != 0)
1532 {
1533 lateness_bound = addTime(t_max_timestamp, window_view.lateness_kind, -window_view.lateness_num_units, *window_view.time_zone);
1534
1535 if (window_view.is_watermark_bounded)
1536 {
1537 UInt32 watermark_lower_bound
1538 = addTime(t_max_watermark, window_view.slide_kind, -window_view.slide_num_units, *window_view.time_zone);
1539
1540 lateness_bound = std::min(watermark_lower_bound, lateness_bound);
1541 }
1542 }
1543 else if (!window_view.is_time_column_func_now)
1544 {
1545 lateness_bound = t_max_fired_watermark;
1546 }
1547
1548 if (lateness_bound > 0) /// Add filter, which leaves rows with timestamp >= lateness_bound
1549 {
1550 auto filter_function = makeASTOperator(
1551 "greaterOrEquals",
1552 make_intrusive<ASTIdentifier>(window_view.timestamp_column_name),
1553 make_intrusive<ASTLiteral>(lateness_bound));
1554
1555 ASTPtr query = filter_function;

Callers

nothing calls this directly

Calls 15

sleep_forFunction · 0.85
addTimeFunction · 0.85
makeASTOperatorFunction · 0.85
TreeRewriterClass · 0.85
ExpressionAnalyzerClass · 0.85
createStorageFunction · 0.85
blocksHaveEqualStructureFunction · 0.85
getByNameMethod · 0.80
getWindowUpperBoundMethod · 0.80
getSourceTableMethod · 0.80
getMergeableQueryMethod · 0.80

Tested by

no test coverage detected