Skip to content

Commit 875c84a

Browse files
Merge pull request #5 from MaterializeInc/fix-tests
Fix failing Materialize backend tests
1 parent 89395f5 commit 875c84a

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

ibis/backends/materialize/tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ def temp_table(con) -> str: # noqa: ARG001
150150

151151

152152
@pytest.fixture
153-
def assert_sql(con): # noqa: ARG001
153+
def assert_sql(con):
154154
"""Fixture for asserting SQL compilation."""
155-
from ibis import to_sql
156155

157156
def check_sql(expr):
158-
"""Check that expression can be compiled to SQL."""
159-
sql = to_sql(expr, dialect="postgres") # Materialize uses postgres dialect
157+
"""Check that expression can be compiled to SQL using Materialize backend."""
158+
# Use the Materialize backend's compiler, not the generic postgres dialect
159+
sql = con.compile(expr)
160160
assert sql is not None
161161
assert isinstance(sql, str)
162162
assert len(sql) > 0

ibis/backends/materialize/tests/test_compiler.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,31 @@ def test_date_literal_cast(assert_sql):
164164

165165

166166
def test_timestamp_from_unix_seconds(simple_table, assert_sql):
167-
"""Test timestamp from Unix seconds uses to_timestamp()."""
168-
expr = simple_table.mutate(ts=simple_table.id.to_timestamp())
167+
"""Test timestamp from Unix seconds uses to_timestamp().
168+
169+
Uses as_timestamp('s') method to convert Unix timestamps.
170+
"""
171+
expr = simple_table.mutate(ts=simple_table.id.as_timestamp("s"))
169172
assert_sql(expr)
170173

171174

172175
def test_timestamp_from_unix_milliseconds(simple_table, assert_sql):
173-
"""Test timestamp from Unix milliseconds converts to seconds."""
174-
expr = simple_table.mutate(ts=simple_table.id.to_timestamp(unit="ms"))
176+
"""Test timestamp from Unix milliseconds converts to seconds.
177+
178+
Uses as_timestamp('ms') method which divides by 1000 before calling to_timestamp().
179+
"""
180+
expr = simple_table.mutate(ts=simple_table.id.as_timestamp("ms"))
175181
assert_sql(expr)
176182

177183

178-
def test_json_extract_with_path_operator(assert_sql):
179-
"""Test JSON extraction uses #>> operator for text.
184+
def test_json_extract_with_cast_to_string(assert_sql):
185+
"""Test JSON extraction can be converted to text using cast.
180186
181-
Materialize doesn't have json_extract_path_text, so we use the #>> operator.
187+
Materialize doesn't have json_extract_path_text, but we can use
188+
bracket notation and cast to string.
182189
"""
183190
t = ibis.table({"json_col": "json"}, name="json_table")
184-
expr = t.mutate(extracted=t.json_col["field1"]["field2"].as_text())
191+
expr = t.mutate(extracted=t.json_col["field1"]["field2"].cast("string"))
185192
assert_sql(expr)
186193

187194

@@ -247,17 +254,23 @@ def test_date_now_operation(simple_table, assert_sql):
247254

248255

249256
def test_interval_from_integer_days(simple_table, assert_sql):
250-
"""Test creating interval from integer (days)."""
257+
"""Test creating interval from integer (days).
258+
259+
Uses as_interval('D') method to convert integers to day intervals.
260+
"""
251261
expr = simple_table.mutate(
252-
future=simple_table.date_col + simple_table.id.to_interval(unit="D")
262+
future=simple_table.date_col + simple_table.id.as_interval("D")
253263
)
254264
assert_sql(expr)
255265

256266

257267
def test_interval_from_integer_hours(simple_table, assert_sql):
258-
"""Test creating interval from integer (hours)."""
268+
"""Test creating interval from integer (hours).
269+
270+
Uses as_interval('h') method to convert integers to hour intervals.
271+
"""
259272
expr = simple_table.mutate(
260-
future=simple_table.timestamp_col + simple_table.id.to_interval(unit="h")
273+
future=simple_table.timestamp_col + simple_table.id.as_interval("h")
261274
)
262275
assert_sql(expr)
263276

ibis/backends/materialize/tests/test_mz_now.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import ibis
88
import ibis.expr.datatypes as dt
9-
from ibis.backends.materialize.api import mz_now
109
from ibis.backends.materialize import operations as mz_ops
10+
from ibis.backends.materialize.api import mz_now
1111

1212

1313
class TestMzNowOperation:
@@ -112,17 +112,18 @@ def test_execute_mz_now(self, con):
112112
assert isinstance(result, (pd.Timestamp, str))
113113

114114
def test_mz_now_vs_now(self, con):
115-
"""Test that mz_now() and now() return different values."""
115+
"""Test that mz_now() and now() return different timestamps."""
116116
mz_now_result = con.execute(mz_now())
117117
now_result = con.execute(ibis.now())
118118

119119
# Both should return timestamps
120120
assert mz_now_result is not None
121121
assert now_result is not None
122122

123-
# The docstring should clarify they're different
124-
assert "logical" in con.mz_now.__doc__.lower()
125-
assert "system clock" in con.mz_now.__doc__.lower()
123+
# The mz_now() function docstring should clarify they're different
124+
assert "logical" in mz_now.__doc__.lower()
125+
# The docstring explains it's different from now() (system clock)
126+
assert "now()" in mz_now.__doc__.lower()
126127

127128
def test_mz_now_in_table_query(self, con):
128129
"""Test mz_now() in a table query."""

ibis/backends/materialize/tests/test_sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_create_auction_source_with_all_tables(self, con):
6464
assert source_name in con.list_sources()
6565

6666
# Wait for data to generate (auction needs more time than counter)
67-
time.sleep(1.5)
67+
time.sleep(3.0)
6868

6969
# Query the bids subsource
7070
bids = con.table("bids")

0 commit comments

Comments
 (0)