當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Recordset.Plan方法代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/rset/rsets.Recordset.Plan方法的典型用法代碼示例。如果您正苦於以下問題:Golang Recordset.Plan方法的具體用法?Golang Recordset.Plan怎麽用?Golang Recordset.Plan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/pingcap/tidb/rset/rsets.Recordset的用法示例。


在下文中一共展示了Recordset.Plan方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestJoin

func (s *testJoinSuit) TestJoin(c *C) {
	s.cols = []*column.Col{
		{
			ColumnInfo: model.ColumnInfo{
				ID:           0,
				Name:         model.NewCIStr("id"),
				Offset:       0,
				DefaultValue: 0,
				FieldType:    *types.NewFieldType(mysql.TypeLonglong),
			},
		},
		{
			ColumnInfo: model.ColumnInfo{
				ID:           1,
				Name:         model.NewCIStr("name"),
				Offset:       1,
				DefaultValue: nil,
				FieldType:    *types.NewFieldType(mysql.TypeVarchar),
			},
		},
	}

	var testData1 = []*testRowData{
		{1, []interface{}{10, "10"}},
		{2, []interface{}{10, "20"}},
		{3, []interface{}{10, "30"}},
		{4, []interface{}{40, "40"}},
		{6, []interface{}{60, "60"}},
	}

	var testData2 = []*testRowData{
		{1, []interface{}{10, "10"}},
		{2, []interface{}{10, "20"}},
		{3, []interface{}{10, "30"}},
		{4, []interface{}{40, "40"}},
		{6, []interface{}{60, "60"}},
	}

	tblPlan1 := &testTablePlan{testData1, []string{"id", "name"}, 0}
	tblPlan2 := &testTablePlan{testData2, []string{"id", "name"}, 0}

	joinPlan := &plans.JoinPlan{
		Left:   tblPlan1,
		Right:  tblPlan2,
		Type:   "CROSS",
		Fields: []*field.ResultField{},
		On:     expression.Value{Val: true},
	}
	rset := rsets.Recordset{
		Plan: joinPlan,
		Ctx:  mock.NewContext()}

	rset.Do(func(data []interface{}) (bool, error) {
		return true, nil
	})
	tblPlan1.Close()
	tblPlan2.Close()
	rset.Plan = &plans.JoinPlan{
		Left:   tblPlan1,
		Right:  tblPlan2,
		Type:   "LEFT",
		Fields: []*field.ResultField{},
		On:     expression.Value{Val: true},
	}
	rset.Do(func(data []interface{}) (bool, error) {
		return true, nil
	})
	tblPlan1.Close()
	tblPlan2.Close()
	joinPlan = &plans.JoinPlan{
		Left:   tblPlan1,
		Right:  tblPlan2,
		Type:   "RIGHT",
		Fields: []*field.ResultField{},
		On:     expression.Value{Val: true},
	}

	expr := &expression.BinaryOperation{
		Op: opcode.LT,
		L: &expression.Ident{
			CIStr: model.NewCIStr("id"),
		},
		R: expression.Value{
			Val: 100,
		},
	}
	np, _, err := joinPlan.Filter(nil, expr)
	c.Assert(np, NotNil)
	c.Assert(err, IsNil)
	rset.Plan = joinPlan
	rset.Do(func(data []interface{}) (bool, error) {
		return true, nil
	})
	tblPlan1.Close()
	tblPlan2.Close()
	rset.Plan = &plans.JoinPlan{
		Left:   tblPlan1,
		Right:  tblPlan2,
		Type:   "FULL",
		Fields: []*field.ResultField{},
//.........這裏部分代碼省略.........
開發者ID:lovedboy,項目名稱:tidb,代碼行數:101,代碼來源:join_test.go

示例2: TestDefaultFieldsPlan

func (s *testFieldsSuit) TestDefaultFieldsPlan(c *C) {
	tblPlan := &testTablePlan{selectFieldsTestData, []string{"id", "name"}, 0}

	sl1 := &plans.SelectList{
		Fields: []*field.Field{
			{
				Expr: &expression.Ident{
					CIStr: model.NewCIStr("name"),
				},
			},
		},
	}

	selFieldsPlan := &plans.SelectFieldsDefaultPlan{
		SelectList: sl1,
		Src:        tblPlan,
	}
	rset := rsets.Recordset{
		Plan: selFieldsPlan,
		Ctx:  mock.NewContext(),
	}
	rset.Do(func(data []interface{}) (bool, error) {
		c.Assert(len(data), Equals, 1)
		c.Assert(data[0].(string), Equals, "hello")
		return true, nil
	})

	// test multiple fields
	sl2 := &plans.SelectList{
		Fields: []*field.Field{
			{
				Expr: &expression.Ident{
					CIStr: model.NewCIStr("name"),
				},
			},
			{
				Expr: &expression.Ident{
					CIStr: model.NewCIStr("id"),
				},
			},
		},
	}
	tblPlan.Close()
	rset.Plan = &plans.SelectFieldsDefaultPlan{
		SelectList: sl2,
		Src:        tblPlan,
	}

	rset.Do(func(data []interface{}) (bool, error) {
		c.Assert(len(data), Equals, 2)
		c.Assert(data[0].(string), Equals, "hello")
		c.Assert(data[1].(int), GreaterEqual, 10)
		return true, nil
	})

	// test field doesn't exists
	sl3 := &plans.SelectList{
		Fields: []*field.Field{
			{
				Expr: &expression.Ident{
					CIStr: model.NewCIStr("nosuchfield"),
				},
			},
		},
	}
	tblPlan.Close()
	rset.Plan = &plans.SelectFieldsDefaultPlan{
		SelectList: sl3,
		Src:        tblPlan,
	}
	err := rset.Do(func(data []interface{}) (bool, error) {
		return true, nil
	})
	c.Assert(err.Error() == "unknown field nosuchfield", Equals, true)
}
開發者ID:lovedboy,項目名稱:tidb,代碼行數:75,代碼來源:fields_test.go


注:本文中的github.com/pingcap/tidb/rset/rsets.Recordset.Plan方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。