github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/s3util_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  package colexec
    15  
    16  import (
    17  	"context"
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/batch"
    21  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    22  	"github.com/matrixorigin/matrixone/pkg/testutil"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestSortKey(t *testing.T) {
    27  	proc := testutil.NewProc()
    28  	proc.Ctx = context.TODO()
    29  	batch1 := &batch.Batch{
    30  		Attrs: []string{"a"},
    31  		Vecs: []*vector.Vector{
    32  			testutil.MakeUint16Vector([]uint16{1, 2, 0}, nil),
    33  		},
    34  	}
    35  	batch1.SetRowCount(3)
    36  	err := sortByKey(proc, batch1, 0, false, proc.GetMPool())
    37  	require.NoError(t, err)
    38  	cols := vector.ExpandFixedCol[uint16](batch1.Vecs[0])
    39  	for i := range cols {
    40  		require.Equal(t, int(cols[i]), i)
    41  	}
    42  
    43  	batch2 := &batch.Batch{
    44  		Attrs: []string{"a"},
    45  		Vecs: []*vector.Vector{
    46  			testutil.MakeTextVector([]string{"b", "a", "c"}, nil),
    47  		},
    48  	}
    49  	batch2.SetRowCount(3)
    50  	res := []string{"a", "b", "c"}
    51  	err = sortByKey(proc, batch2, 0, false, proc.GetMPool())
    52  	require.NoError(t, err)
    53  	cols2 := vector.ExpandStrCol(batch2.Vecs[0])
    54  	for i := range cols {
    55  		require.Equal(t, cols2[i], res[i])
    56  	}
    57  }