github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/ctl/mo_log_date_test.go (about)

     1  // Copyright 2021 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 ctl
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    19  	"github.com/matrixorigin/matrixone/pkg/testutil"
    20  	"github.com/smartystreets/goconvey/convey"
    21  	"github.com/stretchr/testify/require"
    22  	"testing"
    23  )
    24  
    25  func TestMOLogDate(t *testing.T) {
    26  	convey.Convey("MO_LOG_DATE() with multi line", t, func() {
    27  		cases := []struct {
    28  			dateStr string
    29  			expect  string
    30  			isNull  bool
    31  		}{
    32  			{
    33  				dateStr: "2004/04/30",
    34  				expect:  "2004-04-30",
    35  			},
    36  			{
    37  				dateStr: "2012/05/31",
    38  				expect:  "2012-05-31",
    39  			},
    40  			{
    41  				dateStr: "2009/04/23",
    42  				expect:  "2009-04-23",
    43  			},
    44  			{
    45  				dateStr: "2004/01/31",
    46  				expect:  "2004-01-31",
    47  			},
    48  			{
    49  				dateStr: "2018/07/03",
    50  				expect:  "2018-07-03",
    51  			},
    52  			{
    53  				dateStr: "2014/08/25",
    54  				expect:  "2014-08-25",
    55  			},
    56  			{
    57  				dateStr: "2022/06/30",
    58  				expect:  "2022-06-30",
    59  			},
    60  			{
    61  				dateStr: "etl:/i/am/not/include/date/string",
    62  				expect:  ZeroDate,
    63  				isNull:  true,
    64  			},
    65  			{
    66  				dateStr: "etl:/sys/logs/2023/02/03/system.metric/filename",
    67  				expect:  "2023-02-03",
    68  			},
    69  		}
    70  
    71  		var datestrs []string
    72  		var expects []string
    73  		var resultNil []uint64
    74  		for idx, c := range cases {
    75  			datestrs = append(datestrs, c.dateStr)
    76  			expects = append(expects, c.expect)
    77  			if c.isNull {
    78  				resultNil = append(resultNil, uint64(idx))
    79  			}
    80  		}
    81  
    82  		datestrVector := testutil.MakeVarcharVector(datestrs, nil)
    83  		expectVector := testutil.MakeDateVector(expects, resultNil)
    84  
    85  		proc := testutil.NewProc()
    86  		result, err := MOLogDate([]*vector.Vector{datestrVector}, proc)
    87  		require.Nil(t, err)
    88  
    89  		compare := testutil.CompareVectors(expectVector, result)
    90  		require.True(t, compare)
    91  	})
    92  }