countNonStarsInList counts the number of non-* expressions in a target list
(targets *ast.List)
| 372 | |
| 373 | // countNonStarsInList counts the number of non-* expressions in a target list |
| 374 | func countNonStarsInList(targets *ast.List) int { |
| 375 | if targets == nil { |
| 376 | return 0 |
| 377 | } |
| 378 | count := 0 |
| 379 | for _, target := range targets.Items { |
| 380 | resTarget, ok := target.(*ast.ResTarget) |
| 381 | if !ok { |
| 382 | count++ |
| 383 | continue |
| 384 | } |
| 385 | if resTarget.Val == nil { |
| 386 | count++ |
| 387 | continue |
| 388 | } |
| 389 | colRef, ok := resTarget.Val.(*ast.ColumnRef) |
| 390 | if !ok { |
| 391 | count++ |
| 392 | continue |
| 393 | } |
| 394 | if colRef.Fields == nil { |
| 395 | count++ |
| 396 | continue |
| 397 | } |
| 398 | isStar := false |
| 399 | for _, field := range colRef.Fields.Items { |
| 400 | if _, ok := field.(*ast.A_Star); ok { |
| 401 | isStar = true |
| 402 | break |
| 403 | } |
| 404 | } |
| 405 | if !isStar { |
| 406 | count++ |
| 407 | } |
| 408 | } |
| 409 | return count |
| 410 | } |
| 411 | |
| 412 | // rewriteTargetList replaces * in a target list with explicit column references |
| 413 | func rewriteTargetList(targets *ast.List, columns []string) *ast.List { |