Skip to content

chore: introduce orderedmap to preserve column order in SQL results during marshal#1852

Merged
Yuan325 merged 3 commits intogoogleapis:mainfrom
banaras-be-coding:feat-preserve-column-order
Nov 5, 2025
Merged

chore: introduce orderedmap to preserve column order in SQL results during marshal#1852
Yuan325 merged 3 commits intogoogleapis:mainfrom
banaras-be-coding:feat-preserve-column-order

Conversation

@banaras-be-coding
Copy link
Contributor

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
  • Make sure to open an issue as a
    bug/issue
    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

@google-cla
Copy link

google-cla bot commented Nov 4, 2025

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.

@Yuan325 Yuan325 assigned Yuan325 and unassigned averikitsch Nov 4, 2025
@Yuan325
Copy link
Contributor

Yuan325 commented Nov 4, 2025

/gcbrun

@Yuan325 Yuan325 changed the title feat: Preserve column order in SQL results feat: introduce orderedmap to preserve column order in SQL results during marshal Nov 4, 2025
Copy link
Contributor

@Yuan325 Yuan325 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@Yuan325
Copy link
Contributor

Yuan325 commented Nov 5, 2025

/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.
@Yuan325 Yuan325 force-pushed the feat-preserve-column-order branch from 86c744d to e4ef209 Compare November 5, 2025 04:14
@Yuan325
Copy link
Contributor

Yuan325 commented Nov 5, 2025

/gcbrun

@Yuan325 Yuan325 added the tests: run Label to trigger Github Action tests. label Nov 5, 2025
@Yuan325 Yuan325 self-requested a review November 5, 2025 04:14
@github-actions github-actions bot removed the tests: run Label to trigger Github Action tests. label Nov 5, 2025
@Yuan325 Yuan325 changed the title feat: introduce orderedmap to preserve column order in SQL results during marshal chore: introduce orderedmap to preserve column order in SQL results during marshal Nov 5, 2025
@Yuan325 Yuan325 force-pushed the feat-preserve-column-order branch from e4ef209 to 153a192 Compare November 5, 2025 04:21
@Yuan325
Copy link
Contributor

Yuan325 commented Nov 5, 2025

/gcbrun

@Yuan325 Yuan325 added the tests: run Label to trigger Github Action tests. label Nov 5, 2025
@github-actions github-actions bot removed the tests: run Label to trigger Github Action tests. label Nov 5, 2025
@Yuan325 Yuan325 force-pushed the feat-preserve-column-order branch from 153a192 to 8d5e12d Compare November 5, 2025 04:30
@Yuan325 Yuan325 force-pushed the feat-preserve-column-order branch from 8d5e12d to 69ada6f Compare November 5, 2025 17:37
@Yuan325
Copy link
Contributor

Yuan325 commented Nov 5, 2025

/gcbrun

@Yuan325 Yuan325 added the tests: run Label to trigger Github Action tests. label Nov 5, 2025
@github-actions github-actions bot removed the tests: run Label to trigger Github Action tests. label Nov 5, 2025
@Yuan325 Yuan325 enabled auto-merge (squash) November 5, 2025 18:39
@Yuan325 Yuan325 disabled auto-merge November 5, 2025 18:39
@Yuan325 Yuan325 enabled auto-merge (squash) November 5, 2025 18:39
@Yuan325 Yuan325 merged commit c5962bd into googleapis:main Nov 5, 2025
13 checks passed
github-actions bot pushed a commit to dborowitz/genai-toolbox that referenced this pull request Nov 5, 2025
… 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
github-actions bot pushed a commit to dborowitz/genai-toolbox that referenced this pull request Nov 5, 2025
… 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
Yuan325 added a commit that referenced this pull request Nov 6, 2025
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.
github-actions bot pushed a commit to renovate-bot/googleapis-_-genai-toolbox that referenced this pull request Nov 6, 2025
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
github-actions bot pushed a commit to renovate-bot/googleapis-_-genai-toolbox that referenced this pull request Nov 6, 2025
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
rahulpinto19 pushed a commit that referenced this pull request Nov 18, 2025
… 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>
rahulpinto19 pushed a commit that referenced this pull request Nov 18, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement orderedmap to all tools to preserve column order in SQL restults

3 participants