本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.Datum.ResolvedType方法的典型用法代碼示例。如果您正苦於以下問題:Golang Datum.ResolvedType方法的具體用法?Golang Datum.ResolvedType怎麽用?Golang Datum.ResolvedType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/sql/parser.Datum
的用法示例。
在下文中一共展示了Datum.ResolvedType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DatumToEncDatumWithInferredType
// DatumToEncDatumWithInferredType initializes an EncDatum with the given
// Datum, setting its Type automatically. This does not work if the base
// Datum's type is DNull, in which case an error is returned.
func DatumToEncDatumWithInferredType(datum parser.Datum) (EncDatum, error) {
dType, ok := ColumnType_Kind_value[strings.ToUpper(datum.ResolvedType().String())]
if !ok {
return EncDatum{}, errors.Errorf(
"Unknown type %s, could not convert to EncDatum", datum.ResolvedType())
}
return DatumToEncDatum(ColumnType_Kind(dType), datum), nil
}
示例2: SetDatum
// SetDatum initializes the EncDatum with the given Datum.
func (ed *EncDatum) SetDatum(typ ColumnType_Kind, d parser.Datum) {
if d == nil {
panic("nil datum given")
}
if d != parser.DNull && !typ.ToDatumType().Equal(d.ResolvedType()) {
panic(fmt.Sprintf("invalid datum type given: %s, expected %s",
d.ResolvedType(), typ.ToDatumType()))
}
ed.Type = typ
ed.encoded = nil
ed.Datum = d
}
示例3: DatumToEncDatum
// DatumToEncDatum initializes an EncDatum with the given Datum.
func DatumToEncDatum(ctyp ColumnType, d parser.Datum) EncDatum {
if d == nil {
panic("Cannot convert nil datum to EncDatum")
}
if ptyp := ctyp.ToDatumType(); d != parser.DNull && !ptyp.Equal(d.ResolvedType()) {
panic(fmt.Sprintf("invalid datum type given: %s, expected %s",
d.ResolvedType(), ptyp))
}
return EncDatum{
Type: ctyp,
Datum: d,
}
}
示例4: 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) (roachpb.Value, error) {
var r roachpb.Value
if val == parser.DNull {
return r, nil
}
switch col.Type.Kind {
case ColumnType_BOOL:
if v, ok := val.(*parser.DBool); ok {
r.SetBool(bool(*v))
return r, nil
}
case ColumnType_INT:
if v, ok := val.(*parser.DInt); ok {
r.SetInt(int64(*v))
return r, nil
}
case ColumnType_FLOAT:
if v, ok := val.(*parser.DFloat); ok {
r.SetFloat(float64(*v))
return r, nil
}
case ColumnType_DECIMAL:
if v, ok := val.(*parser.DDecimal); ok {
err := r.SetDecimal(&v.Dec)
return r, err
}
case ColumnType_STRING:
if v, ok := val.(*parser.DString); ok {
r.SetString(string(*v))
return r, nil
}
case ColumnType_BYTES:
if v, ok := val.(*parser.DBytes); ok {
r.SetString(string(*v))
return r, nil
}
if v, ok := val.(*parser.DString); ok {
r.SetString(string(*v))
return r, nil
}
case ColumnType_DATE:
if v, ok := val.(*parser.DDate); ok {
r.SetInt(int64(*v))
return r, nil
}
case ColumnType_TIMESTAMP:
if v, ok := val.(*parser.DTimestamp); ok {
r.SetTime(v.Time)
return r, nil
}
case ColumnType_TIMESTAMPTZ:
if v, ok := val.(*parser.DTimestampTZ); ok {
r.SetTime(v.Time)
return r, nil
}
case ColumnType_INTERVAL:
if v, ok := val.(*parser.DInterval); ok {
err := r.SetDuration(v.Duration)
return r, err
}
default:
return r, errors.Errorf("unsupported column type: %s", col.Type.Kind)
}
return r, fmt.Errorf("value type %s doesn't match type %s of column %q",
val.ResolvedType(), col.Type.Kind, col.Name)
}