Skip to content

Commit af402f9

Browse files
kszucscpcloud
andauthored
perf(sql): don't compile pretty sql by default (ibis-project#8616)
Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
1 parent 3e945e9 commit af402f9

99 files changed

Lines changed: 425 additions & 894 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ibis/backends/clickhouse/tests/test_aggregations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
@pytest.mark.parametrize(
1616
"reduction", ["sum", "count", "mean", "max", "min", "std", "var"]
1717
)
18-
def test_reduction_where(alltypes, reduction, snapshot):
18+
def test_reduction_where(alltypes, reduction, assert_sql):
1919
method = getattr(alltypes.double_col, reduction)
2020
cond = alltypes.bigint_col < 70
2121
expr = method(where=cond)
2222

23-
snapshot.assert_match(expr.compile(), "out.sql")
23+
assert_sql(expr)
2424

2525

2626
@pytest.mark.parametrize("method", ["var", "std"])
27-
def test_std_var_pop(con, alltypes, method, snapshot):
27+
def test_std_var_pop(con, alltypes, method, assert_sql):
2828
cond = alltypes.bigint_col < 70
2929
col = alltypes.double_col
3030
expr = getattr(col, method)(where=cond, how="pop")
31-
snapshot.assert_match(expr.compile(), "out.sql")
31+
assert_sql(expr)
3232
assert isinstance(con.execute(expr), float)
3333

3434

ibis/backends/clickhouse/tests/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
cc = pytest.importorskip("clickhouse_connect")
1616

1717

18+
def test_connection(con):
19+
assert con is not None
20+
assert isinstance(con, ibis.backends.clickhouse.Backend)
21+
22+
1823
def test_run_sql(con):
1924
query = "SELECT * FROM ibis_testing.functional_alltypes"
2025
table = con.sql(query)

ibis/backends/clickhouse/tests/test_functions.py

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020

2121
@pytest.mark.parametrize("to_type", ["int8", "int16", "float32", "float", "!float64"])
22-
def test_cast_double_col(alltypes, to_type, snapshot):
22+
def test_cast_double_col(alltypes, to_type, assert_sql):
2323
expr = alltypes.double_col.cast(to_type)
24-
result = expr.compile()
25-
snapshot.assert_match(result, "out.sql")
24+
assert_sql(expr)
2625

2726

2827
@pytest.mark.parametrize(
@@ -37,9 +36,9 @@ def test_cast_double_col(alltypes, to_type, snapshot):
3736
"!struct<a: string, b: int64>",
3837
],
3938
)
40-
def test_cast_string_col(alltypes, to_type, snapshot):
39+
def test_cast_string_col(alltypes, to_type, assert_sql):
4140
expr = alltypes.string_col.cast(to_type)
42-
snapshot.assert_match(expr.compile(), "out.sql")
41+
assert_sql(expr)
4342

4443

4544
@pytest.mark.parametrize(
@@ -60,35 +59,35 @@ def test_cast_string_col(alltypes, to_type, snapshot):
6059
"month",
6160
],
6261
)
63-
def test_noop_cast(alltypes, column, snapshot):
62+
def test_noop_cast(alltypes, column, assert_sql):
6463
col = alltypes[column]
6564
result = col.cast(col.type())
6665
assert result.equals(col)
67-
snapshot.assert_match(result.compile(), "out.sql")
66+
assert_sql(result)
6867

6968

70-
def test_timestamp_cast(alltypes, snapshot):
69+
def test_timestamp_cast(alltypes, assert_sql):
7170
target = dt.Timestamp(nullable=False)
7271
result1 = alltypes.timestamp_col.cast(target)
7372
result2 = alltypes.int_col.cast(target)
7473

7574
assert isinstance(result1, ir.TimestampColumn)
7675
assert isinstance(result2, ir.TimestampColumn)
7776

78-
snapshot.assert_match(result1.compile(), "out1.sql")
79-
snapshot.assert_match(result2.compile(), "out2.sql")
77+
assert_sql(result1, "out1.sql")
78+
assert_sql(result2, "out2.sql")
8079

8180

