|
18 | 18 | # Tests for `date_part` and `EXTRACT` (which is a different syntax |
19 | 19 | # for the same function). |
20 | 20 |
|
| 21 | + |
| 22 | +## Begin tests fo rdate_part with columns and timestamp's with timezones |
| 23 | + |
| 24 | +# Source data table has |
| 25 | +# timestamps with millisecond (very common timestamp precision) and nanosecond (maximum precision) timestamps |
| 26 | +statement count 0 |
| 27 | +CREATE TABLE source_ts AS |
| 28 | +with t as (values |
| 29 | + ('2020-01-01T00:00:00+00:00'), |
| 30 | + ('2021-01-01T00:00:00+00:00'), -- year |
| 31 | + ('2020-09-01T00:00:00+00:00'), -- month |
| 32 | + ('2020-01-25T00:00:00+00:00'), -- day |
| 33 | + ('2020-01-24T00:00:00+00:00'), -- day |
| 34 | + ('2020-01-01T12:00:00+00:00'), -- hour |
| 35 | + ('2020-01-01T00:30:00+00:00'), -- minute |
| 36 | + ('2020-01-01T00:00:30+00:00'), -- second |
| 37 | + ('2020-01-01T00:00:00.123+00:00'), -- ms |
| 38 | + ('2020-01-01T00:00:00.123456+00:00'), -- us |
| 39 | + ('2020-01-01T00:00:00.123456789+00:00') -- ns |
| 40 | +) |
| 41 | +SELECT |
| 42 | + -- nanoseconds, with no, utc, and local timezone |
| 43 | + arrow_cast(column1, 'Timestamp(Nanosecond, None)') as ts_nano_no_tz, |
| 44 | + arrow_cast(column1, 'Timestamp(Nanosecond, Some("UTC"))') as ts_nano_utc, |
| 45 | + arrow_cast(column1, 'Timestamp(Nanosecond, Some("America/New_York"))') as ts_nano_eastern, |
| 46 | + -- milliseconds, with no, utc, and local timezone |
| 47 | + arrow_cast(column1, 'Timestamp(Millisecond, None)') as ts_milli_no_tz, |
| 48 | + arrow_cast(column1, 'Timestamp(Millisecond, Some("UTC"))') as ts_milli_utc, |
| 49 | + arrow_cast(column1, 'Timestamp(Millisecond, Some("America/New_York"))') as ts_milli_eastern |
| 50 | +FROM t; |
| 51 | + |
| 52 | + |
| 53 | +query PPPPPP |
| 54 | +SELECT * FROM source_ts; |
| 55 | +---- |
| 56 | +2020-01-01T00:00:00 2020-01-01T00:00:00Z 2019-12-31T19:00:00-05:00 2020-01-01T00:00:00 2020-01-01T00:00:00Z 2019-12-31T19:00:00-05:00 |
| 57 | +2021-01-01T00:00:00 2021-01-01T00:00:00Z 2020-12-31T19:00:00-05:00 2021-01-01T00:00:00 2021-01-01T00:00:00Z 2020-12-31T19:00:00-05:00 |
| 58 | +2020-09-01T00:00:00 2020-09-01T00:00:00Z 2020-08-31T20:00:00-04:00 2020-09-01T00:00:00 2020-09-01T00:00:00Z 2020-08-31T20:00:00-04:00 |
| 59 | +2020-01-25T00:00:00 2020-01-25T00:00:00Z 2020-01-24T19:00:00-05:00 2020-01-25T00:00:00 2020-01-25T00:00:00Z 2020-01-24T19:00:00-05:00 |
| 60 | +2020-01-24T00:00:00 2020-01-24T00:00:00Z 2020-01-23T19:00:00-05:00 2020-01-24T00:00:00 2020-01-24T00:00:00Z 2020-01-23T19:00:00-05:00 |
| 61 | +2020-01-01T12:00:00 2020-01-01T12:00:00Z 2020-01-01T07:00:00-05:00 2020-01-01T12:00:00 2020-01-01T12:00:00Z 2020-01-01T07:00:00-05:00 |
| 62 | +2020-01-01T00:30:00 2020-01-01T00:30:00Z 2019-12-31T19:30:00-05:00 2020-01-01T00:30:00 2020-01-01T00:30:00Z 2019-12-31T19:30:00-05:00 |
| 63 | +2020-01-01T00:00:30 2020-01-01T00:00:30Z 2019-12-31T19:00:30-05:00 2020-01-01T00:00:30 2020-01-01T00:00:30Z 2019-12-31T19:00:30-05:00 |
| 64 | +2020-01-01T00:00:00.123 2020-01-01T00:00:00.123Z 2019-12-31T19:00:00.123-05:00 2020-01-01T00:00:00.123 2020-01-01T00:00:00.123Z 2019-12-31T19:00:00.123-05:00 |
| 65 | +2020-01-01T00:00:00.123456 2020-01-01T00:00:00.123456Z 2019-12-31T19:00:00.123456-05:00 2020-01-01T00:00:00.123 2020-01-01T00:00:00.123Z 2019-12-31T19:00:00.123-05:00 |
| 66 | +2020-01-01T00:00:00.123456789 2020-01-01T00:00:00.123456789Z 2019-12-31T19:00:00.123456789-05:00 2020-01-01T00:00:00.123 2020-01-01T00:00:00.123Z 2019-12-31T19:00:00.123-05:00 |
| 67 | + |
| 68 | +# date_part (year) with columns and explicit timestamp |
| 69 | +query IIIIII |
| 70 | +SELECT date_part('year', ts_nano_no_tz), date_part('year', ts_nano_utc), date_part('year', ts_nano_eastern), date_part('year', ts_milli_no_tz), date_part('year', ts_milli_utc), date_part('year', ts_milli_eastern) FROM source_ts; |
| 71 | +---- |
| 72 | +2020 2020 2019 2020 2020 2019 |
| 73 | +2021 2021 2020 2021 2021 2020 |
| 74 | +2020 2020 2020 2020 2020 2020 |
| 75 | +2020 2020 2020 2020 2020 2020 |
| 76 | +2020 2020 2020 2020 2020 2020 |
| 77 | +2020 2020 2020 2020 2020 2020 |
| 78 | +2020 2020 2019 2020 2020 2019 |
| 79 | +2020 2020 2019 2020 2020 2019 |
| 80 | +2020 2020 2019 2020 2020 2019 |
| 81 | +2020 2020 2019 2020 2020 2019 |
| 82 | +2020 2020 2019 2020 2020 2019 |
| 83 | + |
| 84 | +# date_part (month) |
| 85 | +query IIIIII |
| 86 | +SELECT date_part('month', ts_nano_no_tz), date_part('month', ts_nano_utc), date_part('month', ts_nano_eastern), date_part('month', ts_milli_no_tz), date_part('month', ts_milli_utc), date_part('month', ts_milli_eastern) FROM source_ts; |
| 87 | +---- |
| 88 | +1 1 12 1 1 12 |
| 89 | +1 1 12 1 1 12 |
| 90 | +9 9 8 9 9 8 |
| 91 | +1 1 1 1 1 1 |
| 92 | +1 1 1 1 1 1 |
| 93 | +1 1 1 1 1 1 |
| 94 | +1 1 12 1 1 12 |
| 95 | +1 1 12 1 1 12 |
| 96 | +1 1 12 1 1 12 |
| 97 | +1 1 12 1 1 12 |
| 98 | +1 1 12 1 1 12 |
| 99 | + |
| 100 | +# date_part (day) |
| 101 | +query IIIIII |
| 102 | +SELECT date_part('day', ts_nano_no_tz), date_part('day', ts_nano_utc), date_part('day', ts_nano_eastern), date_part('day', ts_milli_no_tz), date_part('day', ts_milli_utc), date_part('day', ts_milli_eastern) FROM source_ts; |
| 103 | +---- |
| 104 | +1 1 31 1 1 31 |
| 105 | +1 1 31 1 1 31 |
| 106 | +1 1 31 1 1 31 |
| 107 | +25 25 24 25 25 24 |
| 108 | +24 24 23 24 24 23 |
| 109 | +1 1 1 1 1 1 |
| 110 | +1 1 31 1 1 31 |
| 111 | +1 1 31 1 1 31 |
| 112 | +1 1 31 1 1 31 |
| 113 | +1 1 31 1 1 31 |
| 114 | +1 1 31 1 1 31 |
| 115 | + |
| 116 | +# date_part (hour) |
| 117 | +query IIIIII |
| 118 | +SELECT date_part('hour', ts_nano_no_tz), date_part('hour', ts_nano_utc), date_part('hour', ts_nano_eastern), date_part('hour', ts_milli_no_tz), date_part('hour', ts_milli_utc), date_part('hour', ts_milli_eastern) FROM source_ts; |
| 119 | +---- |
| 120 | +0 0 19 0 0 19 |
| 121 | +0 0 19 0 0 19 |
| 122 | +0 0 20 0 0 20 |
| 123 | +0 0 19 0 0 19 |
| 124 | +0 0 19 0 0 19 |
| 125 | +12 12 7 12 12 7 |
| 126 | +0 0 19 0 0 19 |
| 127 | +0 0 19 0 0 19 |
| 128 | +0 0 19 0 0 19 |
| 129 | +0 0 19 0 0 19 |
| 130 | +0 0 19 0 0 19 |
| 131 | + |
| 132 | +# date_part (minute) |
| 133 | +query IIIIII |
| 134 | +SELECT date_part('minute', ts_nano_no_tz), date_part('minute', ts_nano_utc), date_part('minute', ts_nano_eastern), date_part('minute', ts_milli_no_tz), date_part('minute', ts_milli_utc), date_part('minute', ts_milli_eastern) FROM source_ts; |
| 135 | +---- |
| 136 | +0 0 0 0 0 0 |
| 137 | +0 0 0 0 0 0 |
| 138 | +0 0 0 0 0 0 |
| 139 | +0 0 0 0 0 0 |
| 140 | +0 0 0 0 0 0 |
| 141 | +0 0 0 0 0 0 |
| 142 | +30 30 30 30 30 30 |
| 143 | +0 0 0 0 0 0 |
| 144 | +0 0 0 0 0 0 |
| 145 | +0 0 0 0 0 0 |
| 146 | +0 0 0 0 0 0 |
| 147 | + |
| 148 | +# date_part (second) |
| 149 | +query IIIIII |
| 150 | +SELECT date_part('second', ts_nano_no_tz), date_part('second', ts_nano_utc), date_part('second', ts_nano_eastern), date_part('second', ts_milli_no_tz), date_part('second', ts_milli_utc), date_part('second', ts_milli_eastern) FROM source_ts; |
| 151 | +---- |
| 152 | +0 0 0 0 0 0 |
| 153 | +0 0 0 0 0 0 |
| 154 | +0 0 0 0 0 0 |
| 155 | +0 0 0 0 0 0 |
| 156 | +0 0 0 0 0 0 |
| 157 | +0 0 0 0 0 0 |
| 158 | +0 0 0 0 0 0 |
| 159 | +30 30 30 30 30 30 |
| 160 | +0 0 0 0 0 0 |
| 161 | +0 0 0 0 0 0 |
| 162 | +0 0 0 0 0 0 |
| 163 | + |
| 164 | +# date_part (millisecond) |
| 165 | +query IIIIII |
| 166 | +SELECT date_part('millisecond', ts_nano_no_tz), date_part('millisecond', ts_nano_utc), date_part('millisecond', ts_nano_eastern), date_part('millisecond', ts_milli_no_tz), date_part('millisecond', ts_milli_utc), date_part('millisecond', ts_milli_eastern) FROM source_ts; |
| 167 | +---- |
| 168 | +0 0 0 0 0 0 |
| 169 | +0 0 0 0 0 0 |
| 170 | +0 0 0 0 0 0 |
| 171 | +0 0 0 0 0 0 |
| 172 | +0 0 0 0 0 0 |
| 173 | +0 0 0 0 0 0 |
| 174 | +0 0 0 0 0 0 |
| 175 | +30000 30000 30000 30000 30000 30000 |
| 176 | +123 123 123 123 123 123 |
| 177 | +123 123 123 123 123 123 |
| 178 | +123 123 123 123 123 123 |
| 179 | + |
| 180 | +# date_part (microsecond) |
| 181 | +query IIIIII |
| 182 | +SELECT date_part('microsecond', ts_nano_no_tz), date_part('microsecond', ts_nano_utc), date_part('microsecond', ts_nano_eastern), date_part('microsecond', ts_milli_no_tz), date_part('microsecond', ts_milli_utc), date_part('microsecond', ts_milli_eastern) FROM source_ts; |
| 183 | +---- |
| 184 | +0 0 0 0 0 0 |
| 185 | +0 0 0 0 0 0 |
| 186 | +0 0 0 0 0 0 |
| 187 | +0 0 0 0 0 0 |
| 188 | +0 0 0 0 0 0 |
| 189 | +0 0 0 0 0 0 |
| 190 | +0 0 0 0 0 0 |
| 191 | +30000000 30000000 30000000 30000000 30000000 30000000 |
| 192 | +123000 123000 123000 123000 123000 123000 |
| 193 | +123456 123456 123456 123000 123000 123000 |
| 194 | +123456 123456 123456 123000 123000 123000 |
| 195 | + |
| 196 | +### Cleanup |
| 197 | +statement ok |
| 198 | +drop table source_ts; |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +## "Unit style" tests for types and units on scalar values |
| 203 | + |
| 204 | + |
21 | 205 | query error |
22 | 206 | SELECT EXTRACT("'''year'''" FROM timestamp '2020-09-08T12:00:00+00:00') |
23 | 207 |
|
@@ -528,11 +712,21 @@ select extract(second from '2024-08-09T12:13:14') |
528 | 712 | ---- |
529 | 713 | 14 |
530 | 714 |
|
| 715 | +query I |
| 716 | +select extract(second from timestamp '2024-08-09T12:13:14') |
| 717 | +---- |
| 718 | +14 |
| 719 | + |
531 | 720 | query I |
532 | 721 | select extract(seconds from '2024-08-09T12:13:14') |
533 | 722 | ---- |
534 | 723 | 14 |
535 | 724 |
|
| 725 | +query I |
| 726 | +select extract(seconds from timestamp '2024-08-09T12:13:14') |
| 727 | +---- |
| 728 | +14 |
| 729 | + |
536 | 730 | query I |
537 | 731 | SELECT extract(second from arrow_cast('23:32:50.123456789'::time, 'Time64(Nanosecond)')) |
538 | 732 | ---- |
|
0 commit comments