[Bug] The combination of Command and Aggregate operators causes colmun verification to fail
- Dominant language
- Scala
- Stars
- 2.4k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
### Search before asking
- [X] I have searched in the [issues](https://github.com/apache/kyuubi/issues?q=is%3Aissue) and found no similar issues.
### Describe the bug
test code:
```
test("auth: Command and Aggregate operators causes colmun verification to fail") {
val db = "default"
val table = "src"
val col = "key"
val create = s"CREATE TABLE IF NOT EXISTS $db.$table ($col int, value int) USING $format"
val select = s"CACHE TABLE TEST AS SELECT key FROM $db.$table group by key"
withCleanTmpResources(Seq((s"$db.$table", "table"))) {
doAs("bob", sql(create))
doAs("kent", sql(select).collect())
}
}
```

explain :
```
CacheTableAsSelect TEST, SELECT key FROM default.src group by key, false, true
+- Aggregate [key#17], [key#17]
+- SubqueryAlias spark_catalog.default.src
+- HiveTableRelation [`spark_catalog`.`default`.`src`, org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, Data Cols: [key#17, value#18], Partition Cols: []]
```
This paln did not generate **project** operator, causing PrivilegesBuilder's mergeProjection to merge all columns of HiveTableRelation.

### Affects Version(s)
master
### Kyuubi Server Log Output
_No response_
### Kyuubi Engine Log Output
_No response_
### Kyuubi Server Configurations
_No response_
### Kyuubi Engine Configurations
_No response_
### Additional context
_No response_
### Are you willing to submit PR?
- [X] Yes. I would be willing to submit a PR with guidance from the Kyuubi community to fix.
- [ ] No. I cannot submit a PR at this time.
Contributor guide
Research direction
Start by running the test case from the issue and tracing PrivilegesBuilder.mergeProjection for the shown CacheTableAsSelect and Aggregate plan. Check how the HiveTableRelation columns are handled during verification; done when the reproduction no longer merges unselected columns and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala, spark, sql
- Domain
- authorization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100