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

Function rewriteIntoProjection

rel/sql_rewrite.go:107–137  ·  view source on GitHub ↗
(sel *SqlSelect, m Columns)

Source from the content-addressed store, hash-verified

105 return sql2
106}
107func rewriteIntoProjection(sel *SqlSelect, m Columns) {
108 if len(m) == 0 {
109 return
110 }
111 colsToAdd := make([]string, 0)
112 for _, c := range m {
113 // u.Infof("source=%-15s as=%-15s exprT:%T expr=%s star:%v", c.As, c.SourceField, c.Expr, c.Expr, c.Star)
114 switch n := c.Expr.(type) {
115 case *expr.IdentityNode:
116 colsToAdd = append(colsToAdd, c.SourceField)
117 case *expr.FuncNode:
118
119 idents := expr.FindAllIdentities(n)
120 for _, in := range idents {
121 _, r, _ := in.LeftRight()
122 colsToAdd = append(colsToAdd, r)
123 }
124
125 case nil:
126 if c.Star {
127 colsToAdd = append(colsToAdd, "*")
128 } else {
129 u.Warnf("unhandled column? %T %s", n, n)
130 }
131
132 default:
133 u.Warnf("unhandled column? %T %s", n, n)
134 }
135 }
136 addIntoProjection(sel, colsToAdd)
137}
138func addIntoProjection(sel *SqlSelect, newCols []string) {
139 notExists := make(map[string]bool)
140 for _, colName := range newCols {

Callers 1

RewriteSelectFunction · 0.85

Calls 3

FindAllIdentitiesFunction · 0.92
addIntoProjectionFunction · 0.85
LeftRightMethod · 0.45

Tested by

no test coverage detected