Skip to content

Commit 11a178a

Browse files
authored
Table: Support SELECT aliases in GROUP BY and ORDER BY (#17843)
1 parent ddd8faa commit 11a178a

4 files changed

Lines changed: 571 additions & 16 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5499,6 +5499,75 @@ public void singleInputDistinctAggregationTest() {
54995499
DATABASE_NAME);
55005500
}
55015501

5502+
@Test
5503+
public void selectAliasInGroupByAndOrderByTest() {
5504+
String[] expectedHeader = new String[] {"hour_time", "_col1"};
5505+
String[] retArray =
5506+
new String[] {
5507+
"2024-09-24T06:15:30.000Z,1,",
5508+
"2024-09-24T06:15:35.000Z,1,",
5509+
"2024-09-24T06:15:40.000Z,1,",
5510+
"2024-09-24T06:15:50.000Z,1,",
5511+
"2024-09-24T06:15:55.000Z,1,",
5512+
};
5513+
tableResultSetEqualTest(
5514+
"select date_bin(5s, time) as hour_time, count(*) from table1 where device_id = 'd01' group by hour_time order by hour_time",
5515+
expectedHeader,
5516+
retArray,
5517+
DATABASE_NAME);
5518+
5519+
expectedHeader = new String[] {"province", "input_province"};
5520+
retArray = new String[] {"d01,shanghai,", "d01,shanghai,"};
5521+
tableResultSetEqualTest(
5522+
"select device_id as province, province as input_province from table1 where device_id in ('d01', 'd09') order by province limit 2",
5523+
expectedHeader,
5524+
retArray,
5525+
DATABASE_NAME);
5526+
5527+
expectedHeader = new String[] {"x"};
5528+
retArray = new String[] {"30,", "40,", "55,"};
5529+
tableResultSetEqualTest(
5530+
"select distinct s1 as x from table1 where device_id = 'd01' and s1 is not null order by x",
5531+
expectedHeader,
5532+
retArray,
5533+
DATABASE_NAME);
5534+
tableResultSetEqualTest(
5535+
"select s1 as x from table1 where device_id = 'd01' and s1 is not null order by x + 1",
5536+
expectedHeader,
5537+
retArray,
5538+
DATABASE_NAME);
5539+
5540+
expectedHeader = new String[] {"rn"};
5541+
retArray = new String[] {"1,", "2,", "3,", "4,", "5,"};
5542+
tableResultSetEqualTest(
5543+
"select row_number() over (order by time) as rn from table1 where device_id = 'd01' order by rn",
5544+
expectedHeader,
5545+
retArray,
5546+
DATABASE_NAME);
5547+
5548+
tableAssertTestFail(
5549+
"select s1 as x, count(*) from table1 where device_id = 'd01' and s1 is not null group by rollup(x) order by x nulls last",
5550+
"Only support one groupingSet now",
5551+
DATABASE_NAME);
5552+
tableAssertTestFail(
5553+
"select s1 as x, count(*) from table1 where device_id = 'd01' and s1 is not null group by cube(x) order by x nulls last",
5554+
"Only support one groupingSet now",
5555+
DATABASE_NAME);
5556+
5557+
expectedHeader = new String[] {"x", "_col1"};
5558+
retArray = new String[] {"30,1,", "40,1,", "55,1,"};
5559+
tableResultSetEqualTest(
5560+
"select s1 as x, count(*) from table1 where device_id = 'd01' and s1 is not null group by grouping sets ((x)) order by x",
5561+
expectedHeader,
5562+
retArray,
5563+
DATABASE_NAME);
5564+
5565+
tableAssertTestFail(
5566+
"select s1 as x, s2 as x, count(*) from table1 group by rollup(x)",
5567+
"Column alias 'x' is ambiguous",
5568+
DATABASE_NAME);
5569+
}
5570+
55025571
@Test
55035572
public void exceptionTest2() {
55045573
tableAssertTestFail(

0 commit comments

Comments
 (0)