github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/table_function/table_function_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 table_function
    16  
    17  import (
    18  	"bytes"
    19  	"testing"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/testutil"
    22  	"github.com/matrixorigin/matrixone/pkg/vm"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestString(t *testing.T) {
    27  	arg := Argument{FuncName: "unnest"}
    28  	arg.String(bytes.NewBuffer(nil))
    29  }
    30  
    31  func TestCall(t *testing.T) {
    32  	arg := Argument{FuncName: "unnest",
    33  		OperatorBase: vm.OperatorBase{
    34  			OperatorInfo: vm.OperatorInfo{
    35  				Idx:     0,
    36  				IsFirst: false,
    37  				IsLast:  false,
    38  			},
    39  		},
    40  	}
    41  
    42  	resetChildren(&arg, nil)
    43  	end, err := arg.Call(testutil.NewProc())
    44  	require.NoError(t, err)
    45  	require.True(t, end.Status == vm.ExecStop)
    46  	// arg.Name = "generate_series"
    47  	// end, err = arg.Call(testutil.NewProc())
    48  	// require.NoError(t, err)
    49  	require.True(t, end.Status == vm.ExecStop)
    50  	arg.FuncName = "metadata_scan"
    51  	end, err = arg.Call(testutil.NewProc())
    52  	require.NoError(t, err)
    53  	require.True(t, end.Status == vm.ExecStop)
    54  	arg.FuncName = "not_exist"
    55  	end, err = arg.Call(testutil.NewProc())
    56  	require.Error(t, err)
    57  	require.True(t, end.Status == vm.ExecStop)
    58  }
    59  
    60  func TestPrepare(t *testing.T) {
    61  	arg := Argument{FuncName: "unnest",
    62  		OperatorBase: vm.OperatorBase{
    63  			OperatorInfo: vm.OperatorInfo{
    64  				Idx:     0,
    65  				IsFirst: false,
    66  				IsLast:  false,
    67  			},
    68  		},
    69  	}
    70  	err := arg.Prepare(testutil.NewProc())
    71  	require.Error(t, err)
    72  	arg.FuncName = "generate_series"
    73  	err = arg.Prepare(testutil.NewProc())
    74  	require.NoError(t, err)
    75  	arg.FuncName = "metadata_scan"
    76  	err = arg.Prepare(testutil.NewProc())
    77  	require.NoError(t, err)
    78  	arg.FuncName = "not_exist"
    79  	err = arg.Prepare(testutil.NewProc())
    80  	require.Error(t, err)
    81  }