Skip to content

Commit

Permalink
s3select: fix for cast null operation (#143)
Browse files Browse the repository at this point in the history
cast null operations were returning false instead of null. This fix resolves the issue.

Signed-off-by: Albin Antony <[email protected]>
  • Loading branch information
albin-antony authored Dec 11, 2023
1 parent 815904a commit 524b764
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/s3select_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ struct _fn_to_int : public base_function
var_result = static_cast<int64_t>(v.dbl());
break;

case value::value_En_t::S3NULL:
var_result.setnull();
break;

default:
var_result = v.i64();
break;
Expand Down Expand Up @@ -815,6 +819,10 @@ struct _fn_to_float : public base_function
var_result = v.dbl();
break;

case value::value_En_t::S3NULL:
var_result.setnull();
break;

default:
var_result = v.i64();
break;
Expand Down Expand Up @@ -2050,6 +2058,11 @@ struct _fn_to_bool : public base_function
{
i = func_arg.i64();
}
else if (func_arg.type == value::value_En_t::S3NULL)
{
result->set_null();
return true;
}
else
{
i = 0;
Expand Down
3 changes: 3 additions & 0 deletions test/s3select_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,13 +1733,15 @@ TEST(TestS3selectFunctions, boolcast)
test_single_column_single_row("select cast(0 as bool) from s3object;","false\n");
test_single_column_single_row("select cast(true as bool) from s3object;","true\n");
test_single_column_single_row("select cast('a' as bool) from s3object;","false\n");
test_single_column_single_row("select cast(null as bool) from s3object;","null\n");
}

TEST(TestS3selectFunctions, floatcast)
{
test_single_column_single_row("select cast('1234a' as float) from s3object;","#failure#","extra characters after the number");
test_single_column_single_row("select cast('a1234' as float) from s3object;","#failure#","text cannot be converted to a number");
test_single_column_single_row("select cast('999e+999' as float) from s3object;","#failure#","converted value would fall out of the range of the result type!");
test_single_column_single_row("select cast(null as float) from s3object;","null\n");
}

TEST(TestS3selectFunctions, intcast)
Expand All @@ -1748,6 +1750,7 @@ TEST(TestS3selectFunctions, intcast)
test_single_column_single_row("select cast('a1234' as int) from s3object;","#failure#","text cannot be converted to a number");
test_single_column_single_row("select cast('9223372036854775808' as int) from s3object;","#failure#","converted value would fall out of the range of the result type!");
test_single_column_single_row("select cast('-9223372036854775809' as int) from s3object;","#failure#","converted value would fall out of the range of the result type!");
test_single_column_single_row("select cast(null as int) from s3object;","null\n");
}

TEST(TestS3selectFunctions, predicate_as_projection_column)
Expand Down

0 comments on commit 524b764

Please sign in to comment.