Skip to content

Commit

Permalink
Add boolean to int conversion function.
Browse files Browse the repository at this point in the history
  • Loading branch information
cube2222 committed Oct 15, 2022
1 parent 7ac8799 commit cc43f25
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,18 @@ func FunctionMap() map[string]physical.FunctionDetails {
return values[0], nil
},
},
{
ArgumentTypes: []octosql.Type{octosql.Boolean},
OutputType: octosql.Int,
Strict: true,
Function: func(values []octosql.Value) (octosql.Value, error) {
if values[0].Boolean {
return octosql.NewInt(1), nil
} else {
return octosql.NewInt(0), nil
}
},
},
{
ArgumentTypes: []octosql.Type{octosql.Float},
OutputType: octosql.Int,
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/scenarios/functions/conversions.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
octosql "SELECT int(true), int(false)"
5 changes: 5 additions & 0 deletions tests/scenarios/functions/conversions.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
+-------+-------+
| col_0 | col_1 |
+-------+-------+
| 1 | 0 |
+-------+-------+

0 comments on commit cc43f25

Please sign in to comment.