influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Column order function

Open myka280 opened this issue 6 years ago • 8 comments
trafficstars

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?

myka280 avatar Nov 18 '19 17:11 myka280

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.

russorat avatar Nov 22 '19 18:11 russorat

Is there any progress on this?

FinnHuelsbusch avatar Jan 15 '21 08:01 FinnHuelsbusch

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.

pseudocoder avatar Mar 01 '21 08:03 pseudocoder

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.

psychogun avatar Jul 28 '21 22:07 psychogun

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

Help-i-am-lost avatar Sep 27 '21 16:09 Help-i-am-lost

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

f-michaut avatar Dec 07 '21 13:12 f-michaut

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

toddwarrington avatar Apr 06 '22 15:04 toddwarrington

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.

Tobist avatar Aug 10 '22 09:08 Tobist

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!!!!

oneofthemany avatar Feb 10 '23 10:02 oneofthemany

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

burmajam avatar Apr 03 '23 21:04 burmajam