|
| 1 | +category = "translation" |
| 2 | +construct = "sf.functions.extract.extract-from" |
| 3 | +session_profile = "utc-v1" |
| 4 | + |
| 5 | +[[case]] |
| 6 | +id = "t001_date_parts" |
| 7 | +description = "Calendar and week parts of dates at year and ISO-week boundaries. Catches: dayofweek on another numbering, week by calendar year, or dayofyear 0-based, or ISO numbering for dayofweek (7 instead of 0 on the Sunday row)" |
| 8 | +columns = [{ name = "d", type = "DATE" }] |
| 9 | +rows = [ |
| 10 | + ["'2024-12-30'"], |
| 11 | + ["'2021-01-01'"], |
| 12 | + ["'2024-02-29'"], |
| 13 | + ["'2023-01-01'"], |
| 14 | +] |
| 15 | +query = "SELECT EXTRACT(year FROM d) AS year, EXTRACT(quarter FROM d) AS quarter, EXTRACT(month FROM d) AS month, EXTRACT(day FROM d) AS day, EXTRACT(dayofweek FROM d) AS dayofweek, EXTRACT(dayofweekiso FROM d) AS dayofweekiso, EXTRACT(dayofyear FROM d) AS dayofyear, EXTRACT(week FROM d) AS week, EXTRACT(weekiso FROM d) AS weekiso, EXTRACT(yearofweekiso FROM d) AS yearofweekiso FROM input ORDER BY ordinal" |
| 16 | +order = "ordered" |
| 17 | +tags = ["type-combination"] |
| 18 | + |
| 19 | +[[case]] |
| 20 | +id = "t002_time_parts" |
| 21 | +description = "Time parts with fractional seconds. Catches: seconds rounded, or nanosecond scaled to milliseconds" |
| 22 | +columns = [{ name = "t", type = "TIMESTAMP_NTZ" }] |
| 23 | +rows = [ |
| 24 | + ["'2024-02-29 13:07:59.123456789'"], |
| 25 | + ["'1969-12-31 23:59:59.5'"], |
| 26 | +] |
| 27 | +query = "SELECT EXTRACT(hour FROM t) AS hour, EXTRACT(minute FROM t) AS minute, EXTRACT(second FROM t) AS second, EXTRACT(nanosecond FROM t) AS nanosecond, EXTRACT(epoch_second FROM t) AS epoch_second, EXTRACT(epoch_millisecond FROM t) AS epoch_millisecond FROM input ORDER BY ordinal" |
| 28 | +order = "ordered" |
| 29 | +tags = ["type-combination"] |
| 30 | + |
| 31 | +[[case]] |
| 32 | +id = "t003_timestamp_tz" |
| 33 | +description = "Parts of a TIMESTAMP_TZ, including its offset and epoch. Catches: parts from the UTC instant instead of the wall clock, timezone_hour sign flipped, or epoch from the wall clock" |
| 34 | +columns = [{ name = "t", type = "TIMESTAMP_TZ" }] |
| 35 | +rows = [ |
| 36 | + ["'2024-12-31 23:30:00.250 -0800'"], |
| 37 | + ["'2024-07-01 00:15:00 +0530'"], |
| 38 | +] |
| 39 | +query = "SELECT EXTRACT(year FROM t) AS year, EXTRACT(day FROM t) AS day, EXTRACT(hour FROM t) AS hour, EXTRACT(minute FROM t) AS minute, EXTRACT(timezone_hour FROM t) AS timezone_hour, EXTRACT(timezone_minute FROM t) AS timezone_minute, EXTRACT(epoch_second FROM t) AS epoch_second FROM input ORDER BY ordinal" |
| 40 | +order = "ordered" |
| 41 | +tags = ["type-combination"] |
| 42 | + |
| 43 | +[[case]] |
| 44 | +id = "t004_time" |
| 45 | +description = "Parts of a TIME. Catches: an error for a TIME, or seconds rounded (46)" |
| 46 | +columns = [{ name = "t", type = "TIME" }] |
| 47 | +rows = [ |
| 48 | + ["'18:30:45.75'"], |
| 49 | +] |
| 50 | +query = "SELECT EXTRACT(hour FROM t) AS hour, EXTRACT(minute FROM t) AS minute, EXTRACT(second FROM t) AS second FROM input ORDER BY ordinal" |
| 51 | +order = "ordered" |
| 52 | +tags = ["type-combination"] |
| 53 | + |
| 54 | +[[case]] |
| 55 | +id = "t006_null_date_interval_time_or_timestamp_expr" |
| 56 | +description = "NULL next to a set date. Catches: NULL read as a default date" |
| 57 | +columns = [{ name = "d", type = "DATE" }] |
| 58 | +rows = [ |
| 59 | + ["NULL"], |
| 60 | + ["'2024-01-02'"], |
| 61 | +] |
| 62 | +query = "SELECT EXTRACT(year FROM d) AS year FROM input ORDER BY ordinal" |
| 63 | +order = "ordered" |
| 64 | +tags = ["null"] |
| 65 | + |
| 66 | +[[case]] |
| 67 | +id = "t007_leap" |
| 68 | +description = "Day of year around 29 February. Catches: a 365-day year in 2024" |
| 69 | +columns = [{ name = "d", type = "DATE" }] |
| 70 | +rows = [ |
| 71 | + ["'2024-02-29'"], |
| 72 | + ["'2024-12-31'"], |
| 73 | + ["'2023-12-31'"], |
| 74 | +] |
| 75 | +query = "SELECT EXTRACT(dayofyear FROM d) AS dayofyear, EXTRACT(day FROM d) AS day FROM input ORDER BY ordinal" |
| 76 | +order = "ordered" |
| 77 | +tags = ["boundary"] |
| 78 | + |
| 79 | +[[case]] |
| 80 | +id = "t008_pre_epoch" |
| 81 | +description = "Epoch parts before 1970. Catches: a truncation toward zero instead of floor for negative epochs" |
| 82 | +columns = [{ name = "t", type = "TIMESTAMP_NTZ" }] |
| 83 | +rows = [ |
| 84 | + ["'1969-12-31 23:59:59.900'"], |
| 85 | + ["'1900-01-01 00:00:00'"], |
| 86 | +] |
| 87 | +query = "SELECT EXTRACT(epoch_second FROM t) AS epoch_second, EXTRACT(epoch_millisecond FROM t) AS epoch_millisecond FROM input ORDER BY ordinal" |
| 88 | +order = "ordered" |
| 89 | +tags = ["boundary"] |
0 commit comments