Skip to content

Commit

Permalink
Fix return type for INT64 and FLOAT64 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
earada committed Nov 28, 2024
1 parent 9d65c7d commit aa19dfd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/function_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,11 @@ func bindInt64(args ...Value) (Value, error) {
if len(args) != 1 {
return nil, fmt.Errorf("INT64: invalid argument num %d", len(args))
}
return args[0], nil
value, err := args[0].ToInt64()
if err != nil {
return nil, err
}
return IntValue(value), nil
}

func bindDouble(args ...Value) (Value, error) {
Expand All @@ -1573,9 +1577,17 @@ func bindDouble(args ...Value) (Value, error) {
}
switch mode {
case "exact":
return args[0], nil
value, err := args[0].ToFloat64()
if err != nil {
return nil, err
}
return FloatValue(value), nil
case "round":
return args[0], nil
value, err := args[0].ToFloat64()
if err != nil {
return nil, err
}
return FloatValue(value), nil
}
return nil, fmt.Errorf("unexpected wide_number_mode: %s", mode)
}
Expand Down
20 changes: 20 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5567,6 +5567,26 @@ FROM
{"false", "boolean"},
},
},
{
name: "json_sum_int64 simple",
query: `SELECT SUM(INT64(x)) AS sum FROM UNNEST([JSON '100', JSON '200', JSON '300']) AS x`,
expectedRows: [][]interface{}{{int64(600)}},
},
{
name: "json_sum_int64 key",
query: `SELECT SUM(INT64(x.count)) AS sum FROM UNNEST([JSON '{"count":100}', JSON '{"count":200}', JSON '{"count":300}']) AS x`,
expectedRows: [][]interface{}{{int64(600)}},
},
{
name: "json_sum_float64 simple",
query: `SELECT SUM(FLOAT64(x)) AS sum FROM UNNEST([JSON '1.5', JSON '2.5', JSON '1.1']) AS x`,
expectedRows: [][]interface{}{{float64(5.1)}},
},
{
name: "json_sum_float64_round simple",
query: `SELECT SUM(ROUND(FLOAT64(x))) AS sum FROM UNNEST([JSON '1.6', JSON '1.1', JSON '1.1']) AS x`,
expectedRows: [][]interface{}{{float64(4.0)}},
},

// subquery expr
{
Expand Down

0 comments on commit aa19dfd

Please sign in to comment.