Some SQL engines (namely Oracle) do not support currently generated SQL for window functions where more partitions or order by expressions are used, for example:
win_test <- data.frame(A = c('a', 'a', 'b', 'b', 'c', 'c'),
B = c('d', 'd', 'd', 'e', 'e', 'e'),
C = c(1:6)
)
copy_to(my_db, win_test, name = 'WIN_TEST')
win_test_ora <- tbl(my_db, from = 'WIN_TEST')
x <- mutate(group_by(win_test_ora, A, B),
leadf = order_by(c(A, C), lead(A, 1, 'x'))
)
This generates SQL:
<SQL>
SELECT "A", "B", "C", "leadf"
FROM (SELECT "A", "B", "C", LEAD("A", 1.0, 'x') OVER (PARTITION BY ("A", "B") ORDER BY ("A", "C") AS "leadf"
FROM "WIN_TEST") "_W17"
The only issue is that parentheses are used to enclose each set of expressions. This performed by sql_vector function.