Skip to content

Commit c87ef66

Browse files
committed
Add timestamp and timestamp_tz insert tests
1 parent 16516a6 commit c87ef66

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

soda-core/src/soda_core/common/sql_dialect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def _build_tuple_sql(self, tuple: TUPLE) -> str:
554554
elements: str = ", ".join(self.build_expression_sql(e) for e in tuple.expressions)
555555
return f"({elements})"
556556

557-
def schema_information_schema(self) -> str:
557+
def schema_information_schema(self) -> str | None:
558558
"""
559559
Name of the schema that has the metadata
560560
"""
@@ -605,9 +605,9 @@ def column_data_type(self) -> str:
605605
"""
606606
return self.default_casify("data_type")
607607

608-
def column_data_type_max_length(self) -> str:
608+
def column_data_type_max_length(self) -> str | COLUMN:
609609
"""
610-
Name of the column that has the max data type length in the tables metadata table.
610+
Name or definition of the column that has the max data type length in the tables metadata table.
611611
Purpose of this method is to allow specific data source to override.
612612
"""
613613
return self.default_casify("character_maximum_length")

soda-tests/tests/features/test_sql_ast_inserts.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
2+
import pytz
33
from helpers.data_source_test_helper import DataSourceTestHelper
44
from soda_core.common.data_source_impl import DataSourceImpl
55
from soda_core.common.data_source_results import QueryResult
@@ -36,6 +36,8 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
3636
CREATE_TABLE_COLUMN(name="name", type=DBDataType.TEXT, length=255, nullable=True),
3737
CREATE_TABLE_COLUMN(name="small_text", type=DBDataType.TEXT, length=3, nullable=True),
3838
CREATE_TABLE_COLUMN(name="my_date", type=DBDataType.DATE, nullable=True),
39+
CREATE_TABLE_COLUMN(name="my_timestamp", type=DBDataType.TIMESTAMP, nullable=True),
40+
CREATE_TABLE_COLUMN(name="my_timestamp_tz", type=DBDataType.TIMESTAMP_TZ, nullable=True),
3941
]
4042

4143
standard_columns = [column.convert_to_standard_column() for column in create_table_columns]
@@ -66,8 +68,26 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
6668
INSERT_INTO(
6769
fully_qualified_table_name=my_table_name,
6870
values=[
69-
VALUES_ROW([LITERAL(1), LITERAL("John"), LITERAL("a"), LITERAL(datetime.date(2021, 1, 1))]),
70-
VALUES_ROW([LITERAL(2), LITERAL("Jane"), LITERAL("b"), LITERAL(datetime.date(2021, 1, 2))]),
71+
VALUES_ROW(
72+
[
73+
LITERAL(1),
74+
LITERAL("John"),
75+
LITERAL("a"),
76+
LITERAL(datetime.date(2021, 1, 1)),
77+
LITERAL(datetime.datetime(2021, 1, 1, 12, 10, 0)),
78+
LITERAL(datetime.datetime(2021, 1, 1, 12, 10, 0, tzinfo=datetime.timezone.utc)),
79+
]
80+
),
81+
VALUES_ROW(
82+
[
83+
LITERAL(2),
84+
LITERAL("Jane"),
85+
LITERAL("b"),
86+
LITERAL(datetime.date(2021, 1, 2)),
87+
LITERAL(datetime.datetime(2021, 1, 2, 12, 10, 0)),
88+
LITERAL(datetime.datetime(2021, 1, 2, 12, 10, 0, tzinfo=pytz.timezone("America/New_York"))),
89+
]
90+
),
7191
],
7292
columns=standard_columns,
7393
)
@@ -94,6 +114,8 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
94114
COLUMN("name"),
95115
COLUMN("small_text"),
96116
COLUMN("my_date"),
117+
COLUMN("my_timestamp"),
118+
COLUMN("my_timestamp_tz"),
97119
]
98120
),
99121
FROM(my_table_name[1:-1]),
@@ -116,6 +138,14 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
116138
assert result.rows[1][3] in [datetime.date(2021, 1, 2), datetime.datetime(2021, 1, 2, 0, 0, 0)]
117139
assert result.rows[2][3] is None
118140

141+
assert result.rows[0][4] == datetime.datetime(2021, 1, 1, 12, 10, 0)
142+
assert result.rows[1][4] == datetime.datetime(2021, 1, 2, 12, 10, 0)
143+
assert result.rows[2][4] is None
144+
145+
assert result.rows[0][5] == datetime.datetime(2021, 1, 1, 12, 10, 0, tzinfo=datetime.timezone.utc)
146+
assert result.rows[1][5] == datetime.datetime(2021, 1, 2, 12, 10, 0, tzinfo=pytz.timezone("America/New_York"))
147+
assert result.rows[2][5] is None
148+
119149
finally:
120150
# Then drop the table to clean up
121151
# We explicitly do not use the "if exists" variant, because the table should exist at this point.

0 commit comments

Comments
 (0)