Description
When Spark's ConstantFolding optimizer rule is disabled, all-literal array expressions reach Comet's native engine, which panics with:
index out of bounds: the len is 0 but the index is 0
This occurs for multiple array functions when given literal array arguments.
How to Reproduce
SET spark.sql.optimizer.excludedRules=org.apache.spark.sql.catalyst.optimizer.ConstantFolding;
SELECT array_max(array(1, 2, 3)), array_max(cast(NULL as array<int>));
SELECT array_min(array(1, 2, 3));
SELECT size(array(1, 2, 3));
SELECT array_remove(array(1, 2, 3, 2), 2);
Expected Behavior
The native engine should handle literal array inputs gracefully — either by computing the correct result or by falling back to Spark, not by panicking.
Affected Expressions
array_max()
array_min()
size()
array_remove()