[SPARK-3395] DSL sometimes incorrectly reuses attribute ids, breaking queries

This resolves https://issues.apache.org/jira/browse/SPARK-3395