//export goVColumn
180819
func goVColumn(pCursor, cp unsafe.Pointer, col C.int) *C.char {
	vtc := lookupHandle(uintptr(pCursor)).(*sqliteVTabCursor)
	c := (*SQLiteContext)(cp)
	err := vtc.vTabCursor.Column(c, int(col))
	if err != nil {
		return mPrintf("%s", err.Error())
	}
	return nil
}
441624
func (s *Schema) FindColumn(astCol *ast.ColumnName) (*Column, error) {
	col, _, err := s.FindColumnAndIndex(astCol)
	return col, err
}
932349
func (d *Dataset) ConstrainColumn(header string, constraint ColumnConstraint) {
	i := indexOfColumn(header, d)
	if i != -1 {
		d.constraints[i] = constraint
	}
}
856900
func LexDdlTableColumn(l *Lexer) StateFn {

	/*
		http://dev.mysql.com/doc/refman/5.7/en/create-table.html

		create_definition:
		    col_name column_definition
		  | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)
		      [index_option] ...
		  | {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
		      [index_option] ...
		  | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
		      [index_name] [index_type] (index_col_name,...)
		      [index_option] ...
		  | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...)
		      [index_option] ...
		  | [CONSTRAINT [symbol]] FOREIGN KEY
		      [index_name] (index_col_name,...) reference_definition
		  | CHECK (expr)

		column_definition:
		    data_type [NOT NULL | NULL] [DEFAULT default_value]
		      [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
		      [COMMENT 'string']
		      [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
		      [STORAGE {DISK|MEMORY|DEFAULT}]
		      [reference_definition]
		  | data_type [GENERATED ALWAYS] AS (expression)
		      [VIRTUAL | STORED] [UNIQUE [KEY]] [COMMENT comment]
		      [NOT NULL | NULL] [[PRIMARY] KEY]
	*/
	l.SkipWhiteSpaces()
	r := l.Next()

	//u.Debugf("LexDdlTableColumn  r= '%v'  peek: %s", string(r), l.PeekX(20))

	//
	switch r {
	case '-', '/': // comment?
		p := l.Peek()
		if p == '-' {
			l.backup()
			l.Push("LexDdlTableColumn", LexDdlTableColumn)
			return LexInlineComment
		}
	case ';':
		l.backup()
		return nil
	case '(':
		l.Emit(TokenLeftParenthesis)
		l.Push("LexDdlTableColumn", LexDdlTableColumn)
		l.Push("LexParenRight", LexParenRight)
		return LexListOfArgs
	case ')':
		l.Emit(TokenRightParenthesis)
		return nil
	case ',':
		l.Emit(TokenComma)
		return LexDdlTableColumn
	}

	l.backup()
	word := strings.ToLower(l.PeekWord())
	//u.Debugf("looking for ddl col start:  word=%s", word)
	switch word {
	case "primary":
		l.ConsumeWord(word)
		l.Emit(TokenPrimary)
		return LexDdlTableColumn
	case "not":
		l.ConsumeWord(word)
		l.Emit(TokenNegate)
		return LexDdlTableColumn
	case "null":
		l.ConsumeWord(word)
		l.Emit(TokenNull)
		return LexDdlTableColumn
	case "default":
		l.ConsumeWord(word)
		l.Emit(TokenDefault)
		l.Push("LexDdlTableColumn", LexDdlTableColumn)
		return LexValue
	case "auto_increment":
		l.ConsumeWord(word)
		l.Emit(TokenIdentity)
		return LexDdlTableColumn
	case "unique":
		l.ConsumeWord(word)
		l.Emit(TokenUnique)
		return LexDdlTableColumn
	case "foreign":
		l.ConsumeWord(word)
		l.Emit(TokenForeign)
		return LexDdlTableColumn
	case "key":
		l.ConsumeWord(word)
		l.Emit(TokenKey)
		return LexDdlTableColumn
	case "constraint":
		l.ConsumeWord(word)
		l.Emit(TokenConstraint)
		l.Push("LexDdlTableColumn", LexDdlTableColumn)
		return LexIdentifier
	case "references":
		l.ConsumeWord(word)
		l.Emit(TokenReferences)
		return LexDdlTableColumn
	case "comment":
		l.ConsumeWord(word)
		l.Emit(TokenIdentity)
		l.Push("LexDdlTableColumn", LexDdlTableColumn)
		return LexValue
	// Character set is end of ddl column
	// case "character": // character set
	// 	cs := strings.ToLower(l.PeekX(len("character set")))
	// 	if cs == "character set" {
	// 		l.ConsumeWord(cs)
	// 		l.Emit(TokenCharacterSet)
	// 		l.Push("LexDdlTableColumn", LexDdlTableColumn)
	// 		return nil
	// 	}
	// Below here are Data Types
	case "int", "integer":
		l.ConsumeWord(word)
		l.Emit(TokenTypeInteger)
		p := l.Peek()
		if p == '(' {
			l.Push("LexDdlTableColumn", LexDdlTableColumn)
			l.Push("LexParenRight", LexParenRight)
			return LexListOfArgs
		}
		return LexDdlTableColumn
	case "text":
		l.ConsumeWord(word)
		l.Emit(TokenTypeText)
		return LexDdlTableColumn
	case "bigint":
		l.ConsumeWord(word)
		l.Emit(TokenTypeBigInt)
		p := l.Peek()
		if p == '(' {
			l.Push("LexDdlTableColumn", LexDdlTableColumn)
			l.Push("LexParenRight", LexParenRight)
			return LexListOfArgs
		}
		return LexDdlTableColumn
	case "varchar":
		l.ConsumeWord(word)
		l.Emit(TokenTypeVarChar)
		l.Push("LexDdlTableColumn", LexDdlTableColumn)
		l.Push("LexParenRight", LexParenRight)
		return LexListOfArgs
	case "char":
		l.ConsumeWord(word)
		l.Emit(TokenTypeChar)
		l.Push("LexDdlTableColumn", LexDdlTableColumn)
		l.Push("LexParenRight", LexParenRight)
		return LexListOfArgs
	default:
		if l.isIdentity() {
			l.ConsumeWord(word)
			l.Emit(TokenIdentity)
			return LexDdlTableColumn
		}
	}

	u.Warnf("Did not find anything %s", word)
	return nil
}
238338
func (tb *CreateTableBuilder) appendColumn(c *tableColumn) *CreateTableBuilder {
	tb.columns = append(tb.columns, *c)
	return tb
}
1183523
func indexCol2Col(cols []*Column, col *model.IndexColumn) *Column {
	for _, c := range cols {
		if c.ColName.L == col.Name.L {
			return c
		}
	}
	return nil
}
198476
func (t *TableMap) ColMap(field string) *ColumnMap {
	for _, col := range t.Columns {
		if col.fieldName == field || col.ColumnName == field {
			return col
		}
	}
	panic(fmt.Sprintf("No ColumnMap in table %s type %s with field %s",
		t.TableName, t.gotype.Name(), field))
}
937247
func (d *Dataset) Tabular(format string) *Exportable {
	back := d.Records()
	t := gotabulate.Create(back)

	if format == TabularCondensed || format == TabularMarkdown {
		rendered := regexp.MustCompile("\n\n\\s").ReplaceAllString(t.Render("simple"), "\n ")
		if format == TabularMarkdown {
			firstLine := regexp.MustCompile("-\\s+-").ReplaceAllString(strings.Split(rendered, "\n")[0], "- | -")
			// now just locate the position of pipe characterds, and set them
			positions := make([]int, 0, d.cols-1)
			x := 0
			for _, c := range firstLine {
				if c == '|' {
					positions = append(positions, x)
				}
				x += utf8.RuneLen(c)
			}

			b := newBuffer()
			lines := strings.Split(rendered, "\n")
			for _, line := range lines[1 : len(lines)-2] {
				ipos := 0
				b.WriteString("| ")
				for _, pos := range positions {
					if ipos < len(line) && pos < len(line) {
						b.WriteString(line[ipos:pos])
						b.WriteString(" | ")
						ipos = pos + 1
					}
				}
				if ipos < len(line) {
					b.WriteString(line[ipos:])
				}
				b.WriteString(" | \n")
			}
			return newExportable(b)
		}
		return newExportableFromString(rendered)
	}
	return newExportableFromString(t.Render(format))
}
655409
func (ts *TableSpec) AddColumn(cd *ColumnDefinition) {
	ts.Columns = append(ts.Columns, cd)
}
889242
func BuildColumn(ctx sessionctx.Context, numBuckets, id int64, collector *SampleCollector, tp *types.FieldType) (*Histogram, error) {
	return BuildColumnHist(ctx, numBuckets, id, collector, tp, collector.Count, collector.FMSketch.NDV(), collector.NullCount)
}
30825
func (vt *VirtualTable) RowWithCols(ctx sessionctx.Context, h int64, cols []*table.Column) ([]types.Datum, error) {
	return nil, table.ErrUnsupportedOp
}
412014
func (d *ddl) ChangeColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.AlterTableSpec) error {
	specNewColumn := spec.NewColumns[0]
	if len(specNewColumn.Name.Schema.O) != 0 && ident.Schema.L != specNewColumn.Name.Schema.L {
		return ErrWrongDBName.GenWithStackByArgs(specNewColumn.Name.Schema.O)
	}
	if len(spec.OldColumnName.Schema.O) != 0 && ident.Schema.L != spec.OldColumnName.Schema.L {
		return ErrWrongDBName.GenWithStackByArgs(spec.OldColumnName.Schema.O)
	}
	if len(specNewColumn.Name.Table.O) != 0 && ident.Name.L != specNewColumn.Name.Table.L {
		return ErrWrongTableName.GenWithStackByArgs(specNewColumn.Name.Table.O)
	}
	if len(spec.OldColumnName.Table.O) != 0 && ident.Name.L != spec.OldColumnName.Table.L {
		return ErrWrongTableName.GenWithStackByArgs(spec.OldColumnName.Table.O)
	}

	job, err := d.getModifiableColumnJob(ctx, ident, spec.OldColumnName.Name, spec)
	if err != nil {
		return errors.Trace(err)
	}

	err = d.doDDLJob(ctx, job)
	err = d.callHookOnChanged(err)
	return errors.Trace(err)
}
499629
func (p *LogicalWindow) GetWindowResultColumn() *expression.Column {
	return p.schema.Columns[p.schema.Len()-1]
}
1259086
func (t *ShellTable) MaxColumnWidths() []int {
	if t.maxColumnWidths == nil {
		t.maxColumnWidths = &[]int{}
	}
	for _, r := range t.rows {
		for i, c := range r.columns {
			if len(*t.maxColumnWidths) == i {
				*t.maxColumnWidths = append(*t.maxColumnWidths, 0)
			}
			colWidth := len(c.String())
			if colWidth > (*t.maxColumnWidths)[i] {
				(*t.maxColumnWidths)[i] = colWidth
			}
		}
	}
	return *t.maxColumnWidths
}
637803
func columnNamesCover(normalColNames map[string]struct{}, dependColNames map[string]struct{}) error {
	for name := range dependColNames {
		if _, ok := normalColNames[name]; !ok {
			return errBadField.GenWithStackByArgs(name, "generated column function")
		}
	}
	return nil
}
344840
func (pub *PublicKey) ExportECDSA() *ecdsa.PublicKey {
	return &ecdsa.PublicKey{Curve: pub.Curve, X: pub.X, Y: pub.Y}
}
40811
func (b *SqliteBuilder) DropColumn(table, col string) *Query {
	q := b.NewQuery("")
	q.LastError = errors.New("SQLite does not support dropping columns")
	return q
}