82-
def test_timestamp_now(con, snapshot):
81+
def test_timestamp_now(con, assert_sql):
8382
expr = ibis.now()
84-
snapshot.assert_match(con.compile(expr), "out.sql")
83+
assert_sql(expr)
8584

8685

8786
@pytest.mark.parametrize("unit", ["y", "m", "d", "w", "h", "minute"])
88-
def test_timestamp_truncate(con, unit, snapshot):
87+
def test_timestamp_truncate(con, unit, assert_sql):
8988
stamp = ibis.timestamp("2009-05-17 12:34:56")
9089
expr = stamp.truncate(unit)
91-
snapshot.assert_match(con.compile(expr), "out.sql")
90+
assert_sql(expr)
9291

9392

9493
@pytest.mark.parametrize(("value", "expected"), [(0, None), (5.5, 5.5)])
@@ -185,13 +184,13 @@ def test_string_substring(con, op, expected):
185184
assert con.execute(op(value)) == expected
186185

187186

188-
def test_string_column_substring(con, alltypes, snapshot):
187+
def test_string_column_substring(con, alltypes, assert_sql):
189188
expr = alltypes.string_col.substr(2)
190-
snapshot.assert_match(expr.compile(), "out1.sql")
189+
assert_sql(expr, "out1.sql")
191190
assert len(con.execute(expr))
192191

193192
expr = alltypes.string_col.substr(0, 3)
194-
snapshot.assert_match(expr.compile(), "out2.sql")
193+
assert_sql(expr, "out2.sql")
195194
assert len(con.execute(expr))
196195

197196

@@ -243,12 +242,12 @@ def test_find_in_set(con, value, expected):
243242
assert con.execute(expr) == expected
244243

245244

246-
def test_string_column_find_in_set(con, alltypes, snapshot):
245+
def test_string_column_find_in_set(con, alltypes, assert_sql):
247246
s = alltypes.string_col
248247
vals = list("abc")
249248

250249
expr = s.find_in_set(vals)
251-
snapshot.assert_match(expr.compile(), "out.sql")
250+
assert_sql(expr)
252251
assert len(con.execute(expr))
253252

254253

@@ -271,25 +270,25 @@ def test_string_find_like(con, expr, expected):
271270
assert con.execute(expr) == expected
272271

273272

274-
def test_string_column_like(con, alltypes, snapshot):
273+
def test_string_column_like(con, alltypes, assert_sql):
275274
expr = alltypes.string_col.like("foo%")
276-
snapshot.assert_match(expr.compile(), "out1.sql")
275+
assert_sql(expr, "out1.sql")
277276
assert len(con.execute(expr))
278277

279278
expr = alltypes.string_col.like(["foo%", "%bar"])
280-
snapshot.assert_match(expr.compile(), "out2.sql")
279+
assert_sql(expr, "out2.sql")
281280
assert len(con.execute(expr))
282281

283282

284-
def test_string_column_find(con, alltypes, snapshot):
283+
def test_string_column_find(con, alltypes, assert_sql):
285284
s = alltypes.string_col
286285

287286
expr = s.find("a")
288-
snapshot.assert_match(expr.compile(), "out1.sql")
287+
assert_sql(expr, "out1.sql")
289288
assert len(con.execute(expr))
290289

291290
expr = s.find(s)
292-
snapshot.assert_match(expr.compile(), "out2.sql")
291+
assert_sql(expr, "out2.sql")
293292
assert len(con.execute(expr))
294293

295294

@@ -309,9 +308,9 @@ def test_string_column_find(con, alltypes, snapshot):
309308
param(methodcaller("sign"), id="sign"),
310309
],
311310
)
312-
def test_translate_math_functions(con, alltypes, call, snapshot):
311+
def test_translate_math_functions(con, alltypes, call, assert_sql):
313312
expr = call(alltypes.double_col)
314-
snapshot.assert_match(expr.compile(), "out.sql")
313+
assert_sql(expr, "out.sql")
315314
assert len(con.execute(expr))
316315

317316

@@ -352,21 +351,21 @@ def test_math_functions(con, expr, expected):
352351
assert con.execute(expr) == expected
353352

354353

