Skip to content

Commit

Permalink
test(flink): add flink datatype tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenzhongxu authored and gforsyth committed Dec 6, 2023
1 parent f983bfa commit 620bb2c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/support_matrix.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The changes will show up in the dev docs when your PR is merged!
## Raw Data

```{python}
#| echo: false
#| echo: true
!python ../gen_matrix.py
```

Expand All @@ -45,7 +45,7 @@ You can also download data from the above tables in [CSV format](./backends/raw_
The code used to generate the linked CSV file is below.

```{python}
#| echo: false
#| echo: true
#| output: asis
with open("../gen_matrix.py", mode="r") as f:
print(f"```python\n{f.read()}\n```")
Expand Down
4 changes: 4 additions & 0 deletions ibis/backends/flink/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ def from_ibis(cls, dtype: dt.DataType) -> fl.DataType:
return fl.DataTypes.TIMESTAMP()
else:
return super().from_ibis(dtype)

@classmethod
def to_string(cls, dtype: dt.DataType) -> str:
return cls.from_ibis(dtype).type_name()
38 changes: 38 additions & 0 deletions ibis/backends/flink/tests/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

import pytest
from pytest import param

import ibis.expr.datatypes as dt
from ibis.backends.flink.datatypes import FlinkType


@pytest.mark.parametrize(
("datatype", "expected"),
[
param(dt.float32, "FLOAT", id="float32"),
param(dt.float64, "DOUBLE", id="float64"),
param(dt.uint8, "TINYINT", id="uint8"),
param(dt.uint16, "SMALLINT", id="uint16"),
param(dt.uint32, "INT", id="uint32"),
param(dt.int8, "TINYINT", id="int8"),
param(dt.int16, "SMALLINT", id="int16"),
param(dt.int32, "INT", id="int32"),
param(dt.int64, "BIGINT", id="int64"),
param(dt.string, "VARCHAR", id="string"),
param(dt.date, "DATE", id="date"),
param(dt.timestamp, "TIMESTAMP", id="datetime"),
param(
dt.Timestamp(timezone="UTC"),
"TIMESTAMP",
id="timestamp_with_utc_tz",
),
param(
dt.Timestamp(timezone="US/Eastern"),
"TIMESTAMP",
id="timestamp_with_other_tz",
),
],
)
def test_simple(datatype, expected):
assert FlinkType.to_string(datatype) == expected

0 comments on commit 620bb2c

Please sign in to comment.