Skip to content

Commit cc43f25

Browse files
committed
Add boolean to int conversion function.
1 parent 7ac8799 commit cc43f25

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

functions/functions.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,18 @@ func FunctionMap() map[string]physical.FunctionDetails {
910910
return values[0], nil
911911
},
912912
},
913+
{
914+
ArgumentTypes: []octosql.Type{octosql.Boolean},
915+
OutputType: octosql.Int,
916+
Strict: true,
917+
Function: func(values []octosql.Value) (octosql.Value, error) {
918+
if values[0].Boolean {
919+
return octosql.NewInt(1), nil
920+
} else {
921+
return octosql.NewInt(0), nil
922+
}
923+
},
924+
},
913925
{
914926
ArgumentTypes: []octosql.Type{octosql.Float},
915927
OutputType: octosql.Int,

tests/scenarios/functions/conversions.err

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
octosql "SELECT int(true), int(false)"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
+-------+-------+
2+
| col_0 | col_1 |
3+
+-------+-------+
4+
| 1 | 0 |
5+
+-------+-------+

0 commit comments

Comments
 (0)