@@ -472,5 +472,51 @@ select arrow_metadata(with_metadata(id, 'unit', ''), 'unit') from table_with_met
472472----
473473(empty)
474474
475+ # Regression test: window functions should preserve field metadata
476+ # Test FIRST_VALUE window function preserves metadata
477+ query IT
478+ select
479+ first_value(id) over (order by id asc nulls last) as fv,
480+ arrow_metadata(first_value(id) over (order by id asc nulls last), 'metadata_key') as meta
481+ from table_with_metadata limit 1;
482+ ----
483+ 1 the id field
484+
485+ # Test LAST_VALUE window function preserves metadata
486+ query IT
487+ select
488+ last_value(id) over (order by id asc nulls last rows between unbounded preceding and unbounded following) as lv,
489+ arrow_metadata(last_value(id) over (order by id asc nulls last rows between unbounded preceding and unbounded following), 'metadata_key') as meta
490+ from table_with_metadata limit 1;
491+ ----
492+ NULL the id field
493+
494+ # Test NTH_VALUE window function preserves metadata
495+ query IT
496+ select
497+ nth_value(id, 2) over (order by id asc nulls last) as nv,
498+ arrow_metadata(nth_value(id, 2) over (order by id asc nulls last), 'metadata_key') as meta
499+ from table_with_metadata limit 1;
500+ ----
501+ NULL the id field
502+
503+ # Test LEAD window function preserves metadata
504+ query IT
505+ select
506+ lead(id) over (order by id asc nulls last) as ld,
507+ arrow_metadata(lead(id) over (order by id asc nulls last), 'metadata_key') as meta
508+ from table_with_metadata limit 1;
509+ ----
510+ 3 the id field
511+
512+ # Test LAG window function preserves metadata
513+ query IT
514+ select
515+ lag(id) over (order by id asc nulls last) as lg,
516+ arrow_metadata(lag(id) over (order by id asc nulls last), 'metadata_key') as meta
517+ from table_with_metadata limit 1;
518+ ----
519+ NULL the id field
520+
475521statement ok
476522drop table table_with_metadata;
0 commit comments