The documentation (http://devdoc.net/database/ClickhouseDocs_19.4.1.3-docs/query_language/select/)
says FINAL has to be placed right after the table name, before SAMPLE:
SELECT [DISTINCT] expr_list
[FROM [db.]table | (subquery) | table_function] [FINAL]
[SAMPLE sample_coeff]
At the moment it's appended to the end of the query which results in
invalid queries being generated when there are WHERE, ORDER BY or any
other clauses used.