MCPcopy Create free account
hub / github.com/araddon/qlbridge / parseColumns

Function parseColumns

rel/parse_sql.go:876–1002  ·  view source on GitHub ↗
(m expr.TokenPager, fr expr.FuncResolver, stmt ColumnsStatement)

Source from the content-addressed store, hash-verified

874}
875
876func 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) {

Callers 2

parseSelectMethod · 0.85
parseSqlSelectMethod · 0.85

Calls 12

ParseExprWithFuncsFunction · 0.92
FindFirstIdentityFunction · 0.92
LeftRightFunction · 0.92
FindIdentityNameFunction · 0.92
readCommentFunction · 0.85
NewColumnFromTokenFunction · 0.85
NewColumnValueFunction · 0.85
ErrorfMethod · 0.80
CurMethod · 0.65
NextMethod · 0.65
ErrMsgMethod · 0.65
AddColumnMethod · 0.65

Tested by

no test coverage detected