162244 {
162245 auto &gstate = gstate_p.Cast<StreamingWindowGlobalState>();
162246 auto &state = gstate.local_state->Cast<StreamingWindowState>();
162247
162248
162249 const idx_t count = output.size();
162252 column_t col_idx = input_width + expr_idx;
162254 auto &wexpr = expr.Cast<BoundWindowExpression>();
162255 auto &result = output.data[col_idx];
162256 switch (expr.GetExpressionType()) {
162257 case ExpressionType::WINDOW_AGGREGATE:
162258 state.aggregate_states[expr_idx]->Execute(context, output, result);
162259 break;
162260 case ExpressionType::WINDOW_PERCENT_RANK:
162261 case ExpressionType::WINDOW_RANK:
162262 case ExpressionType::WINDOW_RANK_DENSE:
162263
162264 output.data[col_idx].Reference(*state.const_vectors[expr_idx]);
162265 break;
162266 case ExpressionType::WINDOW_FIRST_VALUE:
162267
162268
162269 if (wexpr.ignore_nulls && ConstantVector::IsNull(*state.const_vectors[expr_idx])) {
162270
162271 ExpressionExecutor executor(context.client);
162272 executor.AddExpression(*wexpr.children[0]);
162273 Vector
arg(wexpr.children[0]->return_type);
162274 executor.ExecuteExpression(output,
arg);
162275 UnifiedVectorFormat unified;
162276 arg.ToUnifiedFormat(count, unified);
162277 const auto &validity = unified.validity;
162278 auto &prev = *state.const_vectors[expr_idx];
162279 if (validity.AllValid()) {
162280 prev.Reference(
arg.GetValue(0));
162281 result.Reference(prev);
162282 } else {
162283 auto &sel = state.sel;
162284 Vector
split(wexpr.children[0]->return_type);
162285 split.SetValue(0, prev.GetValue(0));
162287 for (
sel_t i = 0; i < count; ++i) {
162288 if (!s && validity.RowIsValidUnsafe(unified.sel->get_index(i))) {
162289 auto v =
arg.GetValue(i);
162290 prev.Reference(
v);
162291 s = 1;
162293 }
162294 sel.set_index(i, s);
162295 }
162296 result.Slice(split, sel, count);
162297 }
162298 } else {
162299
162300 result.Reference(*state.const_vectors[expr_idx]);
162301 }
162302 break;
162303 case ExpressionType::WINDOW_LAST_VALUE: {
162304
162305 ExpressionExecutor executor(context.client);
162306 executor.AddExpression(*wexpr.children[0]);
162307 if (wexpr.ignore_nulls) {
162308 auto &prev = *state.const_vectors[expr_idx];
162309 Vector
arg(wexpr.children[0]->return_type);
162310 executor.ExecuteExpression(output,
arg);
162311 UnifiedVectorFormat unified;
162312 arg.ToUnifiedFormat(count, unified);
162313 const auto &validity = unified.validity;
162314 if (validity.AllValid()) {
162315 VectorOperations::Copy(
arg, result, count, 0, 0);
162316 } else {
162317
162318 Vector copy(wexpr.children[0]->return_type);
162319 VectorOperations::Copy(
arg, copy, count, 0, 0);
162320
162321 if (!validity.RowIsValidUnsafe(0)) {
162322 VectorOperations::Copy(prev, copy, 1, 0, 0);
162323 }
162324
162325 auto &sel = state.sel;
162326 sel_t non_null = 0;
162327 for (
sel_t i = 0; i < count; ++i) {
162328 if (validity.RowIsValidUnsafe(unified.sel->get_index(i))) {
162329 non_null = i;
162330 }
162331 sel.set_index(i, non_null);
162332 }
162333 result.Slice(copy, sel, count);
162334 }
162335
162336 prev.Reference(result.GetValue(count - 1));
162337 } else {
162338 executor.ExecuteExpression(output, result);
162339 }
162340 break;
162341 }
162342 case ExpressionType::WINDOW_ROW_NUMBER: {
162343
162344 int64_t start_row = gstate.row_number;
162345 auto rdata = FlatVector::GetData<int64_t>(output.data[col_idx]);
162346 for (
idx_t i = 0; i < count; i++) {
162347 rdata[i] = NumericCast<int64_t>(start_row + NumericCast<int64_t>(i));
162348 }
162349 break;
162350 }
162351 case ExpressionType::WINDOW_LAG:
162352 case ExpressionType::WINDOW_LEAD:
162353 state.lead_lag_states[expr_idx]->Execute(context, output, delayed, result);
162354 break;
162355 default:
162356 throw NotImplementedException("%s for StreamingWindow", ExpressionTypeToString(expr.GetExpressionType()));
162357 }
162358 }
162359 gstate.row_number += NumericCast<int64_t>(count);
162360}
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148
internal::named_arg< T, Char > arg(const S &name, const T &arg)
Definition duckdb.cpp:16242
void split(const Mat &src, Mat *mvbegin)
idx_t column_t
Type used for column identifiers.
Definition duckdb.hpp:259
uint32_t sel_t
Type used for the selection vector.
Definition duckdb.hpp:251