Skip to content

Commit e00932c

Browse files
authored
Minor: Add tests for binary / utf8 coercion (#7839)
1 parent 9aacdee commit e00932c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

datafusion/sqllogictest/test_files/binary.slt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,92 @@ drop table t_source
155155

156156
statement ok
157157
drop table t
158+
159+
160+
#############
161+
## Tests for binary that contains strings
162+
#############
163+
164+
statement ok
165+
CREATE TABLE t_source
166+
AS VALUES
167+
('Foo'),
168+
(NULL),
169+
('Bar'),
170+
('FooBar')
171+
;
172+
173+
# Create a table with Binary, LargeBinary but really has strings
174+
statement ok
175+
CREATE TABLE t
176+
AS SELECT
177+
arrow_cast(column1, 'Binary') as "binary",
178+
arrow_cast(column1, 'LargeBinary') as "largebinary"
179+
FROM t_source;
180+
181+
query ??TT
182+
SELECT binary, largebinary, cast(binary as varchar) as binary_str, cast(largebinary as varchar) as binary_largestr from t;
183+
----
184+
466f6f 466f6f Foo Foo
185+
NULL NULL NULL NULL
186+
426172 426172 Bar Bar
187+
466f6f426172 466f6f426172 FooBar FooBar
188+
189+
# ensure coercion works for = and <>
190+
query ?T
191+
SELECT binary, cast(binary as varchar) as str FROM t WHERE binary = 'Foo';
192+
----
193+
466f6f Foo
194+
195+
query ?T
196+
SELECT binary, cast(binary as varchar) as str FROM t WHERE binary <> 'Foo';
197+
----
198+
426172 Bar
199+
466f6f426172 FooBar
200+
201+
# order by
202+
query ?
203+
SELECT binary FROM t ORDER BY binary;
204+
----
205+
426172
206+
466f6f
207+
466f6f426172
208+
NULL
209+
210+
# order by
211+
query ?
212+
SELECT largebinary FROM t ORDER BY largebinary;
213+
----
214+
426172
215+
466f6f
216+
466f6f426172
217+
NULL
218+
219+
# LIKE
220+
# https://github.com/apache/arrow-datafusion/issues/7342
221+
query error DataFusion error: type_coercion
222+
SELECT binary FROM t where binary LIKE '%F';
223+
224+
query error DataFusion error: type_coercion
225+
SELECT largebinary FROM t where largebinary LIKE '%F';
226+
227+
228+
# character_length function
229+
# https://github.com/apache/arrow-datafusion/issues/7344
230+
query error DataFusion error: Error during planning: The "character_length" function can only accept strings, but got Binary\.
231+
SELECT
232+
cast(binary as varchar) as str,
233+
character_length(binary) as binary_len,
234+
cast(largebinary as varchar) as large_str,
235+
character_length(binary) as largebinary_len
236+
from t;
237+
238+
# regexp_replace
239+
# https://github.com/apache/arrow-datafusion/issues/7345
240+
query error DataFusion error: Error during planning: The "regexp_replace" function can only accept strings, but got Binary\.
241+
SELECT
242+
cast(binary as varchar) as str,
243+
regexp_replace(binary, 'F', 'f') as binary_replaced,
244+
cast(largebinary as varchar) as large_str,
245+
regexp_replace(largebinary, 'F', 'f') as large_binary_replaced
246+
from t;

0 commit comments

Comments
 (0)