When you run a query with an invalid column that also does a group by on a constructed column, the error message you get back references a missing column for the group by rather than the invalid column.
You can reproduce this in pyspark in 3.1.2 with the following code:
The error message for the second spark.sql line is
pyspark.sql.utils.AnalysisException: cannot resolve '`week`' given input columns: [data.d, data.v]; line 1 pos 81;
'Aggregate ['week], 'sum('val) AS value#21, cast(date_trunc(week, cast(d#0 as timestamp), Some(America/New_York)) as date) AS week#22
+- SubqueryAlias data
+- LogicalRDD d#0, v#1L, false
but the actual problem is that I used the wrong variable name in a different part of the query. Nothing is wrong with week in this case.