You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it("should expand virtual column in GROUP BY",()=>{
1337
+
it("should use alias for virtual column in GROUP BY",()=>{
1338
1338
constctx=createVirtualColumnContext();
1339
1339
const{ sql }=printQuery(
1340
1340
"SELECT is_long_running, count(*) FROM runs GROUP BY is_long_running",
1341
1341
ctx
1342
1342
);
1343
1343
1344
-
// Both SELECT and GROUP BY should have the expansion
1344
+
// SELECT should have the expression with alias
1345
1345
expect(sql).toContain(
1346
-
"GROUP BY (if(completed_at IS NOT NULL AND started_at IS NOT NULL, dateDiff('second', started_at, completed_at) > 60, 0))"
1346
+
"(if(completed_at IS NOT NULL AND started_at IS NOT NULL, dateDiff('second', started_at, completed_at) > 60, 0)) AS is_long_running"
1347
+
);
1348
+
// GROUP BY should use the alias, not the expression (ClickHouse allows this)
1349
+
expect(sql).toContain("GROUP BY is_long_running");
1350
+
// Should NOT have the expression in GROUP BY
1351
+
expect(sql).not.toContain(
1352
+
"GROUP BY (if(completed_at IS NOT NULL AND started_at IS NOT NULL"
1353
+
);
1354
+
});
1355
+
1356
+
it("should use alias for virtual column in GROUP BY with WHERE and aggregation",()=>{
1357
+
constctx=createVirtualColumnContext();
1358
+
const{ sql }=printQuery(
1359
+
"SELECT execution_duration, count() AS duration_count FROM runs WHERE execution_duration IS NOT NULL GROUP BY execution_duration ORDER BY duration_count DESC LIMIT 100",
1360
+
ctx
1361
+
);
1362
+
1363
+
// SELECT should have the expression with alias
1364
+
expect(sql).toContain(
1365
+
"(dateDiff('millisecond', started_at, completed_at)) AS execution_duration"
1366
+
);
1367
+
// GROUP BY should use the alias, not the expression
1368
+
expect(sql).toContain("GROUP BY execution_duration");
1369
+
// Should NOT have the expression in GROUP BY
1370
+
expect(sql).not.toContain("GROUP BY (dateDiff('millisecond'");
0 commit comments