influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.95k stars 3.56k forks source link

Column order function #15957

Open myka280 opened 4 years ago

myka280 commented 4 years ago

Proposal: Need a function to order columns manually.

Current behavior: Table columns are received in a specific order and cannot be changed

Desired behavior: InfluxDB 2.0 result table columns could respect function keep() column order and return results columns in that order

|> keep(columns: [“inventory_no”,“temp1”,“temp2”,“battery1”,“rssi”])

Alternatives considered: Alternatevy there could be specific column order (priority) function.

Use case: GUI respects columns order received from InfluxDB?

russorat commented 4 years ago

In the UI, we recently added the ability to reorder the columns in a table view: https://github.com/influxdata/influxdb/pull/15944

Added @nathanielc to comment on the Flux function for column ordering.

FinnHuelsbusch commented 3 years ago

Is there any progress on this?

pseudocoder commented 3 years ago

There is a hack for this - do a map to a series of numbered columns which will keep their order, then rename them:

|> map(fn: (r) => ({ _time: r._time, "1": r.first, "2": r.second, "3": r.third, "4": r.fourth})) |> rename(columns: { "1": "First", "2": "Second", "3": "Third", "4": "Fourth" })

Works well for me doing stacked bars in Grafana; typically I also start with a pivot to get the columns from fields.

psychogun commented 3 years ago

I also want this!

Edit: Can't you just go the Cell > Configure > and on the Table select Customize and under Column Settings just rearrange the Table Columns? Which I just figured out.

Help-i-am-lost commented 3 years ago

Yeah. I need this too. I can't use anything done outside the database query, as the column names are not constant.

Consider column names being numbers generated from data (via pivot). The column names will then depend on the data. Some columns are staying constant as well. So my column names are A, B, C, D, E, 567, 568, 569.

The number of columns with numbered names vary, sometimes there's only one, sometimes there's 10. And I want to order them as A, C, 567, 568, 569 (as many numbered columns as there is), B, E, D.

Even the map and rename is not working here...

f-michaut commented 2 years ago

I need this as well. For now i'm using @pseudocoder 's hack, but I would prefer to use a real function.

toddwarrington commented 2 years ago

@pseudocoder 's solution worked perfectly for the time being. Thanks!!!!!

Tobist commented 2 years ago

I tried this one in my application to get data from my influxdb2.

|> map(fn: (r) => ({ _time: r._time, "1": r.first, "2": r.second, "3": r.third, "4": r.fourth})) |> rename(columns: { "1": "First", "2": "Second", "3": "Third", "4": "Fourth" })

I use these statements in the query with "|> schema.fieldsAsCols()"

It seems that the rearrange does not work here (12 different columns). The Columns seem to be ordered randomly and not alphabetically? With a Table with 2 columns it works fine. But maybe its just a coincidence because there are not as many cases as in the first scenario.

oneofthemany commented 1 year ago

I also want this!

Edit: Can't you just go the Cell > Configure > and on the Table select Customize and under Column Settings just rearrange the Table Columns? Which I just figured out.

Good spot!!!!

burmajam commented 1 year ago

This one would be much appreciated. Grafana logs panel after pivot is useless with random column ordering