influxable icon indicating copy to clipboard operation
influxable copied to clipboard

Order of clauses in select statement

Open voneiden opened this issue 3 years ago • 4 comments

It seems the current implementation has slightly different order of clauses compared to InfluxDB documentation, see for example https://docs.influxdata.com/influxdb/v1.5/query_language/spec/#select

select_stmt = "SELECT" fields from_clause [ into_clause ] [ where_clause ]
              [ group_by_clause ] [ order_by_clause ] [ limit_clause ]
              [ offset_clause ] [ slimit_clause ] [ soffset_clause ] [ timezone_clause ] .

whereas the query generated by influxable is

        initial_query = ' '.join([
            '{select_clause}',
            '{into_clause}',
            '{from_clause}',
            '{where_clause}',
            '{limit_clause}',
            '{offset_clause}',
            '{slimit_clause}',
            '{soffset_clause}',
            '{group_by_clause}',
            '{order_by_clause}',
            '{timezone_clause}',
        ])

A query with a group by clause and limit cause will fail with error "Invalid query" with InfluxDB 1.8, however the same query works if order of the clauses is flipped.

voneiden avatar Oct 05 '22 11:10 voneiden

It seems that the web page of the influxdb changed when I began to create this project.

As I recall, I tested with different combinations of clauses and no influx error was generated.

I agree with you that the order of clauses should be equal to order written in the documentation.

I will update it soon.

Thanks for doing the comparison.

Javid

Javidjms avatar Oct 05 '22 16:10 Javidjms

Some of my tests cases failed due to changed order of into_clause

This query " SELECT * FROM "default" INTO new " will fail.

https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/#the-into-clause

Javidjms avatar Oct 07 '22 13:10 Javidjms

That's mildly funny. I checked v1.3 and v1.8 spec, and in those the order is from before into. In v1.7 spec it's flipped.

https://docs.influxdata.com/influxdb/v1.3/query_language/spec/#select https://docs.influxdata.com/influxdb/v1.7/query_language/spec/#select https://docs.influxdata.com/influxdb/v1.8/query_language/spec/#select

but in these the into is always before from

https://docs.influxdata.com/influxdb/v1.3/query_language/data_exploration/#the-into-clause https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/#the-into-clause https://docs.influxdata.com/influxdb/v1.8/query_language/explore-data/#the-into-clause

so.. I guess the spec page is wrong for v1.3 and v1.8?

voneiden avatar Oct 07 '22 15:10 voneiden

I will try to run tests on several different versions of InfluxDB.

If there are different clauses orders, we have to add a condition depends on the version of InfluxDB and reroute to the correct order.

If there is only one order, I will revert your commit about the order.

Maybe like you said, the specification page is incorrect

Javidjms avatar Oct 08 '22 08:10 Javidjms