Help Center/ Data Lake Insight/ FAQs/ Spark Jobs/ Spark Job O&M/ How Do I Resolve the "Input argument to rand must be a constant" Error in Spark 3.3.1 SQL Statements?
Updated on 2025-07-10 GMT+08:00

How Do I Resolve the "Input argument to rand must be a constant" Error in Spark 3.3.1 SQL Statements?

Symptom

When the rand function is used in SQL statements of Spark 3.3.1, the error message "Input argument to rand must be a constant" is displayed.
Figure 1 rand function error

Solution

In Spark 3.3.1, the rand function requires constant parameters.

To fix this error, update the parameters in the rand function within the SQL statements to constant parameters and rerun the SQL statements.