// ProtoColumnsToFieldTypes converts tipb column info slice to FieldTyps slice. func ProtoColumnsToFieldTypes(pColumns []*tipb.ColumnInfo) []*types.FieldType { fields := make([]*types.FieldType, len(pColumns)) for i, v := range pColumns { field := new(types.FieldType) field.Tp = byte(v.GetTp()) field.Collate = mysql.Collations[byte(v.GetCollation())] field.Decimal = int(v.GetDecimal()) field.Flen = int(v.GetColumnLen()) field.Flag = uint(v.GetFlag()) field.Elems = v.GetElems() fields[i] = field } return fields }
func (d *ddl) setCharsetCollationFlenDecimal(tp *types.FieldType) { if len(tp.Charset) == 0 { switch tp.Tp { case mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString, mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob: tp.Charset, tp.Collate = getDefaultCharsetAndCollate() default: tp.Charset = charset.CharsetBin tp.Collate = charset.CharsetBin } } // If flen is not assigned, assigned it by type. if tp.Flen == types.UnspecifiedLength { tp.Flen = mysql.GetDefaultFieldLength(tp.Tp) } if tp.Decimal == types.UnspecifiedLength { tp.Decimal = mysql.GetDefaultDecimal(tp.Tp) } }