@@ -43,9 +43,45 @@ def session_factory() -> Mock:
4343 return Mock ()
4444
4545
46+ class SimpleDatasetColumn :
47+ def __init__ (self , col_params : dict [str , Any ]):
48+ self .__dict__ .update (col_params )
49+
50+
51+ TEMPORAL_COLUMN_NAMES = ["temporal_column" , "temporal_column_with_python_date_format" ]
52+ TEMPORAL_COLUMNS = {
53+ TEMPORAL_COLUMN_NAMES [0 ]: SimpleDatasetColumn (
54+ {
55+ "column_name" : TEMPORAL_COLUMN_NAMES [0 ],
56+ "is_dttm" : True ,
57+ "python_date_format" : None ,
58+ "type" : "string" ,
59+ "num_types" : ["BIGINT" ],
60+ }
61+ ),
62+ TEMPORAL_COLUMN_NAMES [1 ]: SimpleDatasetColumn (
63+ {
64+ "column_name" : TEMPORAL_COLUMN_NAMES [1 ],
65+ "type" : "BIGINT" ,
66+ "is_dttm" : True ,
67+ "python_date_format" : "%Y" ,
68+ "num_types" : ["BIGINT" ],
69+ }
70+ ),
71+ }
72+
73+
4674@fixture
4775def connector_registry () -> Mock :
48- return Mock (spec = ["get_datasource" ])
76+ datasource_dao_mock = Mock (spec = ["get_datasource" ])
77+ datasource_dao_mock .get_datasource .return_value = Mock ()
78+ datasource_dao_mock .get_datasource ().get_column = Mock (
79+ side_effect = lambda col_name : TEMPORAL_COLUMNS [col_name ]
80+ if col_name in TEMPORAL_COLUMN_NAMES
81+ else Mock ()
82+ )
83+ datasource_dao_mock .get_datasource ().db_extra = None
84+ return datasource_dao_mock
4985
5086
5187def apply_max_row_limit (limit : int , max_limit : Optional [int ] = None ) -> int :
@@ -112,3 +148,55 @@ def test_query_context_null_post_processing_op(
112148 raw_query_context ["result_type" ], ** raw_query_object
113149 )
114150 assert query_object .post_processing == []
151+
152+ def test_query_context_no_python_date_format_filters (
153+ self ,
154+ query_object_factory : QueryObjectFactory ,
155+ raw_query_context : dict [str , Any ],
156+ ):
157+ raw_query_object = raw_query_context ["queries" ][0 ]
158+ raw_query_object ["filters" ].append (
159+ {"col" : TEMPORAL_COLUMN_NAMES [0 ], "op" : "==" , "val" : 315532800000 }
160+ )
161+ query_object = query_object_factory .create (
162+ raw_query_context ["result_type" ],
163+ raw_query_context ["datasource" ],
164+ ** raw_query_object
165+ )
166+ assert query_object .filter [3 ]["val" ] == 315532800000
167+
168+ def test_query_context_python_date_format_filters (
169+ self ,
170+ query_object_factory : QueryObjectFactory ,
171+ raw_query_context : dict [str , Any ],
172+ ):
173+ raw_query_object = raw_query_context ["queries" ][0 ]
174+ raw_query_object ["filters" ].append (
175+ {"col" : TEMPORAL_COLUMN_NAMES [1 ], "op" : "==" , "val" : 315532800000 }
176+ )
177+ query_object = query_object_factory .create (
178+ raw_query_context ["result_type" ],
179+ raw_query_context ["datasource" ],
180+ ** raw_query_object
181+ )
182+ assert query_object .filter [3 ]["val" ] == 1980
183+
184+ def test_query_context_python_date_format_filters_list_of_values (
185+ self ,
186+ query_object_factory : QueryObjectFactory ,
187+ raw_query_context : dict [str , Any ],
188+ ):
189+ raw_query_object = raw_query_context ["queries" ][0 ]
190+ raw_query_object ["filters" ].append (
191+ {
192+ "col" : TEMPORAL_COLUMN_NAMES [1 ],
193+ "op" : "==" ,
194+ "val" : [315532800000 , 631152000000 ],
195+ }
196+ )
197+ query_object = query_object_factory .create (
198+ raw_query_context ["result_type" ],
199+ raw_query_context ["datasource" ],
200+ ** raw_query_object
201+ )
202+ assert query_object .filter [3 ]["val" ] == [1980 , 1990 ]
0 commit comments