Skip to content

Commit bbfee5f

Browse files
authored
Casting of literals is done by Calcite, except for strings (#178)
* Casting of literals is done by Calcite, except for strings * Added more tests for simple cases
1 parent e065161 commit bbfee5f

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

dask_sql/physical/rex/core/call.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ def __init__(self):
188188
super().__init__(self.cast)
189189

190190
def cast(self, operand, rex=None) -> SeriesOrScalar:
191+
if not is_frame(operand):
192+
return operand
193+
191194
output_type = str(rex.getType())
192195
output_type = sql_to_python_type(output_type.upper())
193196

tests/integration/test_filter.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ def test_filter_with_nan(c):
5959
assert_frame_equal(
6060
return_df, expected_df,
6161
)
62+
63+
64+
def test_string_filter(c, string_table):
65+
return_df = c.sql("SELECT * FROM string_table WHERE a = 'a normal string'")
66+
return_df = return_df.compute()
67+
68+
assert_frame_equal(
69+
return_df, string_table.head(1),
70+
)

tests/integration/test_sqlite.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ def test_groupby(assert_query_gives_same_result):
111111
"""
112112
)
113113

114+
assert_query_gives_same_result(
115+
"""
116+
SELECT AVG(c)
117+
FROM df2
118+
"""
119+
)
120+
121+
122+
def test_calc(assert_query_gives_same_result):
123+
assert_query_gives_same_result(
124+
"""
125+
SELECT
126+
a + b,
127+
a*b,
128+
a*5,
129+
a / user_id,
130+
user_id / a
131+
FROM df1
132+
"""
133+
)
134+
114135

115136
def test_filter(assert_query_gives_same_result):
116137
assert_query_gives_same_result(
@@ -132,3 +153,43 @@ def test_filter(assert_query_gives_same_result):
132153
d NOT LIKE '%c'
133154
"""
134155
)
156+
157+
assert_query_gives_same_result(
158+
"""
159+
SELECT
160+
d
161+
FROM df2
162+
WHERE
163+
d = 'a'
164+
"""
165+
)
166+
167+
assert_query_gives_same_result(
168+
"""
169+
SELECT
170+
*
171+
FROM df1
172+
WHERE
173+
1 < a AND a < 5
174+
"""
175+
)
176+
177+
assert_query_gives_same_result(
178+
"""
179+
SELECT
180+
*
181+
FROM df1
182+
WHERE
183+
a < 5 AND b < 5
184+
"""
185+
)
186+
187+
assert_query_gives_same_result(
188+
"""
189+
SELECT
190+
*
191+
FROM df1
192+
WHERE
193+
a + b > 5
194+
"""
195+
)

0 commit comments

Comments
 (0)