Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ fn parse_number<T>(
where
T: FromStr + num_traits::Num,
{
let s = s.trim();
match s.parse::<T>() {
Ok(v) => Ok(v),
Err(e) => {
Expand Down
5 changes: 3 additions & 2 deletions src/query/functions/src/scalars/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,10 @@ fn eval_boolean_to_string(val: Value<BooleanType>, ctx: &mut EvalContext) -> Val

fn eval_string_to_boolean(val: Value<StringType>, ctx: &mut EvalContext) -> Value<BooleanType> {
vectorize_with_builder_1_arg::<StringType, BooleanType>(|val, output, ctx| {
if val.eq_ignore_ascii_case("true") {
let val = val.trim();
if val.eq_ignore_ascii_case("true") || val == "1" {
output.push(true);
} else if val.eq_ignore_ascii_case("false") {
} else if val.eq_ignore_ascii_case("false") || val == "0" {
output.push(false);
} else {
ctx.set_error(output.len(), "cannot parse to type `BOOLEAN`");
Expand Down
38 changes: 20 additions & 18 deletions src/query/functions/tests/it/scalars/testdata/cast.txt
Original file line number Diff line number Diff line change
Expand Up @@ -898,20 +898,22 @@ error:



error:
--> SQL:1:1
|
1 | CAST('0' AS BOOLEAN)
| ^^^^^^^^^^^^^^^^^^^^ cannot parse to type `BOOLEAN` while evaluating function `to_boolean('0')` in expr `CAST('0' AS Boolean)`


ast : CAST('0' AS BOOLEAN)
raw expr : CAST('0' AS Boolean)
checked expr : CAST<String>("0" AS Boolean)
optimized expr : false
output type : Boolean
output domain : {FALSE}
output : false

error:
--> SQL:1:1
|
1 | CAST('1' AS BOOLEAN)
| ^^^^^^^^^^^^^^^^^^^^ cannot parse to type `BOOLEAN` while evaluating function `to_boolean('1')` in expr `CAST('1' AS Boolean)`

ast : CAST('1' AS BOOLEAN)
raw expr : CAST('1' AS Boolean)
checked expr : CAST<String>("1" AS Boolean)
optimized expr : true
output type : Boolean
output domain : {TRUE}
output : true


ast : CAST('true' AS BOOLEAN)
Expand Down Expand Up @@ -3357,19 +3359,19 @@ output : NULL
ast : TRY_CAST('0' AS BOOLEAN)
raw expr : TRY_CAST('0' AS Boolean)
checked expr : TRY_CAST<String>("0" AS Boolean NULL)
optimized expr : NULL
optimized expr : false
output type : Boolean NULL
output domain : {NULL}
output : NULL
output domain : {FALSE}
output : false


ast : TRY_CAST('1' AS BOOLEAN)
raw expr : TRY_CAST('1' AS Boolean)
checked expr : TRY_CAST<String>("1" AS Boolean NULL)
optimized expr : NULL
optimized expr : true
output type : Boolean NULL
output domain : {NULL}
output : NULL
output domain : {TRUE}
output : true


ast : TRY_CAST('true' AS BOOLEAN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ SELECT CAST(' e1' AS DOUBLE)
statement error 1006
SELECT CAST(' E1' AS DOUBLE)

statement error 1006
query I
SELECT CAST(' 1e1' AS INTEGER)
----
10

query R
SELECT CAST('1e1' AS DOUBLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ SELECT '33'::unsigned = 33
----
1

query RI
SELECT CAST(' 1e1' AS DOUBLE), CAST(' 1e1' AS INTEGER)
----
10.0 10

query II
SELECT CAST(' -42 ' AS INTEGER), CAST(' 42 ' AS UNSIGNED)
----
-42 42



statement error 1006
Expand Down Expand Up @@ -144,6 +154,16 @@ select 'false'::boolean = not 'true'::boolean
----
1

query BBBB
select '1'::boolean, '0'::boolean, ' true '::boolean, ' false '::boolean
----
1 0 1 0

query BBBB
select true='1', false='0', ' 1 '=true, ' 0 '=false
----
1 1 1 1

query B
SELECT to_timestamp('2021-03-05 01:01:01') + 1 = to_timestamp('2021-03-05 01:01:01.000001')
----
Expand Down
Loading