1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
|
# name: test/sql/window/test_fill.test_slow
# description: Test Fill function
# group: [window]
#
# Error checks
#
# Only one ordering allowed
statement error
select fill(i) over (order by i, 10-i) from range(3) tbl(i);
----
FILL functions must have only one ORDER BY expression
# Streaming not supported because the interpolation values might be too far away.
statement error
select fill(i) over () from range(3) tbl(i);
----
FILL functions must have only one ORDER BY expression
# Argument must be numeric
statement error
select fill(i::VARCHAR) over (order by i) from range(3) tbl(i);
----
FILL argument must support subtraction
# Ordering must be numeric
statement error
select fill(i) over (order by i::VARCHAR) from range(3) tbl(i);
----
FILL ordering must support subtraction
# No values in partition chunk
statement ok
with null_chunk as (
select
1 as p,
s,
NULL::DOUBLE as v,
from range(2050) tbl(s)
union all
select
2 as p,
s,
s::DOUBLE as v,
from range(16) tbl(s)
)
select
p,
s,
fill(v) over(partition by p order by s) as f,
from null_chunk
#
# Simple interpolation coverage tests
#
foreach ordertype tinyint smallint integer bigint hugeint float double utinyint usmallint uinteger ubigint uhugeint
foreach filltype tinyint smallint integer bigint hugeint float double utinyint usmallint uinteger ubigint uhugeint
loop nulled 0 3
# Between, before and after
query II
select
i,
fill(if(i = ${nulled}, NULL, i)::${filltype}) over(order by i::${ordertype}) as f
from range(3) tbl(i)
qualify i is distinct from f
----
endloop
# Single values
query II
select
i,
fill(if(i > 0, NULL, i)::${filltype}) over(order by i::${ordertype}) as f
from range(3) tbl(i)
qualify f is distinct from 0
----
# No values in partition
query II
select
i,
fill(if(i < 4, NULL, i)::${filltype}) over(partition by i // 2 order by i::${ordertype}) f
from range(8) tbl(i)
order by i
----
0 NULL
1 NULL
2 NULL
3 NULL
4 4
5 5
6 6
7 7
# Outside valid sort values
query II
select
i,
fill(if(i = 2, NULL, i)::${filltype}) over(order by if(i < 4, NULL, i)::${ordertype}) f
from range(8) tbl(i)
qualify i is distinct from f
order by i
----
2 NULL
foreach sense asc desc
foreach nulls first last
# NULL sort key coverage
query II
select
i,
fill(i::${filltype}) over(order by i::${ordertype} ${sense} nulls ${nulls}) f
from (
from range(3) r(i)
union all
select NULL as i
) tbl(i)
qualify i is distinct from f
order by i
----
endloop
endloop
endloop
endloop
foreach ordertype smallint integer bigint hugeint float double usmallint uinteger ubigint uhugeint
foreach filltype smallint integer bigint hugeint float double usmallint uinteger ubigint uhugeint
# Previous in another chunk
query II
select
i,
fill(if(i = 2048, NULL, i)::${filltype}) over(order by i::${ordertype}) f
from range(2060) tbl(i)
qualify i <> f
----
endloop
endloop
#
# Temporal coverage
#
foreach ordertype date timestamp timestamptz
foreach filltype date timestamp timestamptz
loop nulled 1 4
# Before, Between and After values
query II
select
i,
fill(if(day(i) = ${nulled}, NULL, i)::${filltype}) over(order by i::${ordertype}) f
from range('2025-01-01'::DATE, '2025-01-04'::DATE, INTERVAL 1 DAY) tbl(i)
qualify f <> i
----
endloop
foreach sense asc desc
foreach nulls first last
# NULL sort key coverage
query II
select
i,
fill(i::${filltype}) over(order by i::${ordertype} ${sense} nulls ${nulls}) f
from (
from range('2025-01-01'::DATE, '2025-01-04'::DATE, INTERVAL 1 DAY) r(i)
union all
select NULL as i
) tbl(i)
qualify i is distinct from f
order by i
----
endloop
endloop
# Single values
query II
select
i,
fill(if(day(i) > 1, NULL, i)::${filltype}) over(order by i::${ordertype}) f
from range('2025-01-01'::DATE, '2025-01-04'::DATE, INTERVAL 1 DAY) tbl(i)
qualify f <> '2025-01-01'::DATE
----
# No values in partition
query II
select
i,
fill(if(day(i) < 5, NULL, i)::${filltype}) over(partition by (day(i) - 1) // 2 order by i::${ordertype}) f
from range('2025-01-01'::DATE, '2025-01-09'::DATE, INTERVAL 1 DAY) tbl(i)
qualify f is NULL
order by i
----
2025-01-01 00:00:00 NULL
2025-01-02 00:00:00 NULL
2025-01-03 00:00:00 NULL
2025-01-04 00:00:00 NULL
# Outside valid sort values
query II
select
i,
fill(if(day(i) = 3, NULL, i)::${filltype}) over(order by if(day(i) < 5, NULL, i)::${ordertype}) f
from range('2025-01-01'::DATE, '2025-01-09'::DATE, INTERVAL 1 DAY) tbl(i)
qualify i is distinct from f
order by i
----
2025-01-03 00:00:00 NULL
# Previous in another chunk
query II
select
i,
fill(if(i = '2015-01-01'::DATE + 2048, NULL, i)::${filltype}) over(order by i::${ordertype}) f
from range('2025-01-01'::DATE, '2020-08-22'::DATE, INTERVAL 1 DAY) tbl(i)
qualify i <> f
----
endloop
endloop
# Time
loop nulled 1 4
# Before, Between and After values
query II
select
i::TIME t,
fill(if(minute(i) = ${nulled}, NULL, i)::TIME) over(order by i::TIME) f
from range('2025-01-01'::TIMESTAMP, '2025-01-01 00:03'::TIMESTAMP, INTERVAL 1 MINUTE) tbl(i)
qualify f <> t
----
endloop
foreach sense asc desc
foreach nulls first last
# NULL sort key coverage
query II
select
i::TIME t,
fill(t) over(order by t ${sense} nulls ${nulls}) f
from (
from range('2025-01-01'::TIMESTAMP, '2025-01-01 00:03'::TIMESTAMP, INTERVAL 1 MINUTE) r(i)
union all
select NULL as i
) tbl(i)
qualify t is distinct from f
order by t
----
endloop
endloop
# Single values
query II
select
i::TIME t,
fill(if(minute(i) > 0, NULL, i)::TIME) over(order by i::TIME) f
from range('2025-01-01'::TIMESTAMP, '2025-01-01 00:03'::TIMESTAMP, INTERVAL 1 MINUTE) tbl(i)
qualify f <> '00:00:00'::TIME
----
# No values in partition
query II
select
i::TIME t,
fill(if(minute(i) < 4, NULL, i)::TIME) over(partition by minute(i) // 2 order by i::TIME) f
from range('2025-01-01'::TIMESTAMP, '2025-01-01 00:09'::TIMESTAMP, INTERVAL 1 MINUTE) tbl(i)
qualify f is not NULL
order by t
----
00:04:00 00:04:00
00:05:00 00:05:00
00:06:00 00:06:00
00:07:00 00:07:00
00:08:00 00:08:00
# Outside valid sort values
query II
select
i::TIME t,
fill(if(minute(i) = 3, NULL, i)::TIME) over(order by if(minute(i) < 4, NULL, i)::TIME) f
from range('2025-01-01'::TIMESTAMP, '2025-01-01 00:09'::TIMESTAMP, INTERVAL 1 MINUTE) tbl(i)
qualify t is distinct from f
order by t
----
00:03:00 NULL
# Previous in another chunk
query II
select
i::TIME t,
fill(if(i = '2015-01-01'::TIMESTAMP + INTERVAL 2048 SECOND, NULL, i)::TIME) over(order by i::TIME) f
from range('2025-01-01'::TIMESTAMP, '2025-01-01 00:34:20'::TIMESTAMP, INTERVAL 1 SECOND) tbl(i)
qualify t <> f
----
#
# Extrapolation failures
#
# Signed
query II
with source as (
select
i,
if(i = -129, NULL, i)::TINYINT as missing
from range(-129, -120) tbl(i)
)
select
i,
fill(missing) over (order by i) as filled
from source
qualify filled is distinct from i
----
-129 NULL
query II
with source as (
select
i,
if(i = 128, NULL, i)::TINYINT as missing
from range(120, 129) tbl(i)
)
select
i,
fill(missing) over (order by i) as filled
from source
qualify filled is distinct from i
----
128 NULL
# Unsigned
query II
with source as (
select
i,
if(i = -1, NULL, i)::UTINYINT as missing
from range(-1, 10) tbl(i)
)
select
i,
fill(missing) over (order by i) as filled
from source
qualify filled is distinct from i
----
-1 NULL
query II
with source as (
select
i,
if(i = 256, NULL, i)::UTINYINT as missing
from range(250, 257) tbl(i)
)
select
i,
fill(missing) over (order by i) as filled
from source
qualify filled is distinct from i
----
256 NULL
#
# Unusable values
#
# If we use an unsuable value, the interpolation will produce strange values
# Infinity/NaN
foreach ordertype float double
foreach unusable 'infinity' '-infinity' 'NaN'
loop nullable 0 5
query II
select
i,
fill(if(i = ${nullable}, NULL, i)) over(order by i) f
from (
from range(5) r(i)
union all
select ${unusable}::${ordertype} as i
) tbl(i)
qualify i is distinct from f
order by i
----
endloop
endloop
endloop
# Temporal infinities
foreach ordertype date timestamp
foreach filltype date timestamp
foreach unusable 'infinity' '-infinity'
loop nulled 1 4
query II
select
i,
fill(if(day(i) = ${nulled}, NULL, i)::${filltype}) over(order by i::${ordertype}) f
from (
from range('2025-01-01'::DATE, '2025-01-05'::DATE, INTERVAL 1 DAY) r(i)
union all
select ${unusable}::${ordertype} as i
) tbl(i)
qualify f is NULL
order by i
----
endloop
endloop
endloop
endloop
|