355-
def test_greatest_least(con, alltypes, snapshot):
354+
def test_greatest_least(con, alltypes, assert_sql):
356355
expr = ibis.greatest(alltypes.int_col, 10)
357-
snapshot.assert_match(expr.compile(), "out1.sql")
356+
assert_sql(expr, "out1.sql")
358357
assert len(con.execute(expr))
359358

360359
expr = ibis.greatest(alltypes.int_col, alltypes.bigint_col)
361-
snapshot.assert_match(expr.compile(), "out2.sql")
360+
assert_sql(expr, "out2.sql")
362361
assert len(con.execute(expr))
363362

364363
expr = ibis.least(alltypes.int_col, 10)
365-
snapshot.assert_match(expr.compile(), "out3.sql")
364+
assert_sql(expr, "out3.sql")
366365
assert len(con.execute(expr))
367366

368367
expr = ibis.least(alltypes.int_col, alltypes.bigint_col)
369-
snapshot.assert_match(expr.compile(), "out4.sql")
368+
assert_sql(expr, "out4.sql")
370369
assert len(con.execute(expr))
371370

372371

@@ -397,15 +396,15 @@ def test_regexp_extract(con, expr, expected):
397396
assert con.execute(expr) == expected
398397

399398

400-
def test_column_regexp_extract(con, alltypes, snapshot):
399+
def test_column_regexp_extract(con, alltypes, assert_sql):
401400
expr = alltypes.string_col.re_extract(r"[\d]+", 3)
402-
snapshot.assert_match(expr.compile(), "out.sql")
401+
assert_sql(expr, "out.sql")
403402
assert len(con.execute(expr))
404403

405404

406-
def test_column_regexp_replace(con, alltypes, snapshot):
405+
def test_column_regexp_replace(con, alltypes, assert_sql):
407406
expr = alltypes.string_col.re_replace(r"[\d]+", "aaa")
408-
snapshot.assert_match(expr.compile(), "out.sql")
407+
assert_sql(expr, "out.sql")
409408
assert len(con.execute(expr))
410409

411410

@@ -437,10 +436,10 @@ def test_literal_none_to_nullable_column(alltypes):
437436
tm.assert_series_equal(result, expected)
438437

439438

440-
def test_timestamp_from_integer(con, alltypes, snapshot):
439+
def test_timestamp_from_integer(con, alltypes, assert_sql):
441440
# timestamp_col has datetime type
442441
expr = alltypes.int_col.to_timestamp()
443-
snapshot.assert_match(expr.compile(), "out.sql")
442+
assert_sql(expr, "out.sql")
444443
assert len(con.execute(expr))
445444

446445

@@ -460,15 +459,15 @@ def test_count_distinct_with_filter(alltypes):
460459
param(",", 0, id="comma_zero"),
461460
],
462461
)
463-
def test_group_concat(alltypes, sep, where_case, snapshot):
462+
def test_group_concat(alltypes, sep, where_case, assert_sql):
464463
where = None if where_case is None else alltypes.bool_col == where_case
465464
expr = alltypes.string_col.group_concat(sep, where)
466-
snapshot.assert_match(expr.compile(), "out.sql")
465+
assert_sql(expr, "out.sql")
467466

468467

469-
def test_hash(alltypes, snapshot):
468+
def test_hash(alltypes, assert_sql):
470469
expr = alltypes.string_col.hash()
471-
snapshot.assert_match(expr.compile(), "out.sql")
470+
assert_sql(expr)
472471

473472

474473
def test_udf_in_array_map(alltypes):

ibis/backends/clickhouse/tests/test_literals.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
ibis.timestamp("2015-01-01 12:34:56"),
1919
],
2020
)
21-
def test_timestamp_literals(con, expr, snapshot):
22-
snapshot.assert_match(con.compile(expr), "out.sql")
21+
def test_timestamp_literals(con, expr, assert_sql):
22+
assert_sql(expr)
2323
assert con.execute(expr) == Timestamp("2015-01-01 12:34:56")
2424

2525

@@ -32,8 +32,8 @@ def test_timestamp_literals(con, expr, snapshot):
3232
param(ibis.timestamp("2015-01-01 12:34:56.789321 UTC"), id="micros_tz"),
3333
],
3434
)
35-
def test_fine_grained_timestamp_literals(con, expr, snapshot):
36-
snapshot.assert_match(con.compile(expr), "out.sql")
35+
def test_fine_grained_timestamp_literals(con, expr, assert_sql):
36+
assert_sql(expr)
3737
assert con.execute(expr) == expr.op().value
3838

