本文整理匯總了Golang中github.com/pingcap/tidb/util/types.Datum.GetValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Datum.GetValue方法的具體用法?Golang Datum.GetValue怎麽用?Golang Datum.GetValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/util/types.Datum
的用法示例。
在下文中一共展示了Datum.GetValue方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateFirst
func (n *finalAggregater) updateFirst(val types.Datum) error {
ctx := n.getContext()
if ctx.Evaluated {
return nil
}
ctx.Value = val.GetValue()
ctx.Evaluated = true
return nil
}
示例2: updateSum
func (n *finalAggregater) updateSum(val types.Datum, count uint64) error {
ctx := n.getContext()
if val.IsNull() {
return nil
}
var err error
ctx.Value, err = types.CalculateSum(ctx.Value, val.GetValue())
if err != nil {
return errors.Trace(err)
}
ctx.Count += int64(count)
return nil
}
示例3: computeMul
func computeMul(a, b types.Datum) (d types.Datum, err error) {
switch a.Kind() {
case types.KindInt64:
switch b.Kind() {
case types.KindInt64:
r, err1 := types.MulInt64(a.GetInt64(), b.GetInt64())
d.SetInt64(r)
return d, errors.Trace(err1)
case types.KindUint64:
r, err1 := types.MulInteger(b.GetUint64(), a.GetInt64())
d.SetUint64(r)
return d, errors.Trace(err1)
}
case types.KindUint64:
switch b.Kind() {
case types.KindInt64:
r, err1 := types.MulInteger(a.GetUint64(), b.GetInt64())
d.SetUint64(r)
return d, errors.Trace(err1)
case types.KindUint64:
r, err1 := types.MulUint64(a.GetUint64(), b.GetUint64())
d.SetUint64(r)
return d, errors.Trace(err1)
}
case types.KindFloat64:
switch b.Kind() {
case types.KindFloat64:
r := a.GetFloat64() * b.GetFloat64()
d.SetFloat64(r)
return d, nil
}
case types.KindMysqlDecimal:
switch b.Kind() {
case types.KindMysqlDecimal:
r := a.GetMysqlDecimal().Mul(b.GetMysqlDecimal())
d.SetMysqlDecimal(r)
return d, nil
}
}
_, err = types.InvOp2(a.GetValue(), b.GetValue(), opcode.Mul)
return d, errors.Trace(err)
}
示例4: computeMinus
func computeMinus(a, b types.Datum) (d types.Datum, err error) {
switch a.Kind() {
case types.KindInt64:
switch b.Kind() {
case types.KindInt64:
r, err1 := types.SubInt64(a.GetInt64(), b.GetInt64())
d.SetInt64(r)
return d, errors.Trace(err1)
case types.KindUint64:
r, err1 := types.SubIntWithUint(a.GetInt64(), b.GetUint64())
d.SetUint64(r)
return d, errors.Trace(err1)
}
case types.KindUint64:
switch b.Kind() {
case types.KindInt64:
r, err1 := types.SubUintWithInt(a.GetUint64(), b.GetInt64())
d.SetUint64(r)
return d, errors.Trace(err1)
case types.KindUint64:
r, err1 := types.SubUint64(a.GetUint64(), b.GetUint64())
d.SetUint64(r)
return d, errors.Trace(err1)
}
case types.KindFloat64:
switch b.Kind() {
case types.KindFloat64:
r := a.GetFloat64() - b.GetFloat64()
d.SetFloat64(r)
return d, nil
}
case types.KindMysqlDecimal:
switch b.Kind() {
case types.KindMysqlDecimal:
r := a.GetMysqlDecimal().Sub(b.GetMysqlDecimal())
d.SetMysqlDecimal(r)
return d, nil
}
}
_, err = types.InvOp2(a.GetValue(), b.GetValue(), opcode.Minus)
return d, errors.Trace(err)
}
示例5: computeMod
func computeMod(a, b types.Datum) (d types.Datum, err error) {
switch a.Kind() {
case types.KindInt64:
x := a.GetInt64()
switch b.Kind() {
case types.KindInt64:
y := b.GetInt64()
if y == 0 {
return d, nil
}
d.SetInt64(x % y)
return d, nil
case types.KindUint64:
y := b.GetUint64()
if y == 0 {
return d, nil
} else if x < 0 {
d.SetInt64(-int64(uint64(-x) % y))
// first is int64, return int64.
return d, nil
}
d.SetInt64(int64(uint64(x) % y))
return d, nil
}
case types.KindUint64:
x := a.GetUint64()
switch b.Kind() {
case types.KindInt64:
y := b.GetInt64()
if y == 0 {
return d, nil
} else if y < 0 {
// first is uint64, return uint64.
d.SetUint64(uint64(x % uint64(-y)))
return d, nil
}
d.SetUint64(x % uint64(y))
return d, nil
case types.KindUint64:
y := b.GetUint64()
if y == 0 {
return d, nil
}
d.SetUint64(x % y)
return d, nil
}
case types.KindFloat64:
x := a.GetFloat64()
switch b.Kind() {
case types.KindFloat64:
y := b.GetFloat64()
if y == 0 {
return d, nil
}
d.SetFloat64(math.Mod(x, y))
return d, nil
}
case types.KindMysqlDecimal:
x := a.GetMysqlDecimal()
switch b.Kind() {
case types.KindMysqlDecimal:
y := b.GetMysqlDecimal()
xf, _ := x.Float64()
yf, _ := y.Float64()
if yf == 0 {
return d, nil
}
d.SetFloat64(math.Mod(xf, yf))
return d, nil
}
}
_, err = types.InvOp2(a.GetValue(), b.GetValue(), opcode.Mod)
return d, errors.Trace(err)
}
示例6: convertDateFormat
//.........這裏部分代碼省略.........
}
case 'p':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() < 12 {
d.SetString("AM")
break
}
d.SetString("PM")
}
case 'r':
d, err = to12Hour(arg, ctx)
case 'T':
d, err = builtinTime([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
duration := types.Duration{
Duration: d.GetMysqlDuration().Duration,
Fsp: 0}
d.SetMysqlDuration(duration)
}
case 'S', 's':
d, err = builtinSecond([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'f':
d, err = builtinMicroSecond([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%06d", d.GetInt64()))
}
case 'U':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(0)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'u':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(1)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'V':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(2)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'v':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(3)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'a':
d, err = builtinDayName([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(d.GetString()[:3])
}
case 'W':
d, err = builtinDayName([]types.Datum{arg}, ctx)
case 'w':
d, err = builtinDayOfWeek([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetInt64(d.GetInt64() - 1)
}
case 'X':
d, err = builtinYearWeek([]types.Datum{arg, types.NewIntDatum(2)}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() == math.MaxUint32 {
break
}
str := fmt.Sprintf("%04d", d.GetInt64())
d.SetString(fmt.Sprintf("%04s", str[:4]))
}
case 'x':
d, err = builtinYearWeek([]types.Datum{arg, types.NewIntDatum(3)}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() == math.MaxUint32 {
break
}
str := fmt.Sprintf("%04d", d.GetInt64())
d.SetString(fmt.Sprintf("%04s", str[:4]))
}
case 'Y':
d, err = builtinYear([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%04d", d.GetInt64()))
}
case 'y':
d, err = builtinYear([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
str := fmt.Sprintf("%04d", d.GetInt64())
d.SetString(fmt.Sprintf("%02s", str[2:]))
}
default:
d.SetString(string(b))
}
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%v", d.GetValue()))
}
return d, errors.Trace(err)
}