github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/acyclic/causet/cascades/stringer_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 cascades 15 16 import ( 17 "context" 18 19 "github.com/whtcorpsinc/BerolinaSQL" 20 "github.com/whtcorpsinc/BerolinaSQL/perceptron" 21 . "github.com/whtcorpsinc/check" 22 causetembedded "github.com/whtcorpsinc/milevadb/causet/embedded" 23 "github.com/whtcorpsinc/milevadb/causet/memo" 24 "github.com/whtcorpsinc/milevadb/schemareplicant" 25 "github.com/whtcorpsinc/milevadb/soliton/solitonutil" 26 "github.com/whtcorpsinc/milevadb/stochastikctx" 27 ) 28 29 var _ = Suite(&testStringerSuite{}) 30 31 type testStringerSuite struct { 32 *BerolinaSQL.BerolinaSQL 33 is schemareplicant.SchemaReplicant 34 sctx stochastikctx.Context 35 testData solitonutil.TestData 36 optimizer *Optimizer 37 } 38 39 func (s *testStringerSuite) SetUpSuite(c *C) { 40 s.is = schemareplicant.MockSchemaReplicant([]*perceptron.BlockInfo{causetembedded.MockSignedBlock()}) 41 s.sctx = causetembedded.MockContext() 42 s.BerolinaSQL = BerolinaSQL.New() 43 s.optimizer = NewOptimizer() 44 var err error 45 s.testData, err = solitonutil.LoadTestSuiteData("testdata", "stringer_suite") 46 c.Assert(err, IsNil) 47 } 48 49 func (s *testStringerSuite) TearDownSuite(c *C) { 50 c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil) 51 } 52 53 func (s *testStringerSuite) TestGroupStringer(c *C) { 54 s.optimizer.ResetTransformationMemrules(map[memo.Operand][]Transformation{ 55 memo.OperandSelection: { 56 NewMemrulePushSelDownEinsteinDBSingleGather(), 57 NewMemrulePushSelDownBlockScan(), 58 }, 59 memo.OperandDataSource: { 60 NewMemruleEnumeratePaths(), 61 }, 62 }) 63 defer func() { 64 s.optimizer.ResetTransformationMemrules(DefaultMemruleBatches...) 65 }() 66 var input []string 67 var output []struct { 68 ALLEGROALLEGROSQL string 69 Result []string 70 } 71 s.testData.GetTestCases(c, &input, &output) 72 for i, allegrosql := range input { 73 stmt, err := s.ParseOneStmt(allegrosql, "", "") 74 c.Assert(err, IsNil) 75 p, _, err := causetembedded.BuildLogicalCauset(context.Background(), s.sctx, stmt, s.is) 76 c.Assert(err, IsNil) 77 logic, ok := p.(causetembedded.LogicalCauset) 78 c.Assert(ok, IsTrue) 79 logic, err = s.optimizer.onPhasePreprocessing(s.sctx, logic) 80 c.Assert(err, IsNil) 81 group := memo.Convert2Group(logic) 82 err = s.optimizer.onPhaseExploration(s.sctx, group) 83 c.Assert(err, IsNil) 84 group.BuildKeyInfo() 85 s.testData.OnRecord(func() { 86 output[i].ALLEGROALLEGROSQL = allegrosql 87 output[i].Result = ToString(group) 88 }) 89 c.Assert(ToString(group), DeepEquals, output[i].Result) 90 } 91 }