当前位置: 首页>>代码示例>>Golang>>正文


Golang Datum.SetNull方法代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Datum.SetNull方法的典型用法代码示例。如果您正苦于以下问题:Golang Datum.SetNull方法的具体用法?Golang Datum.SetNull怎么用?Golang Datum.SetNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pingcap/tidb/util/types.Datum的用法示例。


在下文中一共展示了Datum.SetNull方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestEvalCoalesce

func (s *testEvalSuite) TestEvalCoalesce(c *C) {
	colID := int64(1)
	row := make(map[int64]types.Datum)
	row[colID] = types.NewIntDatum(100)
	xevaluator := &Evaluator{Row: row}
	nullDatum := types.Datum{}
	nullDatum.SetNull()
	notNullDatum := types.NewStringDatum("not-null")
	cases := []struct {
		expr   *tipb.Expr
		result types.Datum
	}{
		{
			expr:   buildExpr(tipb.ExprType_Coalesce, nullDatum, nullDatum, nullDatum),
			result: nullDatum,
		},
		{
			expr:   buildExpr(tipb.ExprType_Coalesce, nullDatum, notNullDatum, nullDatum),
			result: notNullDatum,
		},
		{
			expr:   buildExpr(tipb.ExprType_Coalesce, nullDatum, notNullDatum, types.NewStringDatum("not-null-2"), nullDatum),
			result: notNullDatum,
		},
	}
	for _, ca := range cases {
		result, err := xevaluator.Eval(ca.expr)
		c.Assert(err, IsNil)
		c.Assert(result.Kind(), Equals, ca.result.Kind())
		cmp, err := result.CompareDatum(xevaluator.sc, ca.result)
		c.Assert(err, IsNil)
		c.Assert(cmp, Equals, 0)
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:34,代码来源:eval_other_funcs_test.go

示例2: evalXor

// evalXor computes result of (X XOR Y).
func (e *Evaluator) evalXor(leftBool, rightBool int64) (types.Datum, error) {
	var d types.Datum
	if leftBool == compareResultNull || rightBool == compareResultNull {
		d.SetNull()
		return d, nil
	}
	if leftBool == rightBool {
		d.SetInt64(0)
		return d, nil
	}
	d.SetInt64(1)
	return d, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:14,代码来源:eval_logic_ops.go

示例3: evalOr

func (e *Evaluator) evalOr(expr *tipb.Expr) (types.Datum, error) {
	leftBool, rightBool, err := e.evalTwoBoolChildren(expr)
	if err != nil {
		return types.Datum{}, errors.Trace(err)
	}
	var d types.Datum
	if leftBool == 1 || rightBool == 1 {
		d.SetInt64(1)
		return d, nil
	}
	if leftBool == compareResultNull || rightBool == compareResultNull {
		d.SetNull()
		return d, nil
	}
	d.SetInt64(0)
	return d, nil
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:17,代码来源:eval.go

示例4: builtinStrToDate

// See https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
func builtinStrToDate(args []types.Datum, _ context.Context) (types.Datum, error) {
	date := args[0].GetString()
	format := args[1].GetString()
	var (
		d types.Datum
		t types.Time
	)

	succ := t.StrToDate(date, format)
	if !succ {
		d.SetNull()
		return d, nil
	}

	d.SetMysqlTime(t)
	return d, nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:18,代码来源:builtin_time.go

示例5: TestEvalCaseWhen

func (s *testEvalSuite) TestEvalCaseWhen(c *C) {
	colID := int64(1)
	xevaluator := NewEvaluator(new(variable.StatementContext))
	xevaluator.Row[colID] = types.NewIntDatum(100)
	trueCond := types.NewIntDatum(1)
	falseCond := types.NewIntDatum(0)
	nullCond := types.Datum{}
	nullCond.SetNull()
	cases := []struct {
		expr   *tipb.Expr
		result types.Datum
	}{
		{
			expr: buildExpr(tipb.ExprType_Case,
				falseCond, types.NewStringDatum("case1"),
				trueCond, types.NewStringDatum("case2"),
				trueCond, types.NewStringDatum("case3")),
			result: types.NewStringDatum("case2"),
		},
		{
			expr: buildExpr(tipb.ExprType_Case,
				falseCond, types.NewStringDatum("case1"),
				falseCond, types.NewStringDatum("case2"),
				falseCond, types.NewStringDatum("case3"),
				types.NewStringDatum("Else")),
			result: types.NewStringDatum("Else"),
		},
		{
			expr: buildExpr(tipb.ExprType_Case,
				falseCond, types.NewStringDatum("case1"),
				falseCond, types.NewStringDatum("case2"),
				falseCond, types.NewStringDatum("case3")),
			result: types.Datum{},
		},
		{
			expr: buildExpr(tipb.ExprType_Case,
				buildExpr(tipb.ExprType_Case,
					falseCond, types.NewIntDatum(0),
					trueCond, types.NewIntDatum(1),
				), types.NewStringDatum("nested case when"),
				falseCond, types.NewStringDatum("case1"),
				trueCond, types.NewStringDatum("case2"),
				trueCond, types.NewStringDatum("case3")),
			result: types.NewStringDatum("nested case when"),
		},
		{
			expr: buildExpr(tipb.ExprType_Case,
				nullCond, types.NewStringDatum("case1"),
				falseCond, types.NewStringDatum("case2"),
				trueCond, types.NewStringDatum("case3")),
			result: types.NewStringDatum("case3"),
		},
	}
	for _, ca := range cases {
		result, err := xevaluator.Eval(ca.expr)
		c.Assert(err, IsNil)
		c.Assert(result.Kind(), Equals, ca.result.Kind())
		cmp, err := result.CompareDatum(xevaluator.sc, ca.result)
		c.Assert(err, IsNil)
		c.Assert(cmp, Equals, 0)
	}
}
开发者ID:pingcap,项目名称:tidb,代码行数:62,代码来源:eval_control_funcs_test.go


注:本文中的github.com/pingcap/tidb/util/types.Datum.SetNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。