github.com/dolthub/go-mysql-server@v0.18.0/sql/rowexec/subqueryalias_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 rowexec
    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/expression"
    25  	"github.com/dolthub/go-mysql-server/sql/plan"
    26  	"github.com/dolthub/go-mysql-server/sql/types"
    27  )
    28  
    29  func TestSubqueryAliasSchema(t *testing.T) {
    30  	require := require.New(t)
    31  
    32  	db := memory.NewDatabase("test")
    33  
    34  	tableSchema := sql.NewPrimaryKeySchema(sql.Schema{
    35  		{Name: "foo", Type: types.Text, Nullable: false, Source: "bar"},
    36  		{Name: "baz", Type: types.Text, Nullable: false, Source: "bar"},
    37  	})
    38  
    39  	subquerySchema := sql.NewPrimaryKeySchema(sql.Schema{
    40  		{Name: "foo", Type: types.Text, Nullable: false, Source: "alias"},
    41  		{Name: "baz", Type: types.Text, Nullable: false, Source: "alias"},
    42  	})
    43  
    44  	table := memory.NewTable(db, "bar", tableSchema, nil)
    45  
    46  	subquery := plan.NewProject(
    47  		[]sql.Expression{
    48  			expression.NewGetField(0, types.Text, "foo", false),
    49  			expression.NewGetField(1, types.Text, "baz", false),
    50  		},
    51  		plan.NewResolvedTable(table, nil, nil),
    52  	)
    53  
    54  	require.Equal(
    55  		subquerySchema.Schema,
    56  		plan.NewSubqueryAlias("alias", "", subquery).Schema(),
    57  	)
    58  }