dataengref errors

Home / Flink / Query compilation

Flink SQL: Sort on a non-time-attribute field is not supported

org.apache.flink.table.api.TableExceptionSort on a non-time-attribute field is not supported.

Reproduced on Flink 2.3.0, · How

A streaming query has ORDER BY on an ordinary column without LIMIT. An unbounded stream can only be sorted by an ascending time attribute; a full sort would have to wait for input that never ends.

Causes · Fixes · Reproduce · Source

Common causes

  1. ORDER BY on a regular column in streaming mode, for example ORDER BY amount, with no LIMIT.How to confirm: The job runs with execution.runtime-mode = streaming (the default) and the ORDER BY column is not a time attribute.
  2. The data is actually bounded (a file or a finished topic), but the job still runs in streaming mode.How to confirm: The source has a fixed end, such as a filesystem table or datagen with number-of-rows.

How to fix it

If only the top rows matter, add LIMIT; Flink then runs a Top-N that keeps updating the result.

SELECT * FROM orders ORDER BY amount DESC LIMIT 10;

For bounded input, run the query in batch mode, where a full sort is allowed.

SettingDefaultNote
execution.runtime-modeSTREAMING

Or sort by a time attribute in ascending order, which streaming mode supports.

Reproduce it

Triggered on Flink 2.3.0 in a local Docker container, using the SQL client:

CREATE TABLE s (id INT, v INT) WITH ('connector' = 'datagen');
SELECT * FROM s ORDER BY v;

Output:

org.apache.flink.table.api.TableException: Sort on a non-time-attribute field is not supported.

Where the message comes from

References

Related errors

Last checked: