(m expr.TokenPager, fr expr.FuncResolver, stmt ColumnsStatement)
| 874 | } |
| 875 | |
| 876 | func parseColumns(m expr.TokenPager, fr expr.FuncResolver, stmt ColumnsStatement) error { |
| 877 | |
| 878 | var col *Column |
| 879 | |
| 880 | comment := readComment(m) |
| 881 | |
| 882 | for { |
| 883 | |
| 884 | comment += readComment(m) |
| 885 | |
| 886 | //u.Debug(m.Cur()) |
| 887 | switch m.Cur().T { |
| 888 | case lex.TokenStar, lex.TokenMultiply: |
| 889 | col = &Column{Star: true} |
| 890 | m.Next() |
| 891 | case lex.TokenUdfExpr: |
| 892 | // we have a udf/functional expression column |
| 893 | col = NewColumnFromToken(m.Cur()) |
| 894 | // function canoncial names are always lowercase |
| 895 | funcName := strings.ToLower(m.Cur().V) |
| 896 | exprNode, err := expr.ParseExprWithFuncs(m, fr) |
| 897 | if err != nil { |
| 898 | return err |
| 899 | } |
| 900 | col.Expr = exprNode |
| 901 | col.SourceField = expr.FindFirstIdentity(col.Expr) |
| 902 | if _, r, ok := expr.LeftRight(col.SourceField); ok { |
| 903 | col.SourceField = r |
| 904 | } |
| 905 | if strings.Contains(col.SourceField, ".") { |
| 906 | if _, right, hasLeft := expr.LeftRight(col.SourceField); hasLeft { |
| 907 | col.SourceOriginal = col.SourceField |
| 908 | col.SourceField = right |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | if m.Cur().T != lex.TokenAs { |
| 913 | switch n := col.Expr.(type) { |
| 914 | case *expr.FuncNode: |
| 915 | n.Name = funcName |
| 916 | col.Agg = n.F.Aggregate |
| 917 | col.As = expr.FindIdentityName(0, n, "") |
| 918 | if col.As == "" { |
| 919 | if n.Name == "count" { |
| 920 | col.As = "count(*)" |
| 921 | } else { |
| 922 | col.As = n.Name |
| 923 | } |
| 924 | } |
| 925 | case *expr.BinaryNode: |
| 926 | //u.Debugf("udf? %T ", col.Expr) |
| 927 | col.As = expr.FindIdentityName(0, n, "") |
| 928 | if col.As == "" { |
| 929 | u.Errorf("could not find as name: %#v", n) |
| 930 | } |
| 931 | } |
| 932 | } else { |
| 933 | switch n := col.Expr.(type) { |
no test coverage detected