github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/col/coldata/vec.eg.go (about)

     1  // Code generated by execgen; DO NOT EDIT.
     2  // Copyright 2018 The Cockroach Authors.
     3  //
     4  // Use of this software is governed by the Business Source License
     5  // included in the file licenses/BSL.txt.
     6  //
     7  // As of the Change Date specified in that file, in accordance with
     8  // the Business Source License, use of this software will be governed
     9  // by the Apache License, Version 2.0, included in the file
    10  // licenses/APL.txt.
    11  
    12  package coldata
    13  
    14  import (
    15  	"fmt"
    16  	"time"
    17  
    18  	"github.com/cockroachdb/apd/v3"
    19  	"github.com/cockroachdb/cockroachdb-parser/pkg/col/typeconv"
    20  	"github.com/cockroachdb/cockroachdb-parser/pkg/sql/colexecerror"
    21  	"github.com/cockroachdb/cockroachdb-parser/pkg/sql/types"
    22  	"github.com/cockroachdb/cockroachdb-parser/pkg/util/duration"
    23  	"github.com/cockroachdb/cockroachdb-parser/pkg/util/json"
    24  	"github.com/cockroachdb/errors"
    25  )
    26  
    27  // Workaround for bazel auto-generated code. goimports does not automatically
    28  // pick up the right packages when run within the bazel sandbox.
    29  var (
    30  	_ = typeconv.DatumVecCanonicalTypeFamily
    31  	_ apd.Context
    32  	_ duration.Duration
    33  	_ json.JSON
    34  	_ = colexecerror.InternalError
    35  	_ = errors.AssertionFailedf
    36  )
    37  
    38  // TypedVecs represents a slice of Vecs that have been converted into the typed
    39  // columns. The idea is that every Vec is stored both in Vecs slice as well as
    40  // in the typed slice, in order. Components that know the type of the vector
    41  // they are working with can then access the typed column directly, avoiding
    42  // expensive type casts.
    43  type TypedVecs struct {
    44  	Vecs  []Vec
    45  	Nulls []*Nulls
    46  
    47  	// Fields below need to be accessed by an index mapped via ColsMap.
    48  	BoolCols      []Bools
    49  	BytesCols     []*Bytes
    50  	DecimalCols   []Decimals
    51  	Int16Cols     []Int16s
    52  	Int32Cols     []Int32s
    53  	Int64Cols     []Int64s
    54  	Float64Cols   []Float64s
    55  	TimestampCols []Times
    56  	IntervalCols  []Durations
    57  	JSONCols      []*JSONs
    58  	DatumCols     []DatumVec
    59  	// ColsMap contains the positions of the corresponding vectors in the slice
    60  	// for the same types. For example, if we have a batch with
    61  	//   types = [Int64, Int64, Bool, Bytes, Bool, Int64],
    62  	// then ColsMap will be
    63  	//                      [0, 1, 0, 0, 1, 2]
    64  	//                       ^  ^  ^  ^  ^  ^
    65  	//                       |  |  |  |  |  |
    66  	//                       |  |  |  |  |  3rd among all Int64's
    67  	//                       |  |  |  |  2nd among all Bool's
    68  	//                       |  |  |  1st among all Bytes's
    69  	//                       |  |  1st among all Bool's
    70  	//                       |  2nd among all Int64's
    71  	//                       1st among all Int64's
    72  	ColsMap []int
    73  }
    74  
    75  // SetBatch updates TypedVecs to represent all vectors from batch.
    76  func (v *TypedVecs) SetBatch(batch Batch) {
    77  	v.Vecs = batch.ColVecs()
    78  	if cap(v.Nulls) < len(v.Vecs) {
    79  		v.Nulls = make([]*Nulls, len(v.Vecs))
    80  		v.ColsMap = make([]int, len(v.Vecs))
    81  	} else {
    82  		v.Nulls = v.Nulls[:len(v.Vecs)]
    83  		v.ColsMap = v.ColsMap[:len(v.Vecs)]
    84  	}
    85  	v.BoolCols = v.BoolCols[:0]
    86  	v.BytesCols = v.BytesCols[:0]
    87  	v.DecimalCols = v.DecimalCols[:0]
    88  	v.Int16Cols = v.Int16Cols[:0]
    89  	v.Int32Cols = v.Int32Cols[:0]
    90  	v.Int64Cols = v.Int64Cols[:0]
    91  	v.Float64Cols = v.Float64Cols[:0]
    92  	v.TimestampCols = v.TimestampCols[:0]
    93  	v.IntervalCols = v.IntervalCols[:0]
    94  	v.JSONCols = v.JSONCols[:0]
    95  	v.DatumCols = v.DatumCols[:0]
    96  	for i, vec := range v.Vecs {
    97  		v.Nulls[i] = vec.Nulls()
    98  		switch vec.CanonicalTypeFamily() {
    99  		case types.BoolFamily:
   100  			switch vec.Type().Width() {
   101  			case -1:
   102  			default:
   103  				v.ColsMap[i] = len(v.BoolCols)
   104  				v.BoolCols = append(v.BoolCols, vec.Bool())
   105  			}
   106  		case types.BytesFamily:
   107  			switch vec.Type().Width() {
   108  			case -1:
   109  			default:
   110  				v.ColsMap[i] = len(v.BytesCols)
   111  				v.BytesCols = append(v.BytesCols, vec.Bytes())
   112  			}
   113  		case types.DecimalFamily:
   114  			switch vec.Type().Width() {
   115  			case -1:
   116  			default:
   117  				v.ColsMap[i] = len(v.DecimalCols)
   118  				v.DecimalCols = append(v.DecimalCols, vec.Decimal())
   119  			}
   120  		case types.IntFamily:
   121  			switch vec.Type().Width() {
   122  			case 16:
   123  				v.ColsMap[i] = len(v.Int16Cols)
   124  				v.Int16Cols = append(v.Int16Cols, vec.Int16())
   125  			case 32:
   126  				v.ColsMap[i] = len(v.Int32Cols)
   127  				v.Int32Cols = append(v.Int32Cols, vec.Int32())
   128  			case -1:
   129  			default:
   130  				v.ColsMap[i] = len(v.Int64Cols)
   131  				v.Int64Cols = append(v.Int64Cols, vec.Int64())
   132  			}
   133  		case types.FloatFamily:
   134  			switch vec.Type().Width() {
   135  			case -1:
   136  			default:
   137  				v.ColsMap[i] = len(v.Float64Cols)
   138  				v.Float64Cols = append(v.Float64Cols, vec.Float64())
   139  			}
   140  		case types.TimestampTZFamily:
   141  			switch vec.Type().Width() {
   142  			case -1:
   143  			default:
   144  				v.ColsMap[i] = len(v.TimestampCols)
   145  				v.TimestampCols = append(v.TimestampCols, vec.Timestamp())
   146  			}
   147  		case types.IntervalFamily:
   148  			switch vec.Type().Width() {
   149  			case -1:
   150  			default:
   151  				v.ColsMap[i] = len(v.IntervalCols)
   152  				v.IntervalCols = append(v.IntervalCols, vec.Interval())
   153  			}
   154  		case types.JsonFamily:
   155  			switch vec.Type().Width() {
   156  			case -1:
   157  			default:
   158  				v.ColsMap[i] = len(v.JSONCols)
   159  				v.JSONCols = append(v.JSONCols, vec.JSON())
   160  			}
   161  		case typeconv.DatumVecCanonicalTypeFamily:
   162  			switch vec.Type().Width() {
   163  			case -1:
   164  			default:
   165  				v.ColsMap[i] = len(v.DatumCols)
   166  				v.DatumCols = append(v.DatumCols, vec.Datum())
   167  			}
   168  		default:
   169  			colexecerror.InternalError(errors.AssertionFailedf("unhandled type %s", vec.Type()))
   170  		}
   171  	}
   172  }
   173  
   174  // Reset performs a deep reset of v while keeping the references to the slices.
   175  func (v *TypedVecs) Reset() {
   176  	v.Vecs = nil
   177  	for i := range v.Nulls {
   178  		v.Nulls[i] = nil
   179  	}
   180  	for i := range v.BoolCols {
   181  		v.BoolCols[i] = nil
   182  	}
   183  	for i := range v.BytesCols {
   184  		v.BytesCols[i] = nil
   185  	}
   186  	for i := range v.DecimalCols {
   187  		v.DecimalCols[i] = nil
   188  	}
   189  	for i := range v.Int16Cols {
   190  		v.Int16Cols[i] = nil
   191  	}
   192  	for i := range v.Int32Cols {
   193  		v.Int32Cols[i] = nil
   194  	}
   195  	for i := range v.Int64Cols {
   196  		v.Int64Cols[i] = nil
   197  	}
   198  	for i := range v.Float64Cols {
   199  		v.Float64Cols[i] = nil
   200  	}
   201  	for i := range v.TimestampCols {
   202  		v.TimestampCols[i] = nil
   203  	}
   204  	for i := range v.IntervalCols {
   205  		v.IntervalCols[i] = nil
   206  	}
   207  	for i := range v.JSONCols {
   208  		v.JSONCols[i] = nil
   209  	}
   210  	for i := range v.DatumCols {
   211  		v.DatumCols[i] = nil
   212  	}
   213  }
   214  
   215  func (m *memColumn) Append(args SliceArgs) {
   216  	switch m.CanonicalTypeFamily() {
   217  	case types.BoolFamily:
   218  		switch m.t.Width() {
   219  		case -1:
   220  		default:
   221  			fromCol := args.Src.Bool()
   222  			toCol := m.Bool()
   223  			// NOTE: it is unfortunate that we always append whole slice without paying
   224  			// attention to whether the values are NULL. However, if we do start paying
   225  			// attention, the performance suffers dramatically, so we choose to copy
   226  			// over "actual" as well as "garbage" values.
   227  			if args.Sel == nil {
   228  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   229  			} else {
   230  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   231  				toCol = toCol.Window(0, args.DestIdx)
   232  				for _, selIdx := range sel {
   233  					val := fromCol.Get(selIdx)
   234  					toCol = append(toCol, val)
   235  				}
   236  			}
   237  			m.nulls.set(args)
   238  			m.col = toCol
   239  		}
   240  	case types.BytesFamily:
   241  		switch m.t.Width() {
   242  		case -1:
   243  		default:
   244  			fromCol := args.Src.Bytes()
   245  			toCol := m.Bytes()
   246  			// NOTE: it is unfortunate that we always append whole slice without paying
   247  			// attention to whether the values are NULL. However, if we do start paying
   248  			// attention, the performance suffers dramatically, so we choose to copy
   249  			// over "actual" as well as "garbage" values.
   250  			if args.Sel == nil {
   251  				toCol.AppendSlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   252  			} else {
   253  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   254  				toCol.appendSliceWithSel(fromCol, args.DestIdx, sel)
   255  			}
   256  			m.nulls.set(args)
   257  			m.col = toCol
   258  		}
   259  	case types.DecimalFamily:
   260  		switch m.t.Width() {
   261  		case -1:
   262  		default:
   263  			fromCol := args.Src.Decimal()
   264  			toCol := m.Decimal()
   265  			// NOTE: it is unfortunate that we always append whole slice without paying
   266  			// attention to whether the values are NULL. However, if we do start paying
   267  			// attention, the performance suffers dramatically, so we choose to copy
   268  			// over "actual" as well as "garbage" values.
   269  			if args.Sel == nil {
   270  				{
   271  					__desiredCap := args.DestIdx + args.SrcEndIdx - args.SrcStartIdx
   272  					if cap(toCol) >= __desiredCap {
   273  						toCol = toCol[:__desiredCap]
   274  					} else {
   275  						__prevCap := cap(toCol)
   276  						__capToAllocate := __desiredCap
   277  						if __capToAllocate < 2*__prevCap {
   278  							__capToAllocate = 2 * __prevCap
   279  						}
   280  						__new_slice := make([]apd.Decimal, __desiredCap, __capToAllocate)
   281  						copy(__new_slice, toCol[:args.DestIdx])
   282  						toCol = __new_slice
   283  					}
   284  					__src_slice := fromCol[args.SrcStartIdx:args.SrcEndIdx]
   285  					__dst_slice := toCol[args.DestIdx:]
   286  					_ = __dst_slice[len(__src_slice)-1]
   287  					for __i := range __src_slice {
   288  						//gcassert:bce
   289  						__dst_slice[__i].Set(&__src_slice[__i])
   290  					}
   291  				}
   292  			} else {
   293  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   294  				toCol = toCol.Window(0, args.DestIdx)
   295  				for _, selIdx := range sel {
   296  					val := fromCol.Get(selIdx)
   297  					toCol = append(toCol, apd.Decimal{})
   298  					toCol[len(toCol)-1].Set(&val)
   299  				}
   300  			}
   301  			m.nulls.set(args)
   302  			m.col = toCol
   303  		}
   304  	case types.IntFamily:
   305  		switch m.t.Width() {
   306  		case 16:
   307  			fromCol := args.Src.Int16()
   308  			toCol := m.Int16()
   309  			// NOTE: it is unfortunate that we always append whole slice without paying
   310  			// attention to whether the values are NULL. However, if we do start paying
   311  			// attention, the performance suffers dramatically, so we choose to copy
   312  			// over "actual" as well as "garbage" values.
   313  			if args.Sel == nil {
   314  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   315  			} else {
   316  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   317  				toCol = toCol.Window(0, args.DestIdx)
   318  				for _, selIdx := range sel {
   319  					val := fromCol.Get(selIdx)
   320  					toCol = append(toCol, val)
   321  				}
   322  			}
   323  			m.nulls.set(args)
   324  			m.col = toCol
   325  		case 32:
   326  			fromCol := args.Src.Int32()
   327  			toCol := m.Int32()
   328  			// NOTE: it is unfortunate that we always append whole slice without paying
   329  			// attention to whether the values are NULL. However, if we do start paying
   330  			// attention, the performance suffers dramatically, so we choose to copy
   331  			// over "actual" as well as "garbage" values.
   332  			if args.Sel == nil {
   333  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   334  			} else {
   335  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   336  				toCol = toCol.Window(0, args.DestIdx)
   337  				for _, selIdx := range sel {
   338  					val := fromCol.Get(selIdx)
   339  					toCol = append(toCol, val)
   340  				}
   341  			}
   342  			m.nulls.set(args)
   343  			m.col = toCol
   344  		case -1:
   345  		default:
   346  			fromCol := args.Src.Int64()
   347  			toCol := m.Int64()
   348  			// NOTE: it is unfortunate that we always append whole slice without paying
   349  			// attention to whether the values are NULL. However, if we do start paying
   350  			// attention, the performance suffers dramatically, so we choose to copy
   351  			// over "actual" as well as "garbage" values.
   352  			if args.Sel == nil {
   353  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   354  			} else {
   355  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   356  				toCol = toCol.Window(0, args.DestIdx)
   357  				for _, selIdx := range sel {
   358  					val := fromCol.Get(selIdx)
   359  					toCol = append(toCol, val)
   360  				}
   361  			}
   362  			m.nulls.set(args)
   363  			m.col = toCol
   364  		}
   365  	case types.FloatFamily:
   366  		switch m.t.Width() {
   367  		case -1:
   368  		default:
   369  			fromCol := args.Src.Float64()
   370  			toCol := m.Float64()
   371  			// NOTE: it is unfortunate that we always append whole slice without paying
   372  			// attention to whether the values are NULL. However, if we do start paying
   373  			// attention, the performance suffers dramatically, so we choose to copy
   374  			// over "actual" as well as "garbage" values.
   375  			if args.Sel == nil {
   376  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   377  			} else {
   378  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   379  				toCol = toCol.Window(0, args.DestIdx)
   380  				for _, selIdx := range sel {
   381  					val := fromCol.Get(selIdx)
   382  					toCol = append(toCol, val)
   383  				}
   384  			}
   385  			m.nulls.set(args)
   386  			m.col = toCol
   387  		}
   388  	case types.TimestampTZFamily:
   389  		switch m.t.Width() {
   390  		case -1:
   391  		default:
   392  			fromCol := args.Src.Timestamp()
   393  			toCol := m.Timestamp()
   394  			// NOTE: it is unfortunate that we always append whole slice without paying
   395  			// attention to whether the values are NULL. However, if we do start paying
   396  			// attention, the performance suffers dramatically, so we choose to copy
   397  			// over "actual" as well as "garbage" values.
   398  			if args.Sel == nil {
   399  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   400  			} else {
   401  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   402  				toCol = toCol.Window(0, args.DestIdx)
   403  				for _, selIdx := range sel {
   404  					val := fromCol.Get(selIdx)
   405  					toCol = append(toCol, val)
   406  				}
   407  			}
   408  			m.nulls.set(args)
   409  			m.col = toCol
   410  		}
   411  	case types.IntervalFamily:
   412  		switch m.t.Width() {
   413  		case -1:
   414  		default:
   415  			fromCol := args.Src.Interval()
   416  			toCol := m.Interval()
   417  			// NOTE: it is unfortunate that we always append whole slice without paying
   418  			// attention to whether the values are NULL. However, if we do start paying
   419  			// attention, the performance suffers dramatically, so we choose to copy
   420  			// over "actual" as well as "garbage" values.
   421  			if args.Sel == nil {
   422  				toCol = append(toCol[:args.DestIdx], fromCol[args.SrcStartIdx:args.SrcEndIdx]...)
   423  			} else {
   424  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   425  				toCol = toCol.Window(0, args.DestIdx)
   426  				for _, selIdx := range sel {
   427  					val := fromCol.Get(selIdx)
   428  					toCol = append(toCol, val)
   429  				}
   430  			}
   431  			m.nulls.set(args)
   432  			m.col = toCol
   433  		}
   434  	case types.JsonFamily:
   435  		switch m.t.Width() {
   436  		case -1:
   437  		default:
   438  			fromCol := args.Src.JSON()
   439  			toCol := m.JSON()
   440  			// NOTE: it is unfortunate that we always append whole slice without paying
   441  			// attention to whether the values are NULL. However, if we do start paying
   442  			// attention, the performance suffers dramatically, so we choose to copy
   443  			// over "actual" as well as "garbage" values.
   444  			if args.Sel == nil {
   445  				toCol.AppendSlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   446  			} else {
   447  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   448  				toCol.appendSliceWithSel(fromCol, args.DestIdx, sel)
   449  			}
   450  			m.nulls.set(args)
   451  			m.col = toCol
   452  		}
   453  	case typeconv.DatumVecCanonicalTypeFamily:
   454  		switch m.t.Width() {
   455  		case -1:
   456  		default:
   457  			fromCol := args.Src.Datum()
   458  			toCol := m.Datum()
   459  			// NOTE: it is unfortunate that we always append whole slice without paying
   460  			// attention to whether the values are NULL. However, if we do start paying
   461  			// attention, the performance suffers dramatically, so we choose to copy
   462  			// over "actual" as well as "garbage" values.
   463  			if args.Sel == nil {
   464  				toCol.AppendSlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   465  			} else {
   466  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   467  				toCol = toCol.Window(0, args.DestIdx)
   468  				for _, selIdx := range sel {
   469  					val := fromCol.Get(selIdx)
   470  					toCol.AppendVal(val)
   471  				}
   472  			}
   473  			m.nulls.set(args)
   474  			m.col = toCol
   475  		}
   476  	default:
   477  		panic(fmt.Sprintf("unhandled type %s", m.t))
   478  	}
   479  }
   480  
   481  func (m *memColumn) Copy(args SliceArgs) {
   482  	if args.SrcStartIdx == args.SrcEndIdx {
   483  		// Nothing to copy, so return early.
   484  		return
   485  	}
   486  	if m.Nulls().MaybeHasNulls() {
   487  		// We're about to overwrite this entire range, so unset all the nulls.
   488  		m.Nulls().UnsetNullRange(args.DestIdx, args.DestIdx+(args.SrcEndIdx-args.SrcStartIdx))
   489  	}
   490  
   491  	switch m.CanonicalTypeFamily() {
   492  	case types.BoolFamily:
   493  		switch m.t.Width() {
   494  		case -1:
   495  		default:
   496  			fromCol := args.Src.Bool()
   497  			toCol := m.Bool()
   498  			if args.Sel != nil {
   499  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   500  				n := len(sel)
   501  				toCol = toCol[args.DestIdx:]
   502  				_ = toCol[n-1]
   503  				if args.Src.MaybeHasNulls() {
   504  					nulls := args.Src.Nulls()
   505  					for i := 0; i < n; i++ {
   506  						//gcassert:bce
   507  						selIdx := sel[i]
   508  						if nulls.NullAt(selIdx) {
   509  							m.nulls.SetNull(i + args.DestIdx)
   510  						} else {
   511  							v := fromCol.Get(selIdx)
   512  							//gcassert:bce
   513  							toCol.Set(i, v)
   514  						}
   515  					}
   516  					return
   517  				}
   518  				// No Nulls.
   519  				for i := 0; i < n; i++ {
   520  					//gcassert:bce
   521  					selIdx := sel[i]
   522  					v := fromCol.Get(selIdx)
   523  					//gcassert:bce
   524  					toCol.Set(i, v)
   525  				}
   526  				return
   527  			}
   528  			// No Sel.
   529  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   530  			m.nulls.set(args)
   531  		}
   532  	case types.BytesFamily:
   533  		switch m.t.Width() {
   534  		case -1:
   535  		default:
   536  			fromCol := args.Src.Bytes()
   537  			toCol := m.Bytes()
   538  			if args.Sel != nil {
   539  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   540  				n := len(sel)
   541  				if args.Src.MaybeHasNulls() {
   542  					nulls := args.Src.Nulls()
   543  					for i := 0; i < n; i++ {
   544  						//gcassert:bce
   545  						selIdx := sel[i]
   546  						if nulls.NullAt(selIdx) {
   547  							m.nulls.SetNull(i + args.DestIdx)
   548  						} else {
   549  							toCol.Copy(fromCol, i+args.DestIdx, selIdx)
   550  						}
   551  					}
   552  					return
   553  				}
   554  				// No Nulls.
   555  				for i := 0; i < n; i++ {
   556  					//gcassert:bce
   557  					selIdx := sel[i]
   558  					toCol.Copy(fromCol, i+args.DestIdx, selIdx)
   559  				}
   560  				return
   561  			}
   562  			// No Sel.
   563  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   564  			m.nulls.set(args)
   565  		}
   566  	case types.DecimalFamily:
   567  		switch m.t.Width() {
   568  		case -1:
   569  		default:
   570  			fromCol := args.Src.Decimal()
   571  			toCol := m.Decimal()
   572  			if args.Sel != nil {
   573  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   574  				n := len(sel)
   575  				toCol = toCol[args.DestIdx:]
   576  				_ = toCol[n-1]
   577  				if args.Src.MaybeHasNulls() {
   578  					nulls := args.Src.Nulls()
   579  					for i := 0; i < n; i++ {
   580  						//gcassert:bce
   581  						selIdx := sel[i]
   582  						if nulls.NullAt(selIdx) {
   583  							m.nulls.SetNull(i + args.DestIdx)
   584  						} else {
   585  							v := fromCol.Get(selIdx)
   586  							//gcassert:bce
   587  							toCol.Set(i, v)
   588  						}
   589  					}
   590  					return
   591  				}
   592  				// No Nulls.
   593  				for i := 0; i < n; i++ {
   594  					//gcassert:bce
   595  					selIdx := sel[i]
   596  					v := fromCol.Get(selIdx)
   597  					//gcassert:bce
   598  					toCol.Set(i, v)
   599  				}
   600  				return
   601  			}
   602  			// No Sel.
   603  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   604  			m.nulls.set(args)
   605  		}
   606  	case types.IntFamily:
   607  		switch m.t.Width() {
   608  		case 16:
   609  			fromCol := args.Src.Int16()
   610  			toCol := m.Int16()
   611  			if args.Sel != nil {
   612  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   613  				n := len(sel)
   614  				toCol = toCol[args.DestIdx:]
   615  				_ = toCol[n-1]
   616  				if args.Src.MaybeHasNulls() {
   617  					nulls := args.Src.Nulls()
   618  					for i := 0; i < n; i++ {
   619  						//gcassert:bce
   620  						selIdx := sel[i]
   621  						if nulls.NullAt(selIdx) {
   622  							m.nulls.SetNull(i + args.DestIdx)
   623  						} else {
   624  							v := fromCol.Get(selIdx)
   625  							//gcassert:bce
   626  							toCol.Set(i, v)
   627  						}
   628  					}
   629  					return
   630  				}
   631  				// No Nulls.
   632  				for i := 0; i < n; i++ {
   633  					//gcassert:bce
   634  					selIdx := sel[i]
   635  					v := fromCol.Get(selIdx)
   636  					//gcassert:bce
   637  					toCol.Set(i, v)
   638  				}
   639  				return
   640  			}
   641  			// No Sel.
   642  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   643  			m.nulls.set(args)
   644  		case 32:
   645  			fromCol := args.Src.Int32()
   646  			toCol := m.Int32()
   647  			if args.Sel != nil {
   648  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   649  				n := len(sel)
   650  				toCol = toCol[args.DestIdx:]
   651  				_ = toCol[n-1]
   652  				if args.Src.MaybeHasNulls() {
   653  					nulls := args.Src.Nulls()
   654  					for i := 0; i < n; i++ {
   655  						//gcassert:bce
   656  						selIdx := sel[i]
   657  						if nulls.NullAt(selIdx) {
   658  							m.nulls.SetNull(i + args.DestIdx)
   659  						} else {
   660  							v := fromCol.Get(selIdx)
   661  							//gcassert:bce
   662  							toCol.Set(i, v)
   663  						}
   664  					}
   665  					return
   666  				}
   667  				// No Nulls.
   668  				for i := 0; i < n; i++ {
   669  					//gcassert:bce
   670  					selIdx := sel[i]
   671  					v := fromCol.Get(selIdx)
   672  					//gcassert:bce
   673  					toCol.Set(i, v)
   674  				}
   675  				return
   676  			}
   677  			// No Sel.
   678  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   679  			m.nulls.set(args)
   680  		case -1:
   681  		default:
   682  			fromCol := args.Src.Int64()
   683  			toCol := m.Int64()
   684  			if args.Sel != nil {
   685  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   686  				n := len(sel)
   687  				toCol = toCol[args.DestIdx:]
   688  				_ = toCol[n-1]
   689  				if args.Src.MaybeHasNulls() {
   690  					nulls := args.Src.Nulls()
   691  					for i := 0; i < n; i++ {
   692  						//gcassert:bce
   693  						selIdx := sel[i]
   694  						if nulls.NullAt(selIdx) {
   695  							m.nulls.SetNull(i + args.DestIdx)
   696  						} else {
   697  							v := fromCol.Get(selIdx)
   698  							//gcassert:bce
   699  							toCol.Set(i, v)
   700  						}
   701  					}
   702  					return
   703  				}
   704  				// No Nulls.
   705  				for i := 0; i < n; i++ {
   706  					//gcassert:bce
   707  					selIdx := sel[i]
   708  					v := fromCol.Get(selIdx)
   709  					//gcassert:bce
   710  					toCol.Set(i, v)
   711  				}
   712  				return
   713  			}
   714  			// No Sel.
   715  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   716  			m.nulls.set(args)
   717  		}
   718  	case types.FloatFamily:
   719  		switch m.t.Width() {
   720  		case -1:
   721  		default:
   722  			fromCol := args.Src.Float64()
   723  			toCol := m.Float64()
   724  			if args.Sel != nil {
   725  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   726  				n := len(sel)
   727  				toCol = toCol[args.DestIdx:]
   728  				_ = toCol[n-1]
   729  				if args.Src.MaybeHasNulls() {
   730  					nulls := args.Src.Nulls()
   731  					for i := 0; i < n; i++ {
   732  						//gcassert:bce
   733  						selIdx := sel[i]
   734  						if nulls.NullAt(selIdx) {
   735  							m.nulls.SetNull(i + args.DestIdx)
   736  						} else {
   737  							v := fromCol.Get(selIdx)
   738  							//gcassert:bce
   739  							toCol.Set(i, v)
   740  						}
   741  					}
   742  					return
   743  				}
   744  				// No Nulls.
   745  				for i := 0; i < n; i++ {
   746  					//gcassert:bce
   747  					selIdx := sel[i]
   748  					v := fromCol.Get(selIdx)
   749  					//gcassert:bce
   750  					toCol.Set(i, v)
   751  				}
   752  				return
   753  			}
   754  			// No Sel.
   755  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   756  			m.nulls.set(args)
   757  		}
   758  	case types.TimestampTZFamily:
   759  		switch m.t.Width() {
   760  		case -1:
   761  		default:
   762  			fromCol := args.Src.Timestamp()
   763  			toCol := m.Timestamp()
   764  			if args.Sel != nil {
   765  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   766  				n := len(sel)
   767  				toCol = toCol[args.DestIdx:]
   768  				_ = toCol[n-1]
   769  				if args.Src.MaybeHasNulls() {
   770  					nulls := args.Src.Nulls()
   771  					for i := 0; i < n; i++ {
   772  						//gcassert:bce
   773  						selIdx := sel[i]
   774  						if nulls.NullAt(selIdx) {
   775  							m.nulls.SetNull(i + args.DestIdx)
   776  						} else {
   777  							v := fromCol.Get(selIdx)
   778  							//gcassert:bce
   779  							toCol.Set(i, v)
   780  						}
   781  					}
   782  					return
   783  				}
   784  				// No Nulls.
   785  				for i := 0; i < n; i++ {
   786  					//gcassert:bce
   787  					selIdx := sel[i]
   788  					v := fromCol.Get(selIdx)
   789  					//gcassert:bce
   790  					toCol.Set(i, v)
   791  				}
   792  				return
   793  			}
   794  			// No Sel.
   795  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   796  			m.nulls.set(args)
   797  		}
   798  	case types.IntervalFamily:
   799  		switch m.t.Width() {
   800  		case -1:
   801  		default:
   802  			fromCol := args.Src.Interval()
   803  			toCol := m.Interval()
   804  			if args.Sel != nil {
   805  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   806  				n := len(sel)
   807  				toCol = toCol[args.DestIdx:]
   808  				_ = toCol[n-1]
   809  				if args.Src.MaybeHasNulls() {
   810  					nulls := args.Src.Nulls()
   811  					for i := 0; i < n; i++ {
   812  						//gcassert:bce
   813  						selIdx := sel[i]
   814  						if nulls.NullAt(selIdx) {
   815  							m.nulls.SetNull(i + args.DestIdx)
   816  						} else {
   817  							v := fromCol.Get(selIdx)
   818  							//gcassert:bce
   819  							toCol.Set(i, v)
   820  						}
   821  					}
   822  					return
   823  				}
   824  				// No Nulls.
   825  				for i := 0; i < n; i++ {
   826  					//gcassert:bce
   827  					selIdx := sel[i]
   828  					v := fromCol.Get(selIdx)
   829  					//gcassert:bce
   830  					toCol.Set(i, v)
   831  				}
   832  				return
   833  			}
   834  			// No Sel.
   835  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   836  			m.nulls.set(args)
   837  		}
   838  	case types.JsonFamily:
   839  		switch m.t.Width() {
   840  		case -1:
   841  		default:
   842  			fromCol := args.Src.JSON()
   843  			toCol := m.JSON()
   844  			if args.Sel != nil {
   845  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   846  				n := len(sel)
   847  				if args.Src.MaybeHasNulls() {
   848  					nulls := args.Src.Nulls()
   849  					for i := 0; i < n; i++ {
   850  						//gcassert:bce
   851  						selIdx := sel[i]
   852  						if nulls.NullAt(selIdx) {
   853  							m.nulls.SetNull(i + args.DestIdx)
   854  						} else {
   855  							toCol.Copy(fromCol, i+args.DestIdx, selIdx)
   856  						}
   857  					}
   858  					return
   859  				}
   860  				// No Nulls.
   861  				for i := 0; i < n; i++ {
   862  					//gcassert:bce
   863  					selIdx := sel[i]
   864  					toCol.Copy(fromCol, i+args.DestIdx, selIdx)
   865  				}
   866  				return
   867  			}
   868  			// No Sel.
   869  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   870  			m.nulls.set(args)
   871  		}
   872  	case typeconv.DatumVecCanonicalTypeFamily:
   873  		switch m.t.Width() {
   874  		case -1:
   875  		default:
   876  			fromCol := args.Src.Datum()
   877  			toCol := m.Datum()
   878  			if args.Sel != nil {
   879  				sel := args.Sel[args.SrcStartIdx:args.SrcEndIdx]
   880  				n := len(sel)
   881  				if args.Src.MaybeHasNulls() {
   882  					nulls := args.Src.Nulls()
   883  					for i := 0; i < n; i++ {
   884  						//gcassert:bce
   885  						selIdx := sel[i]
   886  						if nulls.NullAt(selIdx) {
   887  							m.nulls.SetNull(i + args.DestIdx)
   888  						} else {
   889  							v := fromCol.Get(selIdx)
   890  							toCol.Set(i+args.DestIdx, v)
   891  						}
   892  					}
   893  					return
   894  				}
   895  				// No Nulls.
   896  				for i := 0; i < n; i++ {
   897  					//gcassert:bce
   898  					selIdx := sel[i]
   899  					v := fromCol.Get(selIdx)
   900  					toCol.Set(i+args.DestIdx, v)
   901  				}
   902  				return
   903  			}
   904  			// No Sel.
   905  			toCol.CopySlice(fromCol, args.DestIdx, args.SrcStartIdx, args.SrcEndIdx)
   906  			m.nulls.set(args)
   907  		}
   908  	default:
   909  		panic(fmt.Sprintf("unhandled type %s", m.t))
   910  	}
   911  }
   912  
   913  func (m *memColumn) CopyWithReorderedSource(src Vec, sel, order []int) {
   914  	if len(sel) == 0 {
   915  		return
   916  	}
   917  	if m.nulls.MaybeHasNulls() {
   918  		m.nulls.UnsetNulls()
   919  	}
   920  	switch m.CanonicalTypeFamily() {
   921  	case types.BoolFamily:
   922  		switch m.t.Width() {
   923  		case -1:
   924  		default:
   925  			fromCol := src.Bool()
   926  			toCol := m.Bool()
   927  			n := len(sel)
   928  			_ = sel[n-1]
   929  			if src.MaybeHasNulls() {
   930  				nulls := src.Nulls()
   931  				for i := 0; i < n; i++ {
   932  					//gcassert:bce
   933  					destIdx := sel[i]
   934  					srcIdx := order[destIdx]
   935  					if nulls.NullAt(srcIdx) {
   936  						m.nulls.SetNull(destIdx)
   937  					} else {
   938  						v := fromCol.Get(srcIdx)
   939  						toCol.Set(destIdx, v)
   940  					}
   941  				}
   942  			} else {
   943  				for i := 0; i < n; i++ {
   944  					//gcassert:bce
   945  					destIdx := sel[i]
   946  					srcIdx := order[destIdx]
   947  					{
   948  						v := fromCol.Get(srcIdx)
   949  						toCol.Set(destIdx, v)
   950  					}
   951  				}
   952  			}
   953  		}
   954  	case types.BytesFamily:
   955  		switch m.t.Width() {
   956  		case -1:
   957  		default:
   958  			fromCol := src.Bytes()
   959  			toCol := m.Bytes()
   960  			n := len(sel)
   961  			_ = sel[n-1]
   962  			if src.MaybeHasNulls() {
   963  				nulls := src.Nulls()
   964  				for i := 0; i < n; i++ {
   965  					//gcassert:bce
   966  					destIdx := sel[i]
   967  					srcIdx := order[destIdx]
   968  					if nulls.NullAt(srcIdx) {
   969  						m.nulls.SetNull(destIdx)
   970  					} else {
   971  						toCol.Copy(fromCol, destIdx, srcIdx)
   972  					}
   973  				}
   974  			} else {
   975  				for i := 0; i < n; i++ {
   976  					//gcassert:bce
   977  					destIdx := sel[i]
   978  					srcIdx := order[destIdx]
   979  					{
   980  						toCol.Copy(fromCol, destIdx, srcIdx)
   981  					}
   982  				}
   983  			}
   984  		}
   985  	case types.DecimalFamily:
   986  		switch m.t.Width() {
   987  		case -1:
   988  		default:
   989  			fromCol := src.Decimal()
   990  			toCol := m.Decimal()
   991  			n := len(sel)
   992  			_ = sel[n-1]
   993  			if src.MaybeHasNulls() {
   994  				nulls := src.Nulls()
   995  				for i := 0; i < n; i++ {
   996  					//gcassert:bce
   997  					destIdx := sel[i]
   998  					srcIdx := order[destIdx]
   999  					if nulls.NullAt(srcIdx) {
  1000  						m.nulls.SetNull(destIdx)
  1001  					} else {
  1002  						v := fromCol.Get(srcIdx)
  1003  						toCol.Set(destIdx, v)
  1004  					}
  1005  				}
  1006  			} else {
  1007  				for i := 0; i < n; i++ {
  1008  					//gcassert:bce
  1009  					destIdx := sel[i]
  1010  					srcIdx := order[destIdx]
  1011  					{
  1012  						v := fromCol.Get(srcIdx)
  1013  						toCol.Set(destIdx, v)
  1014  					}
  1015  				}
  1016  			}
  1017  		}
  1018  	case types.IntFamily:
  1019  		switch m.t.Width() {
  1020  		case 16:
  1021  			fromCol := src.Int16()
  1022  			toCol := m.Int16()
  1023  			n := len(sel)
  1024  			_ = sel[n-1]
  1025  			if src.MaybeHasNulls() {
  1026  				nulls := src.Nulls()
  1027  				for i := 0; i < n; i++ {
  1028  					//gcassert:bce
  1029  					destIdx := sel[i]
  1030  					srcIdx := order[destIdx]
  1031  					if nulls.NullAt(srcIdx) {
  1032  						m.nulls.SetNull(destIdx)
  1033  					} else {
  1034  						v := fromCol.Get(srcIdx)
  1035  						toCol.Set(destIdx, v)
  1036  					}
  1037  				}
  1038  			} else {
  1039  				for i := 0; i < n; i++ {
  1040  					//gcassert:bce
  1041  					destIdx := sel[i]
  1042  					srcIdx := order[destIdx]
  1043  					{
  1044  						v := fromCol.Get(srcIdx)
  1045  						toCol.Set(destIdx, v)
  1046  					}
  1047  				}
  1048  			}
  1049  		case 32:
  1050  			fromCol := src.Int32()
  1051  			toCol := m.Int32()
  1052  			n := len(sel)
  1053  			_ = sel[n-1]
  1054  			if src.MaybeHasNulls() {
  1055  				nulls := src.Nulls()
  1056  				for i := 0; i < n; i++ {
  1057  					//gcassert:bce
  1058  					destIdx := sel[i]
  1059  					srcIdx := order[destIdx]
  1060  					if nulls.NullAt(srcIdx) {
  1061  						m.nulls.SetNull(destIdx)
  1062  					} else {
  1063  						v := fromCol.Get(srcIdx)
  1064  						toCol.Set(destIdx, v)
  1065  					}
  1066  				}
  1067  			} else {
  1068  				for i := 0; i < n; i++ {
  1069  					//gcassert:bce
  1070  					destIdx := sel[i]
  1071  					srcIdx := order[destIdx]
  1072  					{
  1073  						v := fromCol.Get(srcIdx)
  1074  						toCol.Set(destIdx, v)
  1075  					}
  1076  				}
  1077  			}
  1078  		case -1:
  1079  		default:
  1080  			fromCol := src.Int64()
  1081  			toCol := m.Int64()
  1082  			n := len(sel)
  1083  			_ = sel[n-1]
  1084  			if src.MaybeHasNulls() {
  1085  				nulls := src.Nulls()
  1086  				for i := 0; i < n; i++ {
  1087  					//gcassert:bce
  1088  					destIdx := sel[i]
  1089  					srcIdx := order[destIdx]
  1090  					if nulls.NullAt(srcIdx) {
  1091  						m.nulls.SetNull(destIdx)
  1092  					} else {
  1093  						v := fromCol.Get(srcIdx)
  1094  						toCol.Set(destIdx, v)
  1095  					}
  1096  				}
  1097  			} else {
  1098  				for i := 0; i < n; i++ {
  1099  					//gcassert:bce
  1100  					destIdx := sel[i]
  1101  					srcIdx := order[destIdx]
  1102  					{
  1103  						v := fromCol.Get(srcIdx)
  1104  						toCol.Set(destIdx, v)
  1105  					}
  1106  				}
  1107  			}
  1108  		}
  1109  	case types.FloatFamily:
  1110  		switch m.t.Width() {
  1111  		case -1:
  1112  		default:
  1113  			fromCol := src.Float64()
  1114  			toCol := m.Float64()
  1115  			n := len(sel)
  1116  			_ = sel[n-1]
  1117  			if src.MaybeHasNulls() {
  1118  				nulls := src.Nulls()
  1119  				for i := 0; i < n; i++ {
  1120  					//gcassert:bce
  1121  					destIdx := sel[i]
  1122  					srcIdx := order[destIdx]
  1123  					if nulls.NullAt(srcIdx) {
  1124  						m.nulls.SetNull(destIdx)
  1125  					} else {
  1126  						v := fromCol.Get(srcIdx)
  1127  						toCol.Set(destIdx, v)
  1128  					}
  1129  				}
  1130  			} else {
  1131  				for i := 0; i < n; i++ {
  1132  					//gcassert:bce
  1133  					destIdx := sel[i]
  1134  					srcIdx := order[destIdx]
  1135  					{
  1136  						v := fromCol.Get(srcIdx)
  1137  						toCol.Set(destIdx, v)
  1138  					}
  1139  				}
  1140  			}
  1141  		}
  1142  	case types.TimestampTZFamily:
  1143  		switch m.t.Width() {
  1144  		case -1:
  1145  		default:
  1146  			fromCol := src.Timestamp()
  1147  			toCol := m.Timestamp()
  1148  			n := len(sel)
  1149  			_ = sel[n-1]
  1150  			if src.MaybeHasNulls() {
  1151  				nulls := src.Nulls()
  1152  				for i := 0; i < n; i++ {
  1153  					//gcassert:bce
  1154  					destIdx := sel[i]
  1155  					srcIdx := order[destIdx]
  1156  					if nulls.NullAt(srcIdx) {
  1157  						m.nulls.SetNull(destIdx)
  1158  					} else {
  1159  						v := fromCol.Get(srcIdx)
  1160  						toCol.Set(destIdx, v)
  1161  					}
  1162  				}
  1163  			} else {
  1164  				for i := 0; i < n; i++ {
  1165  					//gcassert:bce
  1166  					destIdx := sel[i]
  1167  					srcIdx := order[destIdx]
  1168  					{
  1169  						v := fromCol.Get(srcIdx)
  1170  						toCol.Set(destIdx, v)
  1171  					}
  1172  				}
  1173  			}
  1174  		}
  1175  	case types.IntervalFamily:
  1176  		switch m.t.Width() {
  1177  		case -1:
  1178  		default:
  1179  			fromCol := src.Interval()
  1180  			toCol := m.Interval()
  1181  			n := len(sel)
  1182  			_ = sel[n-1]
  1183  			if src.MaybeHasNulls() {
  1184  				nulls := src.Nulls()
  1185  				for i := 0; i < n; i++ {
  1186  					//gcassert:bce
  1187  					destIdx := sel[i]
  1188  					srcIdx := order[destIdx]
  1189  					if nulls.NullAt(srcIdx) {
  1190  						m.nulls.SetNull(destIdx)
  1191  					} else {
  1192  						v := fromCol.Get(srcIdx)
  1193  						toCol.Set(destIdx, v)
  1194  					}
  1195  				}
  1196  			} else {
  1197  				for i := 0; i < n; i++ {
  1198  					//gcassert:bce
  1199  					destIdx := sel[i]
  1200  					srcIdx := order[destIdx]
  1201  					{
  1202  						v := fromCol.Get(srcIdx)
  1203  						toCol.Set(destIdx, v)
  1204  					}
  1205  				}
  1206  			}
  1207  		}
  1208  	case types.JsonFamily:
  1209  		switch m.t.Width() {
  1210  		case -1:
  1211  		default:
  1212  			fromCol := src.JSON()
  1213  			toCol := m.JSON()
  1214  			n := len(sel)
  1215  			_ = sel[n-1]
  1216  			if src.MaybeHasNulls() {
  1217  				nulls := src.Nulls()
  1218  				for i := 0; i < n; i++ {
  1219  					//gcassert:bce
  1220  					destIdx := sel[i]
  1221  					srcIdx := order[destIdx]
  1222  					if nulls.NullAt(srcIdx) {
  1223  						m.nulls.SetNull(destIdx)
  1224  					} else {
  1225  						toCol.Copy(fromCol, destIdx, srcIdx)
  1226  					}
  1227  				}
  1228  			} else {
  1229  				for i := 0; i < n; i++ {
  1230  					//gcassert:bce
  1231  					destIdx := sel[i]
  1232  					srcIdx := order[destIdx]
  1233  					{
  1234  						toCol.Copy(fromCol, destIdx, srcIdx)
  1235  					}
  1236  				}
  1237  			}
  1238  		}
  1239  	case typeconv.DatumVecCanonicalTypeFamily:
  1240  		switch m.t.Width() {
  1241  		case -1:
  1242  		default:
  1243  			fromCol := src.Datum()
  1244  			toCol := m.Datum()
  1245  			n := len(sel)
  1246  			_ = sel[n-1]
  1247  			if src.MaybeHasNulls() {
  1248  				nulls := src.Nulls()
  1249  				for i := 0; i < n; i++ {
  1250  					//gcassert:bce
  1251  					destIdx := sel[i]
  1252  					srcIdx := order[destIdx]
  1253  					if nulls.NullAt(srcIdx) {
  1254  						m.nulls.SetNull(destIdx)
  1255  					} else {
  1256  						v := fromCol.Get(srcIdx)
  1257  						toCol.Set(destIdx, v)
  1258  					}
  1259  				}
  1260  			} else {
  1261  				for i := 0; i < n; i++ {
  1262  					//gcassert:bce
  1263  					destIdx := sel[i]
  1264  					srcIdx := order[destIdx]
  1265  					{
  1266  						v := fromCol.Get(srcIdx)
  1267  						toCol.Set(destIdx, v)
  1268  					}
  1269  				}
  1270  			}
  1271  		}
  1272  	default:
  1273  		panic(fmt.Sprintf("unhandled type %s", m.t))
  1274  	}
  1275  }
  1276  
  1277  func (m *memColumn) Window(start int, end int) Vec {
  1278  	switch m.CanonicalTypeFamily() {
  1279  	case types.BoolFamily:
  1280  		switch m.t.Width() {
  1281  		case -1:
  1282  		default:
  1283  			col := m.Bool()
  1284  			return &memColumn{
  1285  				t:                   m.t,
  1286  				canonicalTypeFamily: m.canonicalTypeFamily,
  1287  				col:                 col.Window(start, end),
  1288  				nulls:               m.nulls.Slice(start, end),
  1289  			}
  1290  		}
  1291  	case types.BytesFamily:
  1292  		switch m.t.Width() {
  1293  		case -1:
  1294  		default:
  1295  			col := m.Bytes()
  1296  			return &memColumn{
  1297  				t:                   m.t,
  1298  				canonicalTypeFamily: m.canonicalTypeFamily,
  1299  				col:                 col.Window(start, end),
  1300  				nulls:               m.nulls.Slice(start, end),
  1301  			}
  1302  		}
  1303  	case types.DecimalFamily:
  1304  		switch m.t.Width() {
  1305  		case -1:
  1306  		default:
  1307  			col := m.Decimal()
  1308  			return &memColumn{
  1309  				t:                   m.t,
  1310  				canonicalTypeFamily: m.canonicalTypeFamily,
  1311  				col:                 col.Window(start, end),
  1312  				nulls:               m.nulls.Slice(start, end),
  1313  			}
  1314  		}
  1315  	case types.IntFamily:
  1316  		switch m.t.Width() {
  1317  		case 16:
  1318  			col := m.Int16()
  1319  			return &memColumn{
  1320  				t:                   m.t,
  1321  				canonicalTypeFamily: m.canonicalTypeFamily,
  1322  				col:                 col.Window(start, end),
  1323  				nulls:               m.nulls.Slice(start, end),
  1324  			}
  1325  		case 32:
  1326  			col := m.Int32()
  1327  			return &memColumn{
  1328  				t:                   m.t,
  1329  				canonicalTypeFamily: m.canonicalTypeFamily,
  1330  				col:                 col.Window(start, end),
  1331  				nulls:               m.nulls.Slice(start, end),
  1332  			}
  1333  		case -1:
  1334  		default:
  1335  			col := m.Int64()
  1336  			return &memColumn{
  1337  				t:                   m.t,
  1338  				canonicalTypeFamily: m.canonicalTypeFamily,
  1339  				col:                 col.Window(start, end),
  1340  				nulls:               m.nulls.Slice(start, end),
  1341  			}
  1342  		}
  1343  	case types.FloatFamily:
  1344  		switch m.t.Width() {
  1345  		case -1:
  1346  		default:
  1347  			col := m.Float64()
  1348  			return &memColumn{
  1349  				t:                   m.t,
  1350  				canonicalTypeFamily: m.canonicalTypeFamily,
  1351  				col:                 col.Window(start, end),
  1352  				nulls:               m.nulls.Slice(start, end),
  1353  			}
  1354  		}
  1355  	case types.TimestampTZFamily:
  1356  		switch m.t.Width() {
  1357  		case -1:
  1358  		default:
  1359  			col := m.Timestamp()
  1360  			return &memColumn{
  1361  				t:                   m.t,
  1362  				canonicalTypeFamily: m.canonicalTypeFamily,
  1363  				col:                 col.Window(start, end),
  1364  				nulls:               m.nulls.Slice(start, end),
  1365  			}
  1366  		}
  1367  	case types.IntervalFamily:
  1368  		switch m.t.Width() {
  1369  		case -1:
  1370  		default:
  1371  			col := m.Interval()
  1372  			return &memColumn{
  1373  				t:                   m.t,
  1374  				canonicalTypeFamily: m.canonicalTypeFamily,
  1375  				col:                 col.Window(start, end),
  1376  				nulls:               m.nulls.Slice(start, end),
  1377  			}
  1378  		}
  1379  	case types.JsonFamily:
  1380  		switch m.t.Width() {
  1381  		case -1:
  1382  		default:
  1383  			col := m.JSON()
  1384  			return &memColumn{
  1385  				t:                   m.t,
  1386  				canonicalTypeFamily: m.canonicalTypeFamily,
  1387  				col:                 col.Window(start, end),
  1388  				nulls:               m.nulls.Slice(start, end),
  1389  			}
  1390  		}
  1391  	case typeconv.DatumVecCanonicalTypeFamily:
  1392  		switch m.t.Width() {
  1393  		case -1:
  1394  		default:
  1395  			col := m.Datum()
  1396  			return &memColumn{
  1397  				t:                   m.t,
  1398  				canonicalTypeFamily: m.canonicalTypeFamily,
  1399  				col:                 col.Window(start, end),
  1400  				nulls:               m.nulls.Slice(start, end),
  1401  			}
  1402  		}
  1403  	}
  1404  	panic(fmt.Sprintf("unhandled type %s", m.t))
  1405  }
  1406  
  1407  // SetValueAt is an inefficient helper to set the value in a Vec when the type
  1408  // is unknown.
  1409  func SetValueAt(v Vec, elem interface{}, rowIdx int) {
  1410  	switch t := v.Type(); v.CanonicalTypeFamily() {
  1411  	case types.BoolFamily:
  1412  		switch t.Width() {
  1413  		case -1:
  1414  		default:
  1415  			target := v.Bool()
  1416  			newVal := elem.(bool)
  1417  			target.Set(rowIdx, newVal)
  1418  		}
  1419  	case types.BytesFamily:
  1420  		switch t.Width() {
  1421  		case -1:
  1422  		default:
  1423  			target := v.Bytes()
  1424  			newVal := elem.([]byte)
  1425  			target.Set(rowIdx, newVal)
  1426  		}
  1427  	case types.DecimalFamily:
  1428  		switch t.Width() {
  1429  		case -1:
  1430  		default:
  1431  			target := v.Decimal()
  1432  			newVal := elem.(apd.Decimal)
  1433  			target.Set(rowIdx, newVal)
  1434  		}
  1435  	case types.IntFamily:
  1436  		switch t.Width() {
  1437  		case 16:
  1438  			target := v.Int16()
  1439  			newVal := elem.(int16)
  1440  			target.Set(rowIdx, newVal)
  1441  		case 32:
  1442  			target := v.Int32()
  1443  			newVal := elem.(int32)
  1444  			target.Set(rowIdx, newVal)
  1445  		case -1:
  1446  		default:
  1447  			target := v.Int64()
  1448  			newVal := elem.(int64)
  1449  			target.Set(rowIdx, newVal)
  1450  		}
  1451  	case types.FloatFamily:
  1452  		switch t.Width() {
  1453  		case -1:
  1454  		default:
  1455  			target := v.Float64()
  1456  			newVal := elem.(float64)
  1457  			target.Set(rowIdx, newVal)
  1458  		}
  1459  	case types.TimestampTZFamily:
  1460  		switch t.Width() {
  1461  		case -1:
  1462  		default:
  1463  			target := v.Timestamp()
  1464  			newVal := elem.(time.Time)
  1465  			target.Set(rowIdx, newVal)
  1466  		}
  1467  	case types.IntervalFamily:
  1468  		switch t.Width() {
  1469  		case -1:
  1470  		default:
  1471  			target := v.Interval()
  1472  			newVal := elem.(duration.Duration)
  1473  			target.Set(rowIdx, newVal)
  1474  		}
  1475  	case types.JsonFamily:
  1476  		switch t.Width() {
  1477  		case -1:
  1478  		default:
  1479  			target := v.JSON()
  1480  			newVal := elem.(json.JSON)
  1481  			target.Set(rowIdx, newVal)
  1482  		}
  1483  	case typeconv.DatumVecCanonicalTypeFamily:
  1484  		switch t.Width() {
  1485  		case -1:
  1486  		default:
  1487  			target := v.Datum()
  1488  			newVal := elem.(interface{})
  1489  			target.Set(rowIdx, newVal)
  1490  		}
  1491  	default:
  1492  		panic(fmt.Sprintf("unhandled type %s", t))
  1493  	}
  1494  }
  1495  
  1496  // GetValueAt is an inefficient helper to get the value in a Vec when the type
  1497  // is unknown.
  1498  func GetValueAt(v Vec, rowIdx int) interface{} {
  1499  	if v.Nulls().NullAt(rowIdx) {
  1500  		return nil
  1501  	}
  1502  	t := v.Type()
  1503  	switch v.CanonicalTypeFamily() {
  1504  	case types.BoolFamily:
  1505  		switch t.Width() {
  1506  		case -1:
  1507  		default:
  1508  			target := v.Bool()
  1509  			return target.Get(rowIdx)
  1510  		}
  1511  	case types.BytesFamily:
  1512  		switch t.Width() {
  1513  		case -1:
  1514  		default:
  1515  			target := v.Bytes()
  1516  			return target.Get(rowIdx)
  1517  		}
  1518  	case types.DecimalFamily:
  1519  		switch t.Width() {
  1520  		case -1:
  1521  		default:
  1522  			target := v.Decimal()
  1523  			return target.Get(rowIdx)
  1524  		}
  1525  	case types.IntFamily:
  1526  		switch t.Width() {
  1527  		case 16:
  1528  			target := v.Int16()
  1529  			return target.Get(rowIdx)
  1530  		case 32:
  1531  			target := v.Int32()
  1532  			return target.Get(rowIdx)
  1533  		case -1:
  1534  		default:
  1535  			target := v.Int64()
  1536  			return target.Get(rowIdx)
  1537  		}
  1538  	case types.FloatFamily:
  1539  		switch t.Width() {
  1540  		case -1:
  1541  		default:
  1542  			target := v.Float64()
  1543  			return target.Get(rowIdx)
  1544  		}
  1545  	case types.TimestampTZFamily:
  1546  		switch t.Width() {
  1547  		case -1:
  1548  		default:
  1549  			target := v.Timestamp()
  1550  			return target.Get(rowIdx)
  1551  		}
  1552  	case types.IntervalFamily:
  1553  		switch t.Width() {
  1554  		case -1:
  1555  		default:
  1556  			target := v.Interval()
  1557  			return target.Get(rowIdx)
  1558  		}
  1559  	case types.JsonFamily:
  1560  		switch t.Width() {
  1561  		case -1:
  1562  		default:
  1563  			target := v.JSON()
  1564  			return target.Get(rowIdx)
  1565  		}
  1566  	case typeconv.DatumVecCanonicalTypeFamily:
  1567  		switch t.Width() {
  1568  		case -1:
  1569  		default:
  1570  			target := v.Datum()
  1571  			return target.Get(rowIdx)
  1572  		}
  1573  	}
  1574  	panic(fmt.Sprintf("unhandled type %s", t))
  1575  }