Skip to content

Commit

Permalink
fix(trino): remove hack that silently breaks join transpilation (#9941)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored Aug 27, 2024
1 parent c15a229 commit c842453
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 0 additions & 9 deletions ibis/backends/sql/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,9 @@ class Generator(Postgres.Generator):
SQLite.Generator.TYPE_MAPPING |= {sge.DataType.Type.BOOLEAN: "BOOLEAN"}


# TODO(cpcloud): remove this hack once
# https://github.com/tobymao/sqlglot/issues/2735 is resolved
def make_cross_joins_explicit(node):
if not (node.kind or node.side):
node.args["kind"] = "CROSS"
return node


Trino.Generator.TRANSFORMS |= {
sge.BitwiseLeftShift: rename_func("bitwise_left_shift"),
sge.BitwiseRightShift: rename_func("bitwise_right_shift"),
sge.FirstValue: rename_func("first_value"),
sge.Join: transforms.preprocess([make_cross_joins_explicit]),
sge.LastValue: rename_func("last_value"),
}
10 changes: 10 additions & 0 deletions ibis/backends/sql/tests/test_compiler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

import sqlglot as sg

import ibis
from ibis import _
from ibis.backends.sql.dialects import Trino


def test_window_with_row_number_compiles():
Expand All @@ -16,3 +19,10 @@ def test_window_with_row_number_compiles():
.filter(~_.is_test)
)
assert ibis.to_sql(expr)


def test_transpile_join():
(result,) = sg.transpile(
"SELECT * FROM t1 JOIN t2 ON x = y", read="duckdb", write=Trino
)
assert "CROSS JOIN" not in result

0 comments on commit c842453

Please sign in to comment.