本文整理匯總了Golang中github.com/cockroachdb/cockroach/roachpb.Value.GetInt方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.GetInt方法的具體用法?Golang Value.GetInt怎麽用?Golang Value.GetInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/roachpb.Value
的用法示例。
在下文中一共展示了Value.GetInt方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mustGetInt
// mustGetInt decodes an int64 value from the bytes field of the receiver
// and panics if the bytes field is not 0 or 8 bytes in length.
func mustGetInt(v *roachpb.Value) int64 {
if v == nil {
return 0
}
i, err := v.GetInt()
if err != nil {
panic(err)
}
return i
}
示例2: unmarshalColumnValue
// unmarshalColumnValue decodes the value from a key-value pair using the type
// expected by the column. An error is returned if the value's type does not
// match the column's type.
func unmarshalColumnValue(kind ColumnType_Kind, value *roachpb.Value) (parser.Datum, *roachpb.Error) {
if value == nil {
return parser.DNull, nil
}
switch kind {
case ColumnType_BOOL:
v, err := value.GetInt()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DBool(v != 0), nil
case ColumnType_INT:
v, err := value.GetInt()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DInt(v), nil
case ColumnType_FLOAT:
v, err := value.GetFloat()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DFloat(v), nil
case ColumnType_STRING:
v, err := value.GetBytes()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DString(v), nil
case ColumnType_BYTES:
v, err := value.GetBytes()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DBytes(v), nil
case ColumnType_DATE:
v, err := value.GetInt()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DDate(v), nil
case ColumnType_TIMESTAMP:
v, err := value.GetTime()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DTimestamp{Time: v}, nil
case ColumnType_INTERVAL:
v, err := value.GetInt()
if err != nil {
return nil, roachpb.NewError(err)
}
return parser.DInterval{Duration: time.Duration(v)}, nil
default:
return nil, roachpb.NewErrorf("unsupported column type: %s", kind)
}
}
示例3: UnmarshalColumnValue
// UnmarshalColumnValue decodes the value from a key-value pair using the type
// expected by the column. An error is returned if the value's type does not
// match the column's type.
func UnmarshalColumnValue(
a *DatumAlloc, kind ColumnType_Kind, value *roachpb.Value,
) (parser.Datum, error) {
if value == nil {
return parser.DNull, nil
}
switch kind {
case ColumnType_BOOL:
v, err := value.GetInt()
if err != nil {
return nil, err
}
return parser.MakeDBool(parser.DBool(v != 0)), nil
case ColumnType_INT:
v, err := value.GetInt()
if err != nil {
return nil, err
}
return a.NewDInt(parser.DInt(v)), nil
case ColumnType_FLOAT:
v, err := value.GetFloat()
if err != nil {
return nil, err
}
return a.NewDFloat(parser.DFloat(v)), nil
case ColumnType_DECIMAL:
v, err := value.GetDecimal()
if err != nil {
return nil, err
}
dd := a.NewDDecimal(parser.DDecimal{})
dd.Set(v)
return dd, nil
case ColumnType_STRING:
v, err := value.GetBytes()
if err != nil {
return nil, err
}
return a.NewDString(parser.DString(v)), nil
case ColumnType_BYTES:
v, err := value.GetBytes()
if err != nil {
return nil, err
}
return a.NewDBytes(parser.DBytes(v)), nil
case ColumnType_DATE:
v, err := value.GetInt()
if err != nil {
return nil, err
}
return a.NewDDate(parser.DDate(v)), nil
case ColumnType_TIMESTAMP:
v, err := value.GetTime()
if err != nil {
return nil, err
}
return a.NewDTimestamp(parser.DTimestamp{Time: v}), nil
case ColumnType_TIMESTAMPTZ:
v, err := value.GetTime()
if err != nil {
return nil, err
}
return a.NewDTimestampTZ(parser.DTimestampTZ{Time: v}), nil
case ColumnType_INTERVAL:
d, err := value.GetDuration()
if err != nil {
return nil, err
}
return a.NewDInterval(parser.DInterval{Duration: d}), nil
default:
return nil, util.Errorf("unsupported column type: %s", kind)
}
}
示例4: tryRangeIDKey
func tryRangeIDKey(kv engine.MVCCKeyValue) (string, error) {
if kv.Key.Timestamp != hlc.ZeroTimestamp {
return "", fmt.Errorf("range ID keys shouldn't have timestamps: %s", kv.Key)
}
_, _, suffix, _, err := keys.DecodeRangeIDKey(kv.Key.Key)
if err != nil {
return "", err
}
// All range ID keys are stored inline on the metadata.
var meta enginepb.MVCCMetadata
if err := meta.Unmarshal(kv.Value); err != nil {
return "", err
}
value := roachpb.Value{RawBytes: meta.RawBytes}
// Values encoded as protobufs set msg and continue outside the
// switch. Other types are handled inside the switch and return.
var msg proto.Message
switch {
case bytes.Equal(suffix, keys.LocalLeaseAppliedIndexSuffix):
fallthrough
case bytes.Equal(suffix, keys.LocalRaftAppliedIndexSuffix):
i, err := value.GetInt()
if err != nil {
return "", err
}
return strconv.FormatInt(i, 10), nil
case bytes.Equal(suffix, keys.LocalRangeFrozenStatusSuffix):
b, err := value.GetBool()
if err != nil {
return "", err
}
return strconv.FormatBool(b), nil
case bytes.Equal(suffix, keys.LocalAbortCacheSuffix):
msg = &roachpb.AbortCacheEntry{}
case bytes.Equal(suffix, keys.LocalRangeLastGCSuffix):
msg = &hlc.Timestamp{}
case bytes.Equal(suffix, keys.LocalRaftTombstoneSuffix):
msg = &roachpb.RaftTombstone{}
case bytes.Equal(suffix, keys.LocalRaftTruncatedStateSuffix):
msg = &roachpb.RaftTruncatedState{}
case bytes.Equal(suffix, keys.LocalRangeLeaseSuffix):
msg = &roachpb.Lease{}
case bytes.Equal(suffix, keys.LocalRangeStatsSuffix):
msg = &enginepb.MVCCStats{}
case bytes.Equal(suffix, keys.LocalRaftHardStateSuffix):
msg = &raftpb.HardState{}
case bytes.Equal(suffix, keys.LocalRaftLastIndexSuffix):
i, err := value.GetInt()
if err != nil {
return "", err
}
return strconv.FormatInt(i, 10), nil
case bytes.Equal(suffix, keys.LocalRangeLastVerificationTimestampSuffix):
msg = &hlc.Timestamp{}
case bytes.Equal(suffix, keys.LocalRangeLastReplicaGCTimestampSuffix):
msg = &hlc.Timestamp{}
default:
return "", fmt.Errorf("unknown raft id key %s", suffix)
}
if err := value.GetProto(msg); err != nil {
return "", err
}
return msg.String(), nil
}