github.com/dolthub/go-mysql-server@v0.18.0/sql/analyzer/process_test.go (about) 1 // Copyright 2020-2021 Dolthub, 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package analyzer 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 22 "github.com/dolthub/go-mysql-server/memory" 23 "github.com/dolthub/go-mysql-server/sql" 24 "github.com/dolthub/go-mysql-server/sql/plan" 25 ) 26 27 func TestTrackProcessSubquery(t *testing.T) { 28 require := require.New(t) 29 rule := getRuleFrom(OnceAfterAll, TrackProcessId) 30 a := NewDefault(sql.NewDatabaseProvider()) 31 32 db := memory.NewDatabase("db") 33 pro := memory.NewDBProvider(db) 34 ctx := newContext(pro) 35 36 node := plan.NewProject( 37 nil, 38 plan.NewSubqueryAlias("f", "", 39 plan.NewQueryProcess( 40 plan.NewResolvedTable(memory.NewTable(db, "foo", sql.PrimaryKeySchema{}, nil), nil, nil), 41 nil, 42 ), 43 ), 44 ) 45 46 result, _, err := rule.Apply(ctx, a, node, nil, DefaultRuleSelector) 47 require.NoError(err) 48 49 expectedChild := plan.NewProject( 50 nil, 51 plan.NewSubqueryAlias("f", "", 52 plan.NewResolvedTable(memory.NewTable(db, "foo", sql.PrimaryKeySchema{}, nil), nil, nil), 53 ), 54 ) 55 56 proc, ok := result.(*plan.QueryProcess) 57 require.True(ok) 58 require.Equal(expectedChild, proc.Child()) 59 } 60 61 // wrapper around sql.Table to make it not indexable 62 type table struct { 63 sql.Table 64 } 65 66 var _ sql.PartitionCounter = (*table)(nil) 67 68 func (t *table) PartitionCount(ctx *sql.Context) (int64, error) { 69 return t.Table.(sql.PartitionCounter).PartitionCount(ctx) 70 }