本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.MapArgs类的典型用法代码示例。如果您正苦于以下问题:Golang MapArgs类的具体用法?Golang MapArgs怎么用?Golang MapArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MapArgs类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CheckColumnType
// CheckColumnType verifies that a given value is compatible
// with the type requested by the column. If the value is a
// placeholder, the type of the placeholder gets populated.
func CheckColumnType(col ColumnDescriptor, val parser.Datum, args parser.MapArgs) error {
if val == parser.DNull {
return nil
}
var ok bool
var err error
var set parser.Datum
switch col.Type.Kind {
case ColumnType_BOOL:
_, ok = val.(*parser.DBool)
set, err = args.SetInferredType(val, parser.TypeBool)
case ColumnType_INT:
_, ok = val.(*parser.DInt)
set, err = args.SetInferredType(val, parser.TypeInt)
case ColumnType_FLOAT:
_, ok = val.(*parser.DFloat)
set, err = args.SetInferredType(val, parser.TypeFloat)
case ColumnType_DECIMAL:
_, ok = val.(*parser.DDecimal)
set, err = args.SetInferredType(val, parser.TypeDecimal)
case ColumnType_STRING:
_, ok = val.(*parser.DString)
set, err = args.SetInferredType(val, parser.TypeString)
case ColumnType_BYTES:
_, ok = val.(*parser.DBytes)
if !ok {
_, ok = val.(*parser.DString)
}
set, err = args.SetInferredType(val, parser.TypeBytes)
case ColumnType_DATE:
_, ok = val.(*parser.DDate)
set, err = args.SetInferredType(val, parser.TypeDate)
case ColumnType_TIMESTAMP:
_, ok = val.(*parser.DTimestamp)
set, err = args.SetInferredType(val, parser.TypeTimestamp)
case ColumnType_TIMESTAMPTZ:
_, ok = val.(*parser.DTimestampTZ)
set, err = args.SetInferredType(val, parser.TypeTimestampTZ)
case ColumnType_INTERVAL:
_, ok = val.(*parser.DInterval)
set, err = args.SetInferredType(val, parser.TypeInterval)
default:
return util.Errorf("unsupported column type: %s", col.Type.Kind)
}
// Check that the value cast has succeeded.
// We ignore the case where it has failed because val was a DArg,
// which is signalled by SetInferredType returning a non-nil assignment.
if !ok && set == nil {
return fmt.Errorf("value type %s doesn't match type %s of column %q",
val.Type(), col.Type.Kind, col.Name)
}
return err
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:57,代码来源:table.go
示例2: marshalColumnValue
// marshalColumnValue returns a Go primitive value equivalent of val, of the
// type expected by col. If val's type is incompatible with col, or if
// col's type is not yet implemented, an error is returned.
func marshalColumnValue(col ColumnDescriptor, val parser.Datum, args parser.MapArgs) (interface{}, error) {
if val == parser.DNull {
return nil, nil
}
switch col.Type.Kind {
case ColumnType_BOOL:
if v, ok := val.(parser.DBool); ok {
return bool(v), nil
}
if set, err := args.SetInferredType(val, parser.DummyBool); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_INT:
if v, ok := val.(parser.DInt); ok {
return int64(v), nil
}
if set, err := args.SetInferredType(val, parser.DummyInt); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_FLOAT:
if v, ok := val.(parser.DFloat); ok {
return float64(v), nil
}
if set, err := args.SetInferredType(val, parser.DummyFloat); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_DECIMAL:
if v, ok := val.(*parser.DDecimal); ok {
return v.Dec, nil
}
if set, err := args.SetInferredType(val, parser.DummyDecimal); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_STRING:
if v, ok := val.(parser.DString); ok {
return string(v), nil
}
if set, err := args.SetInferredType(val, parser.DummyString); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_BYTES:
if v, ok := val.(parser.DBytes); ok {
return string(v), nil
}
if v, ok := val.(parser.DString); ok {
return string(v), nil
}
if set, err := args.SetInferredType(val, parser.DummyBytes); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_DATE:
if v, ok := val.(parser.DDate); ok {
return int64(v), nil
}
if set, err := args.SetInferredType(val, parser.DummyDate); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_TIMESTAMP:
if v, ok := val.(parser.DTimestamp); ok {
return v.Time, nil
}
if set, err := args.SetInferredType(val, parser.DummyTimestamp); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
case ColumnType_INTERVAL:
if v, ok := val.(parser.DInterval); ok {
return v.Duration, nil
}
if set, err := args.SetInferredType(val, parser.DummyInterval); err != nil {
return nil, err
} else if set != nil {
return nil, nil
}
default:
return nil, util.Errorf("unsupported column type: %s", col.Type.Kind)
}
return nil, fmt.Errorf("value type %s doesn't match type %s of column %q",
val.Type(), col.Type.Kind, col.Name)
}
开发者ID:thebrandonstore,项目名称:cockroach,代码行数:99,代码来源:table.go
注:本文中的github.com/cockroachdb/cockroach/sql/parser.MapArgs类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论