|
33 | 33 | (pa.large_binary(), "binary"), |
34 | 34 | (pa.date32(), "date"), |
35 | 35 | (pa.timestamp("us"), "timestamp"), |
| 36 | + (pa.time32("ms"), "time"), |
| 37 | + (pa.time64("us"), "time"), |
| 38 | + (pa.time64("ns"), "time"), |
36 | 39 | (pa.list_(pa.int32()), "array"), |
37 | 40 | (pa.large_list(pa.int32()), "array"), |
38 | 41 | (pa.struct([("a", pa.int32())]), "struct"), |
@@ -145,6 +148,74 @@ def test_description_recovers_complex_type_name_from_metadata(metadata_value, ex |
145 | 148 | assert desc[0][1] == expected |
146 | 149 |
|
147 | 150 |
|
| 151 | +def test_description_recovers_time_type_name_from_metadata(): |
| 152 | + """TIME columns arrive over SEA as time32/time64, or as Utf8 in |
| 153 | + an empty-result manifest whose physical schema carries no TIME |
| 154 | + shape. The kernel annotates the field with |
| 155 | + ``databricks.type_name=TIME``; ``description`` must report |
| 156 | + ``time`` rather than the raw Arrow spelling (``time64[ns]``) or |
| 157 | + ``string``. Mirrors the Thrift backend, which recovers TIME from |
| 158 | + the ``Spark:DataType:SqlName`` Arrow metadata.""" |
| 159 | + schema = pa.schema( |
| 160 | + [ |
| 161 | + pa.field( |
| 162 | + "t", |
| 163 | + pa.time64("ns"), |
| 164 | + metadata={b"databricks.type_name": b"TIME"}, |
| 165 | + ), |
| 166 | + # Empty-manifest shape: Utf8 physical type, logical TIME |
| 167 | + # in metadata — the DATATYPE-044 zero-row case. |
| 168 | + pa.field( |
| 169 | + "e", |
| 170 | + pa.string(), |
| 171 | + metadata={b"databricks.type_name": b"TIME"}, |
| 172 | + ), |
| 173 | + # Declared precision rides along in the metadata value. |
| 174 | + pa.field( |
| 175 | + "p", |
| 176 | + pa.string(), |
| 177 | + metadata={b"databricks.type_name": b"TIME(6)"}, |
| 178 | + ), |
| 179 | + # Plain time64 without metadata still reports ``time`` |
| 180 | + # via the Arrow shape — the DATATYPE-044 NULL-only case |
| 181 | + # when no logical-type metadata is present. |
| 182 | + pa.field("n", pa.time64("us")), |
| 183 | + # Plain Utf8 without the metadata stays ``string``. |
| 184 | + pa.field("s", pa.string()), |
| 185 | + ] |
| 186 | + ) |
| 187 | + desc = description_from_arrow_schema(schema) |
| 188 | + assert [d[1] for d in desc] == ["time", "time", "time", "time", "string"] |
| 189 | + |
| 190 | + |
| 191 | +@pytest.mark.parametrize( |
| 192 | + "metadata_value, expected", |
| 193 | + [ |
| 194 | + (b"TIME", "time"), |
| 195 | + (b"time", "time"), |
| 196 | + (b"Time", "time"), |
| 197 | + (b"TIME(6)", "time"), |
| 198 | + ], |
| 199 | +) |
| 200 | +def test_description_recovers_time_type_name_case_and_precision( |
| 201 | + metadata_value, expected |
| 202 | +): |
| 203 | + """``databricks.type_name`` matching is case-insensitive and |
| 204 | + tolerates a declared precision, matching the Thrift backend's |
| 205 | + SqlName remap (``TIME`` / ``TIME(6)`` / ``time(3)``).""" |
| 206 | + schema = pa.schema( |
| 207 | + [ |
| 208 | + pa.field( |
| 209 | + "t", |
| 210 | + pa.string(), |
| 211 | + metadata={b"databricks.type_name": metadata_value}, |
| 212 | + ), |
| 213 | + ] |
| 214 | + ) |
| 215 | + desc = description_from_arrow_schema(schema) |
| 216 | + assert desc[0][1] == expected |
| 217 | + |
| 218 | + |
148 | 219 | @pytest.mark.parametrize( |
149 | 220 | "metadata_value, expected", |
150 | 221 | [ |
@@ -227,6 +298,7 @@ def test_description_non_decimal_columns_have_none_precision_scale(): |
227 | 298 | ("i", pa.int64()), |
228 | 299 | ("s", pa.string()), |
229 | 300 | ("ts", pa.timestamp("us")), |
| 301 | + ("t", pa.time64("ns")), |
230 | 302 | ] |
231 | 303 | ) |
232 | 304 | desc = description_from_arrow_schema(schema) |
|
0 commit comments