|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
| 18 | +import datetime |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
18 | 22 | from datafusion import ( |
19 | 23 | ExecutionPlan, |
20 | 24 | LogicalPlan, |
@@ -150,3 +154,38 @@ def test_execute_stream_partitioned_metrics() -> None: |
150 | 154 | if ms.output_rows is not None |
151 | 155 | ] |
152 | 156 | assert 2 in output_rows_values |
| 157 | + |
| 158 | + |
| 159 | +def test_value_as_datetime() -> None: |
| 160 | + ctx = SessionContext() |
| 161 | + ctx.sql("CREATE TABLE t AS VALUES (1, 'a'), (2, 'b'), (3, 'c')") |
| 162 | + df = ctx.sql("SELECT * FROM t WHERE column1 > 1") |
| 163 | + df.collect() |
| 164 | + plan = df.execution_plan() |
| 165 | + |
| 166 | + for _, ms in plan.collect_metrics(): |
| 167 | + for metric in ms.metrics(): |
| 168 | + if metric.name in ("start_timestamp", "end_timestamp"): |
| 169 | + dt = metric.value_as_datetime |
| 170 | + assert dt is None or isinstance(dt, datetime.datetime) |
| 171 | + if dt is not None: |
| 172 | + assert dt.tzinfo is not None |
| 173 | + else: |
| 174 | + assert metric.value_as_datetime is None |
| 175 | + |
| 176 | + |
| 177 | +def test_collect_twice_reuses_plan() -> None: |
| 178 | + ctx = SessionContext() |
| 179 | + ctx.sql("CREATE TABLE t AS VALUES (1, 'a'), (2, 'b'), (3, 'c')") |
| 180 | + df = ctx.sql("SELECT * FROM t WHERE column1 > 1") |
| 181 | + |
| 182 | + df.collect() |
| 183 | + df.collect() |
| 184 | + |
| 185 | + plan = df.execution_plan() |
| 186 | + output_rows_values = [ |
| 187 | + ms.output_rows |
| 188 | + for _, ms in plan.collect_metrics() |
| 189 | + if ms.output_rows is not None |
| 190 | + ] |
| 191 | + assert len(output_rows_values) > 0 |
0 commit comments