Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return type for INT64 and FLOAT64 functions #225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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