*Hi Apache IoTDB community,*

I have implemented Part 1 of GitHub issue #17797, which allows SELECT
aliases to be referenced in GROUP BY and ORDER BY for the table model SQL
analyzer.

PR: https://github.com/apache/iotdb/pull/17843
Issue: https://github.com/apache/iotdb/issues/17797

This PR supports cases like:

SELECT date_bin(1h, time) AS hour_time, AVG(s1) AS avg_s1
FROM table1
GROUP BY hour_time
ORDER BY hour_time;

The PR follows the name resolution rules discussed in the issue:
- GROUP BY prefers input columns over SELECT aliases.
- ORDER BY prefers SELECT aliases over input columns.
- Duplicate matching SELECT aliases are rejected with an ambiguity error.

This PR only covers Part 1. Lateral column alias references in the SELECT
list are left for a follow-up PR.

I have added unit tests and verified them with:

./mvnw test -pl iotdb-core/datanode -am -Dtest=SelectAliasReuseTest
-DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -DskipITs

The test passed successfully.

Please take a look when you have time. Any feedback is welcome.

Best regards,
Bryan Yang (杨易达)

Reply via email to