Skip to content

Commit

Permalink
case-insensitive null casting
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Jul 16, 2024
1 parent 5d97fdf commit 5622f1b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/function/cast/vector_cast_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace duckdb {

// ------- Helper functions for splitting string nested types -------
static bool IsNull(const char *buf, idx_t start_pos, Vector &child, idx_t row_idx) {
if (buf[start_pos] == 'N' && buf[start_pos + 1] == 'U' && buf[start_pos + 2] == 'L' && buf[start_pos + 3] == 'L') {
if ((buf[start_pos] == 'N' || buf[start_pos] == 'n') && (buf[start_pos + 1] == 'U' || buf[start_pos + 1] == 'u') &&
(buf[start_pos + 2] == 'L' || buf[start_pos + 2] == 'l') &&
(buf[start_pos + 3] == 'L' || buf[start_pos + 3] == 'l')) {
FlatVector::SetNull(child, row_idx, true);
return true;
}
Expand Down
40 changes: 40 additions & 0 deletions test/sql/types/struct/struct_cast.test
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,43 @@ SELECT s::ROW(i BIGINT, j ROW(a BIGINT, b VARCHAR)) FROM nested_structs
{'i': 1, 'j': {'a': 2, 'b': NULL}}
{'i': 1, 'j': NULL}
NULL

# Issue #12939, NULL used to be case-sensitive
# Testing all permutations for fun
query I
SELECT col::STRUCT(duck INT)
FROM VALUES
('{"duck": null}'),
('{"duck": nulL}'),
('{"duck": nuLl}'),
('{"duck": nuLL}'),
('{"duck": nUll}'),
('{"duck": nUlL}'),
('{"duck": nULl}'),
('{"duck": nULL}'),
('{"duck": Null}'),
('{"duck": NulL}'),
('{"duck": NuLl}'),
('{"duck": NuLL}'),
('{"duck": NUll}'),
('{"duck": NUlL}'),
('{"duck": NULl}'),
('{"duck": NULL}'),
AS tab(col)
----
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}
{'duck': NULL}

0 comments on commit 5622f1b

Please sign in to comment.