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

Method BuildColIndex

rel/sql.go:1392–1426  ·  view source on GitHub ↗
(colNames []string)

Source from the content-addressed store, hash-verified

1390}
1391
1392func (m *SqlSource) BuildColIndex(colNames []string) error {
1393 if len(m.colIndex) == 0 {
1394 m.colIndex = make(map[string]int, len(colNames))
1395 }
1396 if len(colNames) == 0 {
1397 u.LogTraceDf(u.WARN, 10, "No columns?")
1398 }
1399 starDelta := 0 // how many columns were added due to *
1400 for _, col := range m.Source.Columns {
1401 if col.Star {
1402 starStart := len(m.colIndex)
1403 for colIdx := range colNames {
1404 m.colIndex[col.Key()] = colIdx + starStart
1405 }
1406 starDelta = len(colNames)
1407 } else {
1408 found := false
1409 for colIdx, colName := range colNames {
1410 _, colName, _ = expr.LeftRight(colName)
1411 //u.Debugf("col.Key():%v sourceField:%v colName:%v", col.Key(), col.SourceField, colName)
1412 if colName == col.Key() || col.SourceField == colName { //&&
1413 //u.Debugf("build col: idx=%d key=%-15q as=%-15q col=%-15s sourcidx:%d", len(m.colIndex), col.Key(), col.As, col.String(), colIdx)
1414 m.colIndex[col.Key()] = colIdx + starDelta
1415 col.SourceIndex = colIdx + starDelta
1416 found = true
1417 break
1418 }
1419 }
1420 if !found && !col.IsLiteralOrFunc() {
1421 return fmt.Errorf("Missing Column in source: %q", col.String())
1422 }
1423 }
1424 }
1425 return nil
1426}
1427
1428// Rewrite this Source to act as a stand-alone query to backend
1429// @parentStmt = the parent statement that this a partial source to

Callers 1

buildColIndexFunction · 0.80

Calls 5

LeftRightFunction · 0.92
IsLiteralOrFuncMethod · 0.80
ErrorfMethod · 0.80
KeyMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected