// ColumnNames will walk all fields and functions and return the appropriate field names for the select statement
// while maintaining order of the field names.
182146
func (s *SelectStatement) ColumnNames() []string {
	// First walk each field to determine the number of columns.
	columnFields := Fields{}
	for _, field := range s.Fields {
		columnFields = append(columnFields, field)

		switch f := field.Expr.(type) {
		case *Call:
			if s.Target == nil && (f.Name == "top" || f.Name == "bottom") {
				for _, arg := range f.Args[1:] {
					ref, ok := arg.(*VarRef)
					if ok {
						columnFields = append(columnFields, &Field{Expr: ref})
					}
				}
			}
		}
	}

	// Determine if we should add an extra column for an implicit time.
	offset := 0
	if !s.OmitTime {
		offset++
	}

	columnNames := make([]string, len(columnFields)+offset)
	if !s.OmitTime {
		// Add the implicit time if requested.
		columnNames[0] = s.TimeFieldName()
	}

	// Keep track of the encountered column names.
	names := make(map[string]int)

	// Resolve aliases first.
	for i, col := range columnFields {
		if col.Alias != "" {
			columnNames[i+offset] = col.Alias
			names[col.Alias] = 1
		}
	}

	// Resolve any generated names and resolve conflicts.
	for i, col := range columnFields {
		if columnNames[i+offset] != "" {
			continue
		}

		name := col.Name()
		count, conflict := names[name]
		if conflict {
			for {
				resolvedName := fmt.Sprintf("%s_%d", name, count)
				_, conflict = names[resolvedName]
				if !conflict {
					names[name] = count + 1
					name = resolvedName
					break
				}
				count++
			}
		}
		names[name]++
		columnNames[i+offset] = name
	}
	return columnNames
}
164568
func (d *Dataset) columnSQLType(header, dbType string) (string, []interface{}) {
	types := 0
	currentType := ""
	maxString := 0
	values := d.Column(header)
	for _, c := range values {
		switch c.(type) {
		case uint, uint8, uint16, uint32, uint64,
			int, int8, int16, int32, int64,
			float32, float64:
			if currentType != "numeric" {
				currentType = "numeric"
				types++
			}
		case time.Time:
			if currentType != "time" {
				currentType = "time"
				types++
			}
		case string:
			if currentType != "string" {
				currentType = "string"
				types++
			}
			if len(c.(string)) > maxString {
				maxString = len(c.(string))
			}
		}
	}

	if types > 1 {
		return defaults["various."+dbType], values
	}
	switch currentType {
	case "numeric":
		return defaults["numeric."+dbType], values
	case "time":
		return "TIMESTAMP", values
	default:
		if dbType == typePostgres {
			return "TEXT", values
		}
		return "VARCHAR(" + strconv.Itoa(maxString) + ")", values
	}
}
11518
func (dt *DbfTable) FieldNames() []string {
	names := make([]string, 0)

	for _, field := range dt.Fields() {
		names = append(names, field.name)
	}

	return names
}
468473
func SqTableColumns(db XODB, table string) ([]*SqColumn, error) {
	var err error

	// sql query
	var sqlstr = `PRAGMA table_info(` + table + `)`

	// run query
	XOLog(sqlstr)
	q, err := db.Query(sqlstr, table)
	if err != nil {
		return nil, err
	}
	defer q.Close()

	// load results
	res := []*SqColumn{}
	for q.Next() {
		sc := SqColumn{}

		// scan
		err = q.Scan(&sc.FieldOrdinal, &sc.ColumnName, &sc.DataType, &sc.NotNull, &sc.DefaultValue, &sc.PkColIndex)
		if err != nil {
			return nil, err
		}

		res = append(res, &sc)
	}

	return res, nil
}
453891
func (a *ArgType) colname(col *models.Column) string {
	if a.EscapeColumnNames {
		return a.Loader.Escape(ColumnEsc, col.ColumnName)
	}

	return col.ColumnName
}
404346
func GetFieldTypes(db *sql.DB, dbName string, tableName string) []FieldType {
	fields := GetFields(db, dbName, tableName)
	if fields == nil {
		return nil
	}
	types := make([]FieldType, len(fields))
	for i, f := range fields {
		types[i] = f.Type
	}
	return types
}
384340
func (rc *SQLiteRows) ColumnTypeDatabaseTypeName(i int) string {
	return C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))
}
1368663
func (d *dbBase) GetColumns(db dbQuerier, table string) (map[string][3]string, error) {
	columns := make(map[string][3]string)
	query := d.ins.ShowColumnsQuery(table)
	rows, err := db.Query(query)
	if err != nil {
		return columns, err
	}

	defer rows.Close()

	for rows.Next() {
		var (
			name string
			typ  string
			null string
		)
		err := rows.Scan(&name, &typ, &null)
		if err != nil {
			return columns, err
		}
		columns[name] = [3]string{name, typ, null}
	}

	return columns, nil
}
820120
func (rows *Rows) Columns() ([]string, error) {
	if rows.token == nil {
		return []string{}, nil
	}
	startElement := rows.token.(xml.StartElement)
	r := xlsxRow{}
	_ = rows.decoder.DecodeElement(&r, &startElement)
	d := rows.f.sharedStringsReader()
	columns := make([]string, len(r.C))
	for _, colCell := range r.C {
		col, _, err := CellNameToCoordinates(colCell.R)
		if err != nil {
			return columns, err
		}
		val, _ := colCell.getValueFrom(rows.f, d)
		columns[col-1] = val
	}
	return columns, nil
}
928835
func (f Fields) Names() (v []string) {
	for k := range f {
		v = append(v, k)
	}

	sort.Strings(v)
	return
}
760413
func (t *Table) Select(columns ...string) (stmt string, names []string) {
	if len(columns) == 0 {
		return t.sel.stmt, t.sel.names
	}

	return qb.Select(t.metadata.Name).
		Columns(columns...).
		Where(t.primaryKeyCmp[0:len(t.metadata.PartKey)]...).
		ToCql()
}
1038042
func (m *Table) SetColumnsFromFields() {
	m.FieldPositions = make(map[string]int, len(m.Fields))
	cols := make([]string, len(m.Fields))
	for idx, f := range m.Fields {
		col := strings.ToLower(f.Name)
		m.FieldPositions[col] = idx
		cols[idx] = col
	}
	m.cols = cols
}
844008
func (p *ExtensionManagerClient) GetQueryColumns(ctx context.Context, sql string) (r *ExtensionResponse, err error) {
  var _args31 ExtensionManagerGetQueryColumnsArgs
  _args31.Sql = sql
  var _result32 ExtensionManagerGetQueryColumnsResult
  if err = p.Client_().Call(ctx, "getQueryColumns", &_args31, &_result32); err != nil {
    return
  }
  return _result32.GetSuccess(), nil
}
108701
func (l *lexer) columnNum() int {
	if lf := strings.LastIndex(l.input[:l.pos], "\n"); lf != -1 {
		return len(l.input[lf+1 : l.pos])
	}
	return len(l.input[:l.pos])
}
1370878
func (t *transpilerState) mapFields(in cursor) (cursor, error) {
	columns := t.stmt.ColumnNames()
	if len(columns) != len(t.stmt.Fields) {
		// TODO(jsternberg): This scenario should not be possible. Replace the use of ColumnNames with a more
		// statically verifiable list of columns when we process the fields from the select statement instead
		// of doing this in the future.
		panic("number of columns does not match the number of fields")
	}

	properties := make([]*ast.Property, 0, len(t.stmt.Fields)+1)
	properties = append(properties, &ast.Property{
		Key: &ast.Identifier{
			Name: execute.DefaultTimeColLabel,
		},
		Value: &ast.MemberExpression{
			Object: &ast.Identifier{
				Name: "r",
			},
			Property: &ast.Identifier{
				Name: execute.DefaultTimeColLabel,
			},
		},
	})
	for i, f := range t.stmt.Fields {
		if ref, ok := f.Expr.(*influxql.VarRef); ok && ref.Val == "time" {
			// Skip past any time columns.
			continue
		}
		value, err := t.mapField(f.Expr, in)
		if err != nil {
			return nil, err
		}
		properties = append(properties, &ast.Property{
			Key:   &ast.Identifier{Name: columns[i]},
			Value: value,
		})
	}
	return &mapCursor{
		expr: &ast.PipeExpression{
			Argument: in.Expr(),
			Call: &ast.CallExpression{
				Callee: &ast.Identifier{
					Name: "map",
				},
				Arguments: []ast.Expression{
					&ast.ObjectExpression{
						Properties: []*ast.Property{{
							Key: &ast.Identifier{
								Name: "fn",
							},
							Value: &ast.FunctionExpression{
								Params: []*ast.Property{{
									Key: &ast.Identifier{Name: "r"},
								}},
								Body: &ast.ObjectExpression{
									Properties: properties,
								},
							},
						}},
					},
				},
			},
		},
	}, nil
}
543813
func (table *TableElem) Columns() []ColumnElem {
	columns := make([]ColumnElem, len(table.order))
	for index, name := range table.order {
		columns[index] = table.C[name]
	}
	return columns
}
1014205
func (q *query) fieldNames() []string {
	switch {
	case q.hasIncludes():
		return q.includes
	case q.hasExcludes():
		results := q.collection.spec.fieldNames()
		for _, name := range q.excludes {
			results = removeElementFromStringSlice(results, name)
		}
		return results
	default:
		return q.collection.spec.fieldNames()
	}
}