3939

@@ -49,10 +49,9 @@ def test_fine_grained_timestamp_literals(con, expr, snapshot):
4949
param(False, id="false"),
5050
],
5151
)
52-
def test_string_numeric_boolean_literals(con, value, snapshot):
52+
def test_string_numeric_boolean_literals(con, value, assert_sql):
5353
expr = ibis.literal(value)
54-
result = con.compile(expr)
55-
snapshot.assert_match(result, "out.sql")
54+
assert_sql(expr)
5655
assert con.execute(expr) == value
5756

5857

ibis/backends/clickhouse/tests/test_operators.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def test_string_temporal_compare(con, op, left, right, type):
5656
"op",
5757
["add", "sub", "mul", "truediv", "pow", "lt", "le", "gt", "ge", "eq", "ne"],
5858
)
59-
def test_binary_infix_operators(con, alltypes, op, snapshot):
59+
def test_binary_infix_operators(con, alltypes, op, assert_sql):
6060
func = getattr(operator, op)
6161
a, b = alltypes.int_col, alltypes.tinyint_col
6262
expr = func(a, b)
63-
snapshot.assert_match(expr.compile(), "out.sql")
63+
assert_sql(expr)
6464
assert len(con.execute(expr))
6565

6666

@@ -78,19 +78,19 @@ def test_binary_infix_operators(con, alltypes, op, snapshot):
7878
lambda a, b, c: (b + (-(a + c))),
7979
],
8080
)
81-
def test_binary_infix_parenthesization(con, alltypes, op, snapshot):
81+
def test_binary_infix_parenthesization(con, alltypes, op, assert_sql):
8282
a = alltypes.int_col
8383
b = alltypes.tinyint_col
8484
c = alltypes.double_col
8585

8686
expr = op(a, b, c)
87-
snapshot.assert_match(expr.compile(), "out.sql")
87+
assert_sql(expr)
8888
assert len(con.execute(expr))
8989

9090

91-
def test_between(con, alltypes, snapshot):
91+
def test_between(con, alltypes, assert_sql):
9292
expr = alltypes.int_col.between(0, 10)
93-
snapshot.assert_match(expr.compile(), "out.sql")
93+
assert_sql(expr)
9494
assert len(con.execute(expr))
9595

9696

@@ -143,9 +143,9 @@ def test_field_in_literals(con, alltypes, df, container):
143143

144144

145145
@pytest.mark.parametrize("column", ["int_col", "float_col", "bool_col"])
146-
def test_negate(con, alltypes, column, snapshot):
146+
def test_negate(con, alltypes, column, assert_sql):
147147
expr = -alltypes[column]
148-
snapshot.assert_match(expr.compile(), "out.sql")
148+
assert_sql(expr)
149149
assert len(con.execute(expr))
150150

151151

@@ -199,17 +199,17 @@ def test_ifelse(alltypes, df, op, pandas_op):
199199
tm.assert_series_equal(result, expected)
200200

201201

202-
def test_simple_case(con, alltypes, snapshot):
202+
def test_simple_case(con, alltypes, assert_sql):
203203
t = alltypes
204204
expr = (
205205
t.string_col.case().when("foo", "bar").when("baz", "qux").else_("default").end()
206206
)
207207

208-
snapshot.assert_match(expr.compile(), "out.sql")
208+
assert_sql(expr)
209209
assert len(con.execute(expr))
210210

211211

212-
def test_search_case(con, alltypes, snapshot):
212+
def test_search_case(con, alltypes, assert_sql):
213213
t = alltypes
214214
expr = (
215215
ibis.case()
@@ -219,7 +219,7 @@ def test_search_case(con, alltypes, snapshot):
219219
.end()
220220
)
221221

222-
snapshot.assert_match(expr.compile(), "out.sql")
222+
assert_sql(expr)
223223
assert len(con.execute(expr))
224224

225225

0 commit comments

Comments
 (0)