github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/aggexec/singleNew.go (about)

     1  // Copyright 2024 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 aggexec
    16  
    17  import (
    18  	"fmt"
    19  	"github.com/matrixorigin/matrixone/pkg/container/types"
    20  )
    21  
    22  // all the codes in this file were to make the single column aggregation executor from agg information.
    23  
    24  func newSingleAggFuncExec1(
    25  	mg AggMemoryManager, info singleAggInfo, opt singleAggOptimizedInfo, impl aggImplementation) AggFuncExec {
    26  	switch info.retType.Oid {
    27  	case types.T_bool:
    28  		return newSingleAggFuncExec1WithKnownResultType[bool](mg, info, opt, impl)
    29  	case types.T_int8:
    30  		return newSingleAggFuncExec1WithKnownResultType[int8](mg, info, opt, impl)
    31  	case types.T_int16:
    32  		return newSingleAggFuncExec1WithKnownResultType[int16](mg, info, opt, impl)
    33  	case types.T_int32:
    34  		return newSingleAggFuncExec1WithKnownResultType[int32](mg, info, opt, impl)
    35  	case types.T_int64:
    36  		return newSingleAggFuncExec1WithKnownResultType[int64](mg, info, opt, impl)
    37  	case types.T_uint8:
    38  		return newSingleAggFuncExec1WithKnownResultType[uint8](mg, info, opt, impl)
    39  	case types.T_uint16:
    40  		return newSingleAggFuncExec1WithKnownResultType[uint16](mg, info, opt, impl)
    41  	case types.T_uint32:
    42  		return newSingleAggFuncExec1WithKnownResultType[uint32](mg, info, opt, impl)
    43  	case types.T_uint64:
    44  		return newSingleAggFuncExec1WithKnownResultType[uint64](mg, info, opt, impl)
    45  	case types.T_float32:
    46  		return newSingleAggFuncExec1WithKnownResultType[float32](mg, info, opt, impl)
    47  	case types.T_float64:
    48  		return newSingleAggFuncExec1WithKnownResultType[float64](mg, info, opt, impl)
    49  	case types.T_decimal64:
    50  		return newSingleAggFuncExec1WithKnownResultType[types.Decimal64](mg, info, opt, impl)
    51  	case types.T_decimal128:
    52  		return newSingleAggFuncExec1WithKnownResultType[types.Decimal128](mg, info, opt, impl)
    53  	case types.T_date:
    54  		return newSingleAggFuncExec1WithKnownResultType[types.Date](mg, info, opt, impl)
    55  	case types.T_datetime:
    56  		return newSingleAggFuncExec1WithKnownResultType[types.Datetime](mg, info, opt, impl)
    57  	case types.T_time:
    58  		return newSingleAggFuncExec1WithKnownResultType[types.Time](mg, info, opt, impl)
    59  	case types.T_timestamp:
    60  		return newSingleAggFuncExec1WithKnownResultType[types.Timestamp](mg, info, opt, impl)
    61  	case types.T_bit:
    62  		return newSingleAggFuncExec1WithKnownResultType[uint64](mg, info, opt, impl)
    63  	case types.T_TS:
    64  		return newSingleAggFuncExec1WithKnownResultType[types.TS](mg, info, opt, impl)
    65  	case types.T_Rowid:
    66  		return newSingleAggFuncExec1WithKnownResultType[types.Rowid](mg, info, opt, impl)
    67  	case types.T_Blockid:
    68  		return newSingleAggFuncExec1WithKnownResultType[types.Blockid](mg, info, opt, impl)
    69  	case types.T_uuid:
    70  		return newSingleAggFuncExec1WithKnownResultType[types.Uuid](mg, info, opt, impl)
    71  	}
    72  	panic(fmt.Sprintf("unsupported result type %s for singleAggFuncExec1", info.retType))
    73  }
    74  
    75  func newSingleAggFuncExec1WithKnownResultType[to types.FixedSizeTExceptStrType](
    76  	mg AggMemoryManager, info singleAggInfo, opt singleAggOptimizedInfo, impl aggImplementation) AggFuncExec {
    77  
    78  	switch info.argType.Oid {
    79  	case types.T_bool:
    80  		e := &singleAggFuncExec1[bool, to]{}
    81  		e.init(mg, info, opt, impl)
    82  		return e
    83  
    84  	case types.T_bit:
    85  		e := &singleAggFuncExec1[uint64, to]{}
    86  		e.init(mg, info, opt, impl)
    87  		return e
    88  
    89  	case types.T_int8:
    90  		e := &singleAggFuncExec1[int8, to]{}
    91  		e.init(mg, info, opt, impl)
    92  		return e
    93  
    94  	case types.T_int16:
    95  		e := &singleAggFuncExec1[int16, to]{}
    96  		e.init(mg, info, opt, impl)
    97  		return e
    98  
    99  	case types.T_int32:
   100  		e := &singleAggFuncExec1[int32, to]{}
   101  		e.init(mg, info, opt, impl)
   102  		return e
   103  
   104  	case types.T_int64:
   105  		e := &singleAggFuncExec1[int64, to]{}
   106  		e.init(mg, info, opt, impl)
   107  		return e
   108  
   109  	case types.T_uint8:
   110  		e := &singleAggFuncExec1[uint8, to]{}
   111  		e.init(mg, info, opt, impl)
   112  		return e
   113  
   114  	case types.T_uint16:
   115  		e := &singleAggFuncExec1[uint16, to]{}
   116  		e.init(mg, info, opt, impl)
   117  		return e
   118  
   119  	case types.T_uint32:
   120  		e := &singleAggFuncExec1[uint32, to]{}
   121  		e.init(mg, info, opt, impl)
   122  		return e
   123  
   124  	case types.T_uint64:
   125  		e := &singleAggFuncExec1[uint64, to]{}
   126  		e.init(mg, info, opt, impl)
   127  		return e
   128  
   129  	case types.T_float32:
   130  		e := &singleAggFuncExec1[float32, to]{}
   131  		e.init(mg, info, opt, impl)
   132  		return e
   133  
   134  	case types.T_float64:
   135  		e := &singleAggFuncExec1[float64, to]{}
   136  		e.init(mg, info, opt, impl)
   137  		return e
   138  
   139  	case types.T_decimal64:
   140  		e := &singleAggFuncExec1[types.Decimal64, to]{}
   141  		e.init(mg, info, opt, impl)
   142  		return e
   143  
   144  	case types.T_decimal128:
   145  		e := &singleAggFuncExec1[types.Decimal128, to]{}
   146  		e.init(mg, info, opt, impl)
   147  		return e
   148  
   149  	case types.T_date:
   150  		e := &singleAggFuncExec1[types.Date, to]{}
   151  		e.init(mg, info, opt, impl)
   152  		return e
   153  
   154  	case types.T_datetime:
   155  		e := &singleAggFuncExec1[types.Datetime, to]{}
   156  		e.init(mg, info, opt, impl)
   157  		return e
   158  
   159  	case types.T_time:
   160  		e := &singleAggFuncExec1[types.Time, to]{}
   161  		e.init(mg, info, opt, impl)
   162  		return e
   163  
   164  	case types.T_timestamp:
   165  		e := &singleAggFuncExec1[types.Timestamp, to]{}
   166  		e.init(mg, info, opt, impl)
   167  		return e
   168  
   169  	case types.T_TS:
   170  		e := &singleAggFuncExec1[types.TS, to]{}
   171  		e.init(mg, info, opt, impl)
   172  		return e
   173  
   174  	case types.T_Rowid:
   175  		e := &singleAggFuncExec1[types.Rowid, to]{}
   176  		e.init(mg, info, opt, impl)
   177  		return e
   178  
   179  	case types.T_Blockid:
   180  		e := &singleAggFuncExec1[types.Rowid, to]{}
   181  		e.init(mg, info, opt, impl)
   182  		return e
   183  
   184  	case types.T_uuid:
   185  		e := &singleAggFuncExec1[types.Uuid, to]{}
   186  		e.init(mg, info, opt, impl)
   187  		return e
   188  	}
   189  	panic(fmt.Sprintf("unexpected parameter to Init a singleAggFuncExec1, aggInfo: %s", info))
   190  }
   191  
   192  func newSingleAggFuncExec2(
   193  	mg AggMemoryManager, info singleAggInfo, opt singleAggOptimizedInfo, impl aggImplementation) AggFuncExec {
   194  	switch info.argType.Oid {
   195  	case types.T_bool:
   196  		e := &singleAggFuncExec2[bool]{}
   197  		e.init(mg, info, opt, impl)
   198  		return e
   199  
   200  	case types.T_bit:
   201  		e := &singleAggFuncExec2[uint64]{}
   202  		e.init(mg, info, opt, impl)
   203  		return e
   204  
   205  	case types.T_int8:
   206  		e := &singleAggFuncExec2[int8]{}
   207  		e.init(mg, info, opt, impl)
   208  		return e
   209  
   210  	case types.T_int16:
   211  		e := &singleAggFuncExec2[int16]{}
   212  		e.init(mg, info, opt, impl)
   213  		return e
   214  
   215  	case types.T_int32:
   216  		e := &singleAggFuncExec2[int32]{}
   217  		e.init(mg, info, opt, impl)
   218  		return e
   219  
   220  	case types.T_int64:
   221  		e := &singleAggFuncExec2[int64]{}
   222  		e.init(mg, info, opt, impl)
   223  		return e
   224  
   225  	case types.T_uint8:
   226  		e := &singleAggFuncExec2[uint8]{}
   227  		e.init(mg, info, opt, impl)
   228  		return e
   229  
   230  	case types.T_uint16:
   231  		e := &singleAggFuncExec2[uint16]{}
   232  		e.init(mg, info, opt, impl)
   233  		return e
   234  
   235  	case types.T_uint32:
   236  		e := &singleAggFuncExec2[uint32]{}
   237  		e.init(mg, info, opt, impl)
   238  		return e
   239  
   240  	case types.T_uint64:
   241  		e := &singleAggFuncExec2[uint64]{}
   242  		e.init(mg, info, opt, impl)
   243  		return e
   244  
   245  	case types.T_float32:
   246  		e := &singleAggFuncExec2[float32]{}
   247  		e.init(mg, info, opt, impl)
   248  		return e
   249  
   250  	case types.T_float64:
   251  		e := &singleAggFuncExec2[float64]{}
   252  		e.init(mg, info, opt, impl)
   253  		return e
   254  
   255  	case types.T_decimal64:
   256  		e := &singleAggFuncExec2[types.Decimal64]{}
   257  		e.init(mg, info, opt, impl)
   258  		return e
   259  
   260  	case types.T_decimal128:
   261  		e := &singleAggFuncExec2[types.Decimal128]{}
   262  		e.init(mg, info, opt, impl)
   263  		return e
   264  
   265  	case types.T_date:
   266  		e := &singleAggFuncExec2[types.Date]{}
   267  		e.init(mg, info, opt, impl)
   268  		return e
   269  
   270  	case types.T_datetime:
   271  		e := &singleAggFuncExec2[types.Datetime]{}
   272  		e.init(mg, info, opt, impl)
   273  		return e
   274  
   275  	case types.T_time:
   276  		e := &singleAggFuncExec2[types.Time]{}
   277  		e.init(mg, info, opt, impl)
   278  		return e
   279  
   280  	case types.T_timestamp:
   281  		e := &singleAggFuncExec2[types.Timestamp]{}
   282  		e.init(mg, info, opt, impl)
   283  		return e
   284  
   285  	case types.T_TS:
   286  		e := &singleAggFuncExec2[types.TS]{}
   287  		e.init(mg, info, opt, impl)
   288  		return e
   289  
   290  	case types.T_Rowid:
   291  		e := &singleAggFuncExec2[types.Rowid]{}
   292  		e.init(mg, info, opt, impl)
   293  		return e
   294  
   295  	case types.T_Blockid:
   296  		e := &singleAggFuncExec2[types.Blockid]{}
   297  		e.init(mg, info, opt, impl)
   298  		return e
   299  
   300  	case types.T_uuid:
   301  		e := &singleAggFuncExec2[types.Uuid]{}
   302  		e.init(mg, info, opt, impl)
   303  		return e
   304  	}
   305  	panic(fmt.Sprintf("unsupported parameter type %s for singleAggFuncExec2", info.argType))
   306  }
   307  
   308  func newSingleAggFuncExec3(
   309  	mg AggMemoryManager, info singleAggInfo, opt singleAggOptimizedInfo, impl aggImplementation) AggFuncExec {
   310  	switch info.retType.Oid {
   311  	case types.T_bool:
   312  		e := &singleAggFuncExec3[bool]{}
   313  		e.init(mg, info, opt, impl)
   314  		return e
   315  	case types.T_bit:
   316  		e := &singleAggFuncExec3[uint64]{}
   317  		e.init(mg, info, opt, impl)
   318  		return e
   319  	case types.T_int8:
   320  		e := &singleAggFuncExec3[int8]{}
   321  		e.init(mg, info, opt, impl)
   322  		return e
   323  	case types.T_int16:
   324  		e := &singleAggFuncExec3[int16]{}
   325  		e.init(mg, info, opt, impl)
   326  		return e
   327  	case types.T_int32:
   328  		e := &singleAggFuncExec3[int32]{}
   329  		e.init(mg, info, opt, impl)
   330  		return e
   331  	case types.T_int64:
   332  		e := &singleAggFuncExec3[int64]{}
   333  		e.init(mg, info, opt, impl)
   334  		return e
   335  	case types.T_uint8:
   336  		e := &singleAggFuncExec3[uint8]{}
   337  		e.init(mg, info, opt, impl)
   338  		return e
   339  	case types.T_uint16:
   340  		e := &singleAggFuncExec3[uint16]{}
   341  		e.init(mg, info, opt, impl)
   342  		return e
   343  	case types.T_uint32:
   344  		e := &singleAggFuncExec3[uint32]{}
   345  		e.init(mg, info, opt, impl)
   346  		return e
   347  	case types.T_uint64:
   348  		e := &singleAggFuncExec3[uint64]{}
   349  		e.init(mg, info, opt, impl)
   350  		return e
   351  	case types.T_float32:
   352  		e := &singleAggFuncExec3[float32]{}
   353  		e.init(mg, info, opt, impl)
   354  		return e
   355  	case types.T_float64:
   356  		e := &singleAggFuncExec3[float64]{}
   357  		e.init(mg, info, opt, impl)
   358  		return e
   359  	case types.T_decimal64:
   360  		e := &singleAggFuncExec3[types.Decimal64]{}
   361  		e.init(mg, info, opt, impl)
   362  		return e
   363  	case types.T_decimal128:
   364  		e := &singleAggFuncExec3[types.Decimal128]{}
   365  		e.init(mg, info, opt, impl)
   366  		return e
   367  	case types.T_date:
   368  		e := &singleAggFuncExec3[types.Date]{}
   369  		e.init(mg, info, opt, impl)
   370  		return e
   371  	case types.T_datetime:
   372  		e := &singleAggFuncExec3[types.Datetime]{}
   373  		e.init(mg, info, opt, impl)
   374  		return e
   375  	case types.T_time:
   376  		e := &singleAggFuncExec3[types.Time]{}
   377  		e.init(mg, info, opt, impl)
   378  		return e
   379  	case types.T_timestamp:
   380  		e := &singleAggFuncExec3[types.Timestamp]{}
   381  		e.init(mg, info, opt, impl)
   382  		return e
   383  	case types.T_TS:
   384  		e := &singleAggFuncExec3[types.TS]{}
   385  		e.init(mg, info, opt, impl)
   386  		return e
   387  	case types.T_Rowid:
   388  		e := &singleAggFuncExec3[types.Rowid]{}
   389  		e.init(mg, info, opt, impl)
   390  		return e
   391  	case types.T_Blockid:
   392  		e := &singleAggFuncExec3[types.Blockid]{}
   393  		e.init(mg, info, opt, impl)
   394  		return e
   395  	case types.T_uuid:
   396  		e := &singleAggFuncExec3[types.Uuid]{}
   397  		e.init(mg, info, opt, impl)
   398  		return e
   399  	}
   400  	panic(fmt.Sprintf("unsupported result type %s for singleAggFuncExec3", info.retType))
   401  }
   402  
   403  func newSingleAggFuncExec4(
   404  	mg AggMemoryManager, info singleAggInfo, opt singleAggOptimizedInfo, impl aggImplementation) AggFuncExec {
   405  	e := &singleAggFuncExec4{}
   406  	e.init(mg, info, opt, impl)
   407  	return e
   408  }