Consider the following query:
This is expected to mean that the database orders the rows by charvalue, then intkey, then for each row finds the lead value in the ordered data set, then sorts all the results by intkey.
Indeed, when run against e.g. postgres or oracle datasource, the results are as follows:
The results are also the same when running the query against teiid with e.g. postgres datasource, as the lead/lag is pushed down.
However, when run against teiid with datasource that does not support lead/lag pushdown (such as csv), the results are different:
I. e. it appears that the ORDER BY in the OVER clause is ignored and the LEAD/LAG uses the (possibly arbitrary) ordering returned from the datasource (which in this case is actually sorted by intkey, but we've seen random ordering from other datasources such as couchbase).
Please note that the same result comes from teiid even when removing either of the columns from the OVER (ORDER BY ...) clause, as well when removing the overall ORDER BY clause.
Processor plan for the above query: