當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。