Skip to content

Commit 207dd54

Browse files
committed
dolphin: Convert aggregate functions
1 parent 7b9c95a commit 207dd54

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

examples/ondeck/mysql/venue.sql.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/engine/dolphin/convert.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,21 +446,33 @@ func (c *cc) convertAdminStmt(n *pcast.AdminStmt) ast.Node {
446446
}
447447

448448
func (c *cc) convertAggregateFuncExpr(n *pcast.AggregateFuncExpr) *ast.FuncCall {
449-
return &ast.FuncCall{
449+
fn := &ast.FuncCall{
450450
Func: &ast.FuncName{
451-
Name: "count",
451+
Name: n.F,
452452
},
453453
Funcname: &ast.List{
454454
Items: []ast.Node{
455455
&ast.String{
456-
Str: "count",
456+
Str: n.F,
457457
},
458458
},
459459
},
460460
Args: &ast.List{},
461461
AggOrder: &ast.List{},
462-
AggStar: true,
463462
}
463+
for _, a := range n.Args {
464+
if value, ok := a.(*driver.ValueExpr); ok {
465+
if value.GetInt64() == int64(1) {
466+
fn.AggStar = true
467+
continue
468+
}
469+
}
470+
fn.Args.Items = append(fn.Args.Items, c.convert(a))
471+
}
472+
if n.Distinct {
473+
fn.AggDistinct = true
474+
}
475+
return fn
464476
}
465477

466478
func (c *cc) convertAlterDatabaseStmt(n *pcast.AlterDatabaseStmt) ast.Node {

0 commit comments

Comments
 (0)