github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/auto_incr_test.go (about)

     1  // Copyright 2022 Matrix Origin
     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 colexec
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    21  	"github.com/matrixorigin/matrixone/pkg/container/types"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine"
    23  	"github.com/smartystreets/goconvey/convey"
    24  )
    25  
    26  func Test_makeAutoIncrBatch(t *testing.T) {
    27  	mp := mpool.MustNewZero()
    28  	convey.Convey("Test makeAutoIncrBatch succ", t, func() {
    29  		name := "a"
    30  		num, step := 0, 1
    31  		bat := makeAutoIncrBatch(name, uint64(num), uint64(step), mp)
    32  		convey.So(bat.Attrs, convey.ShouldResemble, AUTO_INCR_TABLE_COLNAME[1:])
    33  		convey.So(len(bat.Vecs), convey.ShouldEqual, 3)
    34  		convey.So(bat.Vecs[1].Col, convey.ShouldResemble, []uint64{uint64(num)})
    35  		convey.So(bat.Vecs[2].Col, convey.ShouldResemble, []uint64{uint64(step)})
    36  	})
    37  }
    38  
    39  func Test_getAutoIncrTableDef(t *testing.T) {
    40  	convey.Convey("Test getAutoIncrTableDef succ", t, func() {
    41  		def := getAutoIncrTableDef()
    42  		convey.So(len(def), convey.ShouldEqual, 4)
    43  		nameAttr, ok := def[0].(*engine.AttributeDef)
    44  		convey.So(ok, convey.ShouldBeTrue)
    45  		convey.So(nameAttr.Attr.Name, convey.ShouldEqual, AUTO_INCR_TABLE_COLNAME[1])
    46  		convey.So(nameAttr.Attr.Type, convey.ShouldResemble, types.T_varchar.ToType())
    47  		convey.So(nameAttr.Attr.Primary, convey.ShouldBeTrue)
    48  
    49  		numAttr, ok := def[1].(*engine.AttributeDef)
    50  		convey.So(ok, convey.ShouldBeTrue)
    51  		convey.So(numAttr.Attr.Name, convey.ShouldEqual, AUTO_INCR_TABLE_COLNAME[2])
    52  		convey.So(numAttr.Attr.Type, convey.ShouldResemble, types.T_uint64.ToType())
    53  		convey.So(numAttr.Attr.Primary, convey.ShouldBeFalse)
    54  
    55  		stepAttr, ok := def[2].(*engine.AttributeDef)
    56  		convey.So(ok, convey.ShouldBeTrue)
    57  		convey.So(stepAttr.Attr.Name, convey.ShouldEqual, AUTO_INCR_TABLE_COLNAME[3])
    58  		convey.So(stepAttr.Attr.Type, convey.ShouldResemble, types.T_uint64.ToType())
    59  		convey.So(stepAttr.Attr.Primary, convey.ShouldBeFalse)
    60  
    61  		constraint, ok := def[3].(*engine.ConstraintDef)
    62  		convey.So(ok, convey.ShouldBeTrue)
    63  		pkeyDef := constraint.GetPrimaryKeyDef()
    64  		convey.So(pkeyDef.Pkey.Names, convey.ShouldResemble, []string{AUTO_INCR_TABLE_COLNAME[1]})
    65  	})
    66  }