github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/acyclic/causet/memo/pattern_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package memo 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 causetembedded "github.com/whtcorpsinc/milevadb/causet/embedded" 19 ) 20 21 func (s *testMemoSuite) TestGetOperand(c *C) { 22 c.Assert(GetOperand(&causetembedded.LogicalJoin{}), Equals, OperandJoin) 23 c.Assert(GetOperand(&causetembedded.LogicalAggregation{}), Equals, OperanPosetDaggregation) 24 c.Assert(GetOperand(&causetembedded.LogicalProjection{}), Equals, OperandProjection) 25 c.Assert(GetOperand(&causetembedded.LogicalSelection{}), Equals, OperandSelection) 26 c.Assert(GetOperand(&causetembedded.LogicalApply{}), Equals, OperandApply) 27 c.Assert(GetOperand(&causetembedded.LogicalMaxOneRow{}), Equals, OperandMaxOneRow) 28 c.Assert(GetOperand(&causetembedded.LogicalBlockDual{}), Equals, OperandBlockDual) 29 c.Assert(GetOperand(&causetembedded.DataSource{}), Equals, OperandDataSource) 30 c.Assert(GetOperand(&causetembedded.LogicalUnionScan{}), Equals, OperandUnionScan) 31 c.Assert(GetOperand(&causetembedded.LogicalUnionAll{}), Equals, OperandUnionAll) 32 c.Assert(GetOperand(&causetembedded.LogicalSort{}), Equals, OperandSort) 33 c.Assert(GetOperand(&causetembedded.LogicalTopN{}), Equals, OperandTopN) 34 c.Assert(GetOperand(&causetembedded.LogicalLock{}), Equals, OperandLock) 35 c.Assert(GetOperand(&causetembedded.LogicalLimit{}), Equals, OperandLimit) 36 } 37 38 func (s *testMemoSuite) TestOperandMatch(c *C) { 39 c.Assert(OperandAny.Match(OperandLimit), IsTrue) 40 c.Assert(OperandAny.Match(OperandSelection), IsTrue) 41 c.Assert(OperandAny.Match(OperandJoin), IsTrue) 42 c.Assert(OperandAny.Match(OperandMaxOneRow), IsTrue) 43 c.Assert(OperandAny.Match(OperandAny), IsTrue) 44 45 c.Assert(OperandLimit.Match(OperandAny), IsTrue) 46 c.Assert(OperandSelection.Match(OperandAny), IsTrue) 47 c.Assert(OperandJoin.Match(OperandAny), IsTrue) 48 c.Assert(OperandMaxOneRow.Match(OperandAny), IsTrue) 49 c.Assert(OperandAny.Match(OperandAny), IsTrue) 50 51 c.Assert(OperandLimit.Match(OperandLimit), IsTrue) 52 c.Assert(OperandSelection.Match(OperandSelection), IsTrue) 53 c.Assert(OperandJoin.Match(OperandJoin), IsTrue) 54 c.Assert(OperandMaxOneRow.Match(OperandMaxOneRow), IsTrue) 55 c.Assert(OperandAny.Match(OperandAny), IsTrue) 56 57 c.Assert(OperandLimit.Match(OperandSelection), IsFalse) 58 c.Assert(OperandLimit.Match(OperandJoin), IsFalse) 59 c.Assert(OperandLimit.Match(OperandMaxOneRow), IsFalse) 60 } 61 62 func (s *testMemoSuite) TestNewPattern(c *C) { 63 p := NewPattern(OperandAny, EngineAll) 64 c.Assert(p.Operand, Equals, OperandAny) 65 c.Assert(p.Children, IsNil) 66 67 p = NewPattern(OperandJoin, EngineAll) 68 c.Assert(p.Operand, Equals, OperandJoin) 69 c.Assert(p.Children, IsNil) 70 } 71 72 func (s *testMemoSuite) TestPatternSetChildren(c *C) { 73 p := NewPattern(OperandAny, EngineAll) 74 p.SetChildren(NewPattern(OperandLimit, EngineAll)) 75 c.Assert(len(p.Children), Equals, 1) 76 c.Assert(p.Children[0].Operand, Equals, OperandLimit) 77 c.Assert(p.Children[0].Children, IsNil) 78 79 p = NewPattern(OperandJoin, EngineAll) 80 p.SetChildren(NewPattern(OperandProjection, EngineAll), NewPattern(OperandSelection, EngineAll)) 81 c.Assert(len(p.Children), Equals, 2) 82 c.Assert(p.Children[0].Operand, Equals, OperandProjection) 83 c.Assert(p.Children[0].Children, IsNil) 84 c.Assert(p.Children[1].Operand, Equals, OperandSelection) 85 c.Assert(p.Children[1].Children, IsNil) 86 }