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

Preserve column ordering #14

Merged
merged 3 commits into from
Aug 8, 2024

Conversation

samjewell
Copy link
Collaborator

Currently SQL Expressions returns a data frame with columns that are in a different order to the order the user requested.

image

Not only is this a poor UX, it also blocks us from doing more exciting NoQL things with SQL Expressions, such as:

  • Drag and drop table columns by their header
  • "Add calculation" functionality that would add a custom column at the end of the table.

This confirms that we need a new approach to creating the fields in the
dataframe
The JSON records that DuckDB dumps are actually ordered maps. The object
keys (and values) appear in the order that they were requested in the
SELECT statement.
Although JSON has no concept of ordering within objects, this is the
simplest and quickest way to fix this problem.

I'll try to investigate some other avenues for fixing this one day in the
future. @ryantxu suggested a couple of things we could try:
- We can implement a JSON parser that goes straight to data frame (like the one in the sdk)
- or better may be using parquet output. if named based on a hash this could also be a cache system 'for free'

Also note, there's another orderedmap Go package we could have used:
https://github.com/wk8/go-ordered-map
They seem to have a similar number of forks and stars on Github, and I
just happened across the iancoleman one first.
@scottlepp scottlepp merged commit 8ea1ec4 into scottlepp:main Aug 8, 2024
1 check passed
@samjewell samjewell deleted the sj/preserve-column-ordering branch August 9, 2024 08:43
samjewell added a commit to grafana/grafana that referenced this pull request Aug 12, 2024
This fixed ordering of the columns

**What is this feature, why do we need it?**

See scottlepp/go-duck#14 for a description of the improvement we're including here

**Who is this feature for?**

Anyone who uses SQL Expressions. This is still an experimental feature, and only used by a very small number of instances.
mildwonkey pushed a commit to grafana/grafana that referenced this pull request Aug 12, 2024
* Bump to go-duck v0.1.0

This fixed ordering of the columns

**What is this feature, why do we need it?**

See scottlepp/go-duck#14 for a description of the improvement we're including here

**Who is this feature for?**

Anyone who uses SQL Expressions. This is still an experimental feature, and only used by a very small number of instances.

* Run `make update-workspace`
giorgioatmerqury pushed a commit to cybermerqury/grafana that referenced this pull request Aug 21, 2024
* Bump to go-duck v0.1.0

This fixed ordering of the columns

**What is this feature, why do we need it?**

See scottlepp/go-duck#14 for a description of the improvement we're including here

**Who is this feature for?**

Anyone who uses SQL Expressions. This is still an experimental feature, and only used by a very small number of instances.

* Run `make update-workspace`
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.

2 participants