chore: introduce orderedmap to preserve column order in SQL results during marshal#1852
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
/gcbrun |
orderedmap to preserve column order in SQL results during marshal
Yuan325
left a comment
There was a problem hiding this comment.
Thank you for adding this! Left some comments.
Please run go mod tidy to clean up the deps (https://github.com/googleapis/genai-toolbox/blob/main/DEVELOPER.md#prerequisites) and golangci-lint run --fix to fix any linting issues (https://github.com/googleapis/genai-toolbox/blob/main/DEVELOPER.md#linting).
internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go
Outdated
Show resolved
Hide resolved
|
/gcbrun |
This commit introduces a new `orderedmap` package to preserve the column order of SQL query results when they are marshaled to JSON. The default Go `json.Marshal` function sorts map keys, which was causing the column order to be lost in the output of the database tools. This commit updates the following tools to use the new `orderedmap` package: - `mysqlexecutesql` - `mssqlexecutesql` - `postgresexecutesql` - `spannerexecutesql` - `sqliteexecutesql` - `bigqueryexecutesql` A new test has been added to the `mysqlexecutesql` tool to verify that the column order is preserved.
86c744d to
e4ef209
Compare
|
/gcbrun |
orderedmap to preserve column order in SQL results during marshalorderedmap to preserve column order in SQL results during marshal
e4ef209 to
153a192
Compare
|
/gcbrun |
153a192 to
8d5e12d
Compare
8d5e12d to
69ada6f
Compare
|
/gcbrun |
… results during marshal (googleapis#1852) This commit introduces a new `orderedmap` package to preserve the column order of SQL query results when they are marshaled to JSON. The default Go `json.Marshal` function sorts map keys, which was causing the column order to be lost in the output of the database tools. This commit updates the following tools to use the new `orderedmap` package: - `mysqlexecutesql` - `mssqlexecutesql` - `postgresexecutesql` - `spannerexecutesql` - `sqliteexecutesql` - `bigqueryexecutesql` A new test has been added to the `mysqlexecutesql` tool to verify that the column order is preserved. ## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes googleapis#1492 --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Yuan Teoh <yuanteoh@google.com> Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com> c5962bd
… results during marshal (googleapis#1852) This commit introduces a new `orderedmap` package to preserve the column order of SQL query results when they are marshaled to JSON. The default Go `json.Marshal` function sorts map keys, which was causing the column order to be lost in the output of the database tools. This commit updates the following tools to use the new `orderedmap` package: - `mysqlexecutesql` - `mssqlexecutesql` - `postgresexecutesql` - `spannerexecutesql` - `sqliteexecutesql` - `bigqueryexecutesql` A new test has been added to the `mysqlexecutesql` tool to verify that the column order is preserved. ## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes googleapis#1492 --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Yuan Teoh <yuanteoh@google.com> Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com> c5962bd
Assigning job iterator value to an array instead of map to preserve
column order.
When assigning incoming values to map, sometimes the result is not in
order of statement. E.g. `SELECT id, name from ...` might turn into
`{"name": "name_value", "id":1}` rather than `{"id":1, "name":
"name_value"}`. Previously, during json marshaling, it will ALWAYS order
the map in alphabetical order. so that wasn't an issue.
With the implementation of `orderedmap` (#1852), the bigquery execute
sql tool will now preserves the column order during the marshaling
process. Due to this, bigquery's integration test is flaky and failed
when the map is reordered. This update assign incoming value as array
instead, preserving the actual order.
Assigning job iterator value to an array instead of map to preserve
column order.
When assigning incoming values to map, sometimes the result is not in
order of statement. E.g. `SELECT id, name from ...` might turn into
`{"name": "name_value", "id":1}` rather than `{"id":1, "name":
"name_value"}`. Previously, during json marshaling, it will ALWAYS order
the map in alphabetical order. so that wasn't an issue.
With the implementation of `orderedmap` (googleapis#1852), the bigquery execute
sql tool will now preserves the column order during the marshaling
process. Due to this, bigquery's integration test is flaky and failed
when the map is reordered. This update assign incoming value as array
instead, preserving the actual order. 559e2a2
Assigning job iterator value to an array instead of map to preserve
column order.
When assigning incoming values to map, sometimes the result is not in
order of statement. E.g. `SELECT id, name from ...` might turn into
`{"name": "name_value", "id":1}` rather than `{"id":1, "name":
"name_value"}`. Previously, during json marshaling, it will ALWAYS order
the map in alphabetical order. so that wasn't an issue.
With the implementation of `orderedmap` (googleapis#1852), the bigquery execute
sql tool will now preserves the column order during the marshaling
process. Due to this, bigquery's integration test is flaky and failed
when the map is reordered. This update assign incoming value as array
instead, preserving the actual order. 559e2a2
… during marshal (#1852) This commit introduces a new `orderedmap` package to preserve the column order of SQL query results when they are marshaled to JSON. The default Go `json.Marshal` function sorts map keys, which was causing the column order to be lost in the output of the database tools. This commit updates the following tools to use the new `orderedmap` package: - `mysqlexecutesql` - `mssqlexecutesql` - `postgresexecutesql` - `spannerexecutesql` - `sqliteexecutesql` - `bigqueryexecutesql` A new test has been added to the `mysqlexecutesql` tool to verify that the column order is preserved. ## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #1492 --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Yuan Teoh <yuanteoh@google.com> Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>
Assigning job iterator value to an array instead of map to preserve
column order.
When assigning incoming values to map, sometimes the result is not in
order of statement. E.g. `SELECT id, name from ...` might turn into
`{"name": "name_value", "id":1}` rather than `{"id":1, "name":
"name_value"}`. Previously, during json marshaling, it will ALWAYS order
the map in alphabetical order. so that wasn't an issue.
With the implementation of `orderedmap` (#1852), the bigquery execute
sql tool will now preserves the column order during the marshaling
process. Due to this, bigquery's integration test is flaky and failed
when the map is reordered. This update assign incoming value as array
instead, preserving the actual order.
This commit introduces a new
orderedmappackage to preserve the column order of SQL query results when they are marshaled to JSON.The default Go
json.Marshalfunction sorts map keys, which was causing the column order to be lost in the output of the database tools.This commit updates the following tools to use the new
orderedmappackage:mysqlexecutesqlmssqlexecutesqlpostgresexecutesqlspannerexecutesqlsqliteexecutesqlbigqueryexecutesqlA new test has been added to the
mysqlexecutesqltool to verify that the column order is preserved.Description
PR Checklist
CONTRIBUTING.md
bug/issue
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
!if this involve a breaking change🛠️ Fixes #1492