Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanc-n committed Nov 13, 2024
1 parent 97bf34c commit 7a88d98
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
3 changes: 1 addition & 2 deletions datafusion/functions/src/core/named_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fn named_struct_expr(args: &[ColumnarValue]) -> Result<ColumnarValue> {
let name_column = &chunk[0];
let name = match name_column {
ColumnarValue::Scalar(ScalarValue::Utf8(Some(name_scalar))) => name_scalar,
ColumnarValue::Scalar(ScalarValue::Utf8View(Some(name_scalar))) => name_scalar,
_ => return exec_err!("named_struct even arguments must be string literals, got {name_column:?} instead at position {}", i * 2)
};

Expand Down Expand Up @@ -149,7 +148,7 @@ impl ScalarUDFImpl for NamedStructFunc {
let name = &chunk[0];
let value = &chunk[1];

if let Expr::Literal(ScalarValue::Utf8(Some(name))) | Expr::Literal(ScalarValue::Utf8View(Some(name))) = name {
if let Expr::Literal(ScalarValue::Utf8(Some(name))) = name {
Ok(Field::new(name, value.get_type(schema)?, true))
} else {
exec_err!("named_struct even arguments must be string literals, got {name} instead at position {}", i * 2)
Expand Down
4 changes: 1 addition & 3 deletions datafusion/functions/src/datetime/date_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ impl ScalarUDFImpl for DateBinFunc {

fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
match &arg_types[1] {
Timestamp(Nanosecond, None) | Utf8 | Utf8View | Null => {
Ok(Timestamp(Nanosecond, None))
}
Timestamp(Nanosecond, None) | Utf8 | Null => Ok(Timestamp(Nanosecond, None)),
Timestamp(Nanosecond, tz_opt) => Ok(Timestamp(Nanosecond, tz_opt.clone())),
Timestamp(Microsecond, tz_opt) => Ok(Timestamp(Microsecond, tz_opt.clone())),
Timestamp(Millisecond, tz_opt) => Ok(Timestamp(Millisecond, tz_opt.clone())),
Expand Down
18 changes: 18 additions & 0 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3973,6 +3973,24 @@ ORDER BY column1;
3 [bar] bar
NULL [baz] baz

# test utf8view against
statement ok
CREATE TABLE table_utf8view AS VALUES
('hello'),
('world'),
('jonathan'),
('chen')
;

query T
SELECT array_to_string(array_agg(column1), ',')
FROM (
SELECT arrow_cast(column1, 'Utf8View') as column1
FROM table_utf8view
);
----
hello,world,jonathan,chen

statement ok
drop table table1;

Expand Down
31 changes: 31 additions & 0 deletions datafusion/sqllogictest/test_files/encoding.slt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,34 @@ select to_hex(num) from test ORDER BY num;
0
1
2

# test for Utf8View support for encode
statement ok
CREATE TABLE test_source AS VALUES
('Andrew', 'X'),
('Xiangpeng', 'Xiangpeng'),
('Raphael', 'R'),
(NULL, 'R');

statement ok
CREATE TABLE test_utf8view AS
select
arrow_cast(column1, 'Utf8View') AS column1_utf8view,
arrow_cast(column2, 'Utf8View') AS column2_utf8view
FROM test_source;

query TTTTTT
SELECT
column1_utf8view,
encode(column1_utf8view, 'base64') AS column1_base64,
encode(column1_utf8view, 'hex') AS column1_hex,

column2_utf8view,
encode(column2_utf8view, 'base64') AS column2_base64,
encode(column2_utf8view, 'hex') AS column2_hex
FROM test_utf8view;
----
Andrew QW5kcmV3 416e64726577 X WA 58
Xiangpeng WGlhbmdwZW5n 5869616e6770656e67 Xiangpeng WGlhbmdwZW5n 5869616e6770656e67
Raphael UmFwaGFlbA 5261706861656c R Ug 52
NULL NULL NULL R Ug 52
5 changes: 5 additions & 0 deletions datafusion/sqllogictest/test_files/expr.slt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ SELECT bit_length(NULL)
----
NULL

query I
SELECT bit_length(arrow_cast('jonathan', 'Utf8View'));
----
64

query T
SELECT btrim(' xyxtrimyyx ', NULL)
----
Expand Down

0 comments on commit 7a88d98

Please sign in to comment.