github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/entity/columns_scalar_gen_test.go (about)

     1  // Code generated by go generate; DO NOT EDIT
     2  // This file is generated by go generated 
     3  
     4  package entity 
     5  
     6  import (
     7  	"fmt"
     8  	"math/rand"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  	schema "github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
    14  )
    15  
    16  func TestColumnBool(t *testing.T) {
    17  	rand.Seed(time.Now().UnixNano())
    18  	columnName := fmt.Sprintf("column_Bool_%d", rand.Int())
    19  	columnLen := 8 + rand.Intn(10)
    20  
    21  	v := make([]bool, columnLen)
    22  	column := NewColumnBool(columnName, v)
    23  
    24  	t.Run("test meta", func(t *testing.T) {
    25  		ft := FieldTypeBool
    26  		assert.Equal(t, "Bool", ft.Name())
    27  		assert.Equal(t, "bool", ft.String())
    28  		pbName, pbType := ft.PbFieldType()
    29  		assert.Equal(t, "Bool", pbName)
    30  		assert.Equal(t, "bool", pbType)
    31  	})
    32  
    33  	t.Run("test column attribute", func(t *testing.T) {
    34  		assert.Equal(t, columnName, column.Name())
    35  		assert.Equal(t, FieldTypeBool, column.Type())
    36  		assert.Equal(t, columnLen, column.Len())
    37  		assert.EqualValues(t, v, column.Data())
    38  	})
    39  
    40  	t.Run("test column field data", func(t *testing.T) {
    41  		fd := column.FieldData()
    42  		assert.NotNil(t, fd)
    43  		assert.Equal(t, fd.GetFieldName(), columnName)
    44  	})
    45  
    46  	t.Run("test column value by idx", func(t *testing.T) {
    47  		_, err := column.ValueByIdx(-1)
    48  		assert.NotNil(t, err)
    49  		_, err = column.ValueByIdx(columnLen)
    50  		assert.NotNil(t, err)
    51  		for i := 0; i < columnLen; i++ {
    52  			v, err := column.ValueByIdx(i)
    53  			assert.Nil(t, err)
    54  			assert.Equal(t, column.values[i], v)
    55  		}
    56  	})
    57  }
    58  
    59  func TestFieldDataBoolColumn(t *testing.T) {
    60  	len := rand.Intn(10) + 8
    61  	name := fmt.Sprintf("fd_Bool_%d", rand.Int())
    62  	fd := &schema.FieldData{
    63  		Type: schema.DataType_Bool,
    64  		FieldName: name,
    65  	}
    66  
    67  	t.Run("normal usage", func(t *testing.T) {
    68  		fd.Field = &schema.FieldData_Scalars{
    69  			Scalars: &schema.ScalarField{
    70  				Data: &schema.ScalarField_BoolData{
    71  					BoolData: &schema.BoolArray{
    72  						Data: make([]bool, len),
    73  					},
    74  				},
    75  			},
    76  		}
    77  		column, err := FieldDataColumn(fd, 0, len)
    78  		assert.Nil(t, err)
    79  		assert.NotNil(t, column)
    80   
    81  		assert.Equal(t, name, column.Name())
    82  		assert.Equal(t, len, column.Len())
    83  		assert.Equal(t, FieldTypeBool, column.Type())
    84  
    85  		var ev bool
    86  		err = column.AppendValue(ev)
    87  		assert.Equal(t, len+1, column.Len())
    88  		assert.Nil(t, err)
    89  
    90  		err = column.AppendValue(struct{}{})
    91  		assert.Equal(t, len+1, column.Len())
    92  		assert.NotNil(t, err)
    93  	})
    94  
    95  	
    96  	t.Run("nil data", func(t *testing.T) {
    97  		fd.Field = nil
    98  		_, err := FieldDataColumn(fd, 0, len)
    99  		assert.NotNil(t, err)
   100  	})
   101  	
   102  	t.Run("get all data", func(t *testing.T) {
   103  		fd.Field = &schema.FieldData_Scalars{
   104  			Scalars: &schema.ScalarField{
   105  				Data: &schema.ScalarField_BoolData{
   106  					BoolData: &schema.BoolArray{
   107  						Data: make([]bool, len),
   108  					},
   109  				},
   110  			},
   111  		}
   112  		column, err := FieldDataColumn(fd, 0, -1)
   113  		assert.Nil(t, err)
   114  		assert.NotNil(t, column)
   115  		
   116  		assert.Equal(t, name, column.Name())
   117  		assert.Equal(t, len, column.Len())
   118  		assert.Equal(t, FieldTypeBool, column.Type())
   119  	})
   120  }
   121  
   122  func TestColumnInt8(t *testing.T) {
   123  	rand.Seed(time.Now().UnixNano())
   124  	columnName := fmt.Sprintf("column_Int8_%d", rand.Int())
   125  	columnLen := 8 + rand.Intn(10)
   126  
   127  	v := make([]int8, columnLen)
   128  	column := NewColumnInt8(columnName, v)
   129  
   130  	t.Run("test meta", func(t *testing.T) {
   131  		ft := FieldTypeInt8
   132  		assert.Equal(t, "Int8", ft.Name())
   133  		assert.Equal(t, "int8", ft.String())
   134  		pbName, pbType := ft.PbFieldType()
   135  		assert.Equal(t, "Int", pbName)
   136  		assert.Equal(t, "int32", pbType)
   137  	})
   138  
   139  	t.Run("test column attribute", func(t *testing.T) {
   140  		assert.Equal(t, columnName, column.Name())
   141  		assert.Equal(t, FieldTypeInt8, column.Type())
   142  		assert.Equal(t, columnLen, column.Len())
   143  		assert.EqualValues(t, v, column.Data())
   144  	})
   145  
   146  	t.Run("test column field data", func(t *testing.T) {
   147  		fd := column.FieldData()
   148  		assert.NotNil(t, fd)
   149  		assert.Equal(t, fd.GetFieldName(), columnName)
   150  	})
   151  
   152  	t.Run("test column value by idx", func(t *testing.T) {
   153  		_, err := column.ValueByIdx(-1)
   154  		assert.NotNil(t, err)
   155  		_, err = column.ValueByIdx(columnLen)
   156  		assert.NotNil(t, err)
   157  		for i := 0; i < columnLen; i++ {
   158  			v, err := column.ValueByIdx(i)
   159  			assert.Nil(t, err)
   160  			assert.Equal(t, column.values[i], v)
   161  		}
   162  	})
   163  }
   164  
   165  func TestFieldDataInt8Column(t *testing.T) {
   166  	len := rand.Intn(10) + 8
   167  	name := fmt.Sprintf("fd_Int8_%d", rand.Int())
   168  	fd := &schema.FieldData{
   169  		Type: schema.DataType_Int8,
   170  		FieldName: name,
   171  	}
   172  
   173  	t.Run("normal usage", func(t *testing.T) {
   174  		fd.Field = &schema.FieldData_Scalars{
   175  			Scalars: &schema.ScalarField{
   176  				Data: &schema.ScalarField_IntData{
   177  					IntData: &schema.IntArray{
   178  						Data: make([]int32, len),
   179  					},
   180  				},
   181  			},
   182  		}
   183  		column, err := FieldDataColumn(fd, 0, len)
   184  		assert.Nil(t, err)
   185  		assert.NotNil(t, column)
   186   
   187  		assert.Equal(t, name, column.Name())
   188  		assert.Equal(t, len, column.Len())
   189  		assert.Equal(t, FieldTypeInt8, column.Type())
   190  
   191  		var ev int8
   192  		err = column.AppendValue(ev)
   193  		assert.Equal(t, len+1, column.Len())
   194  		assert.Nil(t, err)
   195  
   196  		err = column.AppendValue(struct{}{})
   197  		assert.Equal(t, len+1, column.Len())
   198  		assert.NotNil(t, err)
   199  	})
   200  
   201  	
   202  	t.Run("nil data", func(t *testing.T) {
   203  		fd.Field = nil
   204  		_, err := FieldDataColumn(fd, 0, len)
   205  		assert.NotNil(t, err)
   206  	})
   207  	
   208  	t.Run("get all data", func(t *testing.T) {
   209  		fd.Field = &schema.FieldData_Scalars{
   210  			Scalars: &schema.ScalarField{
   211  				Data: &schema.ScalarField_IntData{
   212  					IntData: &schema.IntArray{
   213  						Data: make([]int32, len),
   214  					},
   215  				},
   216  			},
   217  		}
   218  		column, err := FieldDataColumn(fd, 0, -1)
   219  		assert.Nil(t, err)
   220  		assert.NotNil(t, column)
   221  		
   222  		assert.Equal(t, name, column.Name())
   223  		assert.Equal(t, len, column.Len())
   224  		assert.Equal(t, FieldTypeInt8, column.Type())
   225  	})
   226  }
   227  
   228  func TestColumnInt16(t *testing.T) {
   229  	rand.Seed(time.Now().UnixNano())
   230  	columnName := fmt.Sprintf("column_Int16_%d", rand.Int())
   231  	columnLen := 8 + rand.Intn(10)
   232  
   233  	v := make([]int16, columnLen)
   234  	column := NewColumnInt16(columnName, v)
   235  
   236  	t.Run("test meta", func(t *testing.T) {
   237  		ft := FieldTypeInt16
   238  		assert.Equal(t, "Int16", ft.Name())
   239  		assert.Equal(t, "int16", ft.String())
   240  		pbName, pbType := ft.PbFieldType()
   241  		assert.Equal(t, "Int", pbName)
   242  		assert.Equal(t, "int32", pbType)
   243  	})
   244  
   245  	t.Run("test column attribute", func(t *testing.T) {
   246  		assert.Equal(t, columnName, column.Name())
   247  		assert.Equal(t, FieldTypeInt16, column.Type())
   248  		assert.Equal(t, columnLen, column.Len())
   249  		assert.EqualValues(t, v, column.Data())
   250  	})
   251  
   252  	t.Run("test column field data", func(t *testing.T) {
   253  		fd := column.FieldData()
   254  		assert.NotNil(t, fd)
   255  		assert.Equal(t, fd.GetFieldName(), columnName)
   256  	})
   257  
   258  	t.Run("test column value by idx", func(t *testing.T) {
   259  		_, err := column.ValueByIdx(-1)
   260  		assert.NotNil(t, err)
   261  		_, err = column.ValueByIdx(columnLen)
   262  		assert.NotNil(t, err)
   263  		for i := 0; i < columnLen; i++ {
   264  			v, err := column.ValueByIdx(i)
   265  			assert.Nil(t, err)
   266  			assert.Equal(t, column.values[i], v)
   267  		}
   268  	})
   269  }
   270  
   271  func TestFieldDataInt16Column(t *testing.T) {
   272  	len := rand.Intn(10) + 8
   273  	name := fmt.Sprintf("fd_Int16_%d", rand.Int())
   274  	fd := &schema.FieldData{
   275  		Type: schema.DataType_Int16,
   276  		FieldName: name,
   277  	}
   278  
   279  	t.Run("normal usage", func(t *testing.T) {
   280  		fd.Field = &schema.FieldData_Scalars{
   281  			Scalars: &schema.ScalarField{
   282  				Data: &schema.ScalarField_IntData{
   283  					IntData: &schema.IntArray{
   284  						Data: make([]int32, len),
   285  					},
   286  				},
   287  			},
   288  		}
   289  		column, err := FieldDataColumn(fd, 0, len)
   290  		assert.Nil(t, err)
   291  		assert.NotNil(t, column)
   292   
   293  		assert.Equal(t, name, column.Name())
   294  		assert.Equal(t, len, column.Len())
   295  		assert.Equal(t, FieldTypeInt16, column.Type())
   296  
   297  		var ev int16
   298  		err = column.AppendValue(ev)
   299  		assert.Equal(t, len+1, column.Len())
   300  		assert.Nil(t, err)
   301  
   302  		err = column.AppendValue(struct{}{})
   303  		assert.Equal(t, len+1, column.Len())
   304  		assert.NotNil(t, err)
   305  	})
   306  
   307  	
   308  	t.Run("nil data", func(t *testing.T) {
   309  		fd.Field = nil
   310  		_, err := FieldDataColumn(fd, 0, len)
   311  		assert.NotNil(t, err)
   312  	})
   313  	
   314  	t.Run("get all data", func(t *testing.T) {
   315  		fd.Field = &schema.FieldData_Scalars{
   316  			Scalars: &schema.ScalarField{
   317  				Data: &schema.ScalarField_IntData{
   318  					IntData: &schema.IntArray{
   319  						Data: make([]int32, len),
   320  					},
   321  				},
   322  			},
   323  		}
   324  		column, err := FieldDataColumn(fd, 0, -1)
   325  		assert.Nil(t, err)
   326  		assert.NotNil(t, column)
   327  		
   328  		assert.Equal(t, name, column.Name())
   329  		assert.Equal(t, len, column.Len())
   330  		assert.Equal(t, FieldTypeInt16, column.Type())
   331  	})
   332  }
   333  
   334  func TestColumnInt32(t *testing.T) {
   335  	rand.Seed(time.Now().UnixNano())
   336  	columnName := fmt.Sprintf("column_Int32_%d", rand.Int())
   337  	columnLen := 8 + rand.Intn(10)
   338  
   339  	v := make([]int32, columnLen)
   340  	column := NewColumnInt32(columnName, v)
   341  
   342  	t.Run("test meta", func(t *testing.T) {
   343  		ft := FieldTypeInt32
   344  		assert.Equal(t, "Int32", ft.Name())
   345  		assert.Equal(t, "int32", ft.String())
   346  		pbName, pbType := ft.PbFieldType()
   347  		assert.Equal(t, "Int", pbName)
   348  		assert.Equal(t, "int32", pbType)
   349  	})
   350  
   351  	t.Run("test column attribute", func(t *testing.T) {
   352  		assert.Equal(t, columnName, column.Name())
   353  		assert.Equal(t, FieldTypeInt32, column.Type())
   354  		assert.Equal(t, columnLen, column.Len())
   355  		assert.EqualValues(t, v, column.Data())
   356  	})
   357  
   358  	t.Run("test column field data", func(t *testing.T) {
   359  		fd := column.FieldData()
   360  		assert.NotNil(t, fd)
   361  		assert.Equal(t, fd.GetFieldName(), columnName)
   362  	})
   363  
   364  	t.Run("test column value by idx", func(t *testing.T) {
   365  		_, err := column.ValueByIdx(-1)
   366  		assert.NotNil(t, err)
   367  		_, err = column.ValueByIdx(columnLen)
   368  		assert.NotNil(t, err)
   369  		for i := 0; i < columnLen; i++ {
   370  			v, err := column.ValueByIdx(i)
   371  			assert.Nil(t, err)
   372  			assert.Equal(t, column.values[i], v)
   373  		}
   374  	})
   375  }
   376  
   377  func TestFieldDataInt32Column(t *testing.T) {
   378  	len := rand.Intn(10) + 8
   379  	name := fmt.Sprintf("fd_Int32_%d", rand.Int())
   380  	fd := &schema.FieldData{
   381  		Type: schema.DataType_Int32,
   382  		FieldName: name,
   383  	}
   384  
   385  	t.Run("normal usage", func(t *testing.T) {
   386  		fd.Field = &schema.FieldData_Scalars{
   387  			Scalars: &schema.ScalarField{
   388  				Data: &schema.ScalarField_IntData{
   389  					IntData: &schema.IntArray{
   390  						Data: make([]int32, len),
   391  					},
   392  				},
   393  			},
   394  		}
   395  		column, err := FieldDataColumn(fd, 0, len)
   396  		assert.Nil(t, err)
   397  		assert.NotNil(t, column)
   398   
   399  		assert.Equal(t, name, column.Name())
   400  		assert.Equal(t, len, column.Len())
   401  		assert.Equal(t, FieldTypeInt32, column.Type())
   402  
   403  		var ev int32
   404  		err = column.AppendValue(ev)
   405  		assert.Equal(t, len+1, column.Len())
   406  		assert.Nil(t, err)
   407  
   408  		err = column.AppendValue(struct{}{})
   409  		assert.Equal(t, len+1, column.Len())
   410  		assert.NotNil(t, err)
   411  	})
   412  
   413  	
   414  	t.Run("nil data", func(t *testing.T) {
   415  		fd.Field = nil
   416  		_, err := FieldDataColumn(fd, 0, len)
   417  		assert.NotNil(t, err)
   418  	})
   419  	
   420  	t.Run("get all data", func(t *testing.T) {
   421  		fd.Field = &schema.FieldData_Scalars{
   422  			Scalars: &schema.ScalarField{
   423  				Data: &schema.ScalarField_IntData{
   424  					IntData: &schema.IntArray{
   425  						Data: make([]int32, len),
   426  					},
   427  				},
   428  			},
   429  		}
   430  		column, err := FieldDataColumn(fd, 0, -1)
   431  		assert.Nil(t, err)
   432  		assert.NotNil(t, column)
   433  		
   434  		assert.Equal(t, name, column.Name())
   435  		assert.Equal(t, len, column.Len())
   436  		assert.Equal(t, FieldTypeInt32, column.Type())
   437  	})
   438  }
   439  
   440  func TestColumnInt64(t *testing.T) {
   441  	rand.Seed(time.Now().UnixNano())
   442  	columnName := fmt.Sprintf("column_Int64_%d", rand.Int())
   443  	columnLen := 8 + rand.Intn(10)
   444  
   445  	v := make([]int64, columnLen)
   446  	column := NewColumnInt64(columnName, v)
   447  
   448  	t.Run("test meta", func(t *testing.T) {
   449  		ft := FieldTypeInt64
   450  		assert.Equal(t, "Int64", ft.Name())
   451  		assert.Equal(t, "int64", ft.String())
   452  		pbName, pbType := ft.PbFieldType()
   453  		assert.Equal(t, "Long", pbName)
   454  		assert.Equal(t, "int64", pbType)
   455  	})
   456  
   457  	t.Run("test column attribute", func(t *testing.T) {
   458  		assert.Equal(t, columnName, column.Name())
   459  		assert.Equal(t, FieldTypeInt64, column.Type())
   460  		assert.Equal(t, columnLen, column.Len())
   461  		assert.EqualValues(t, v, column.Data())
   462  	})
   463  
   464  	t.Run("test column field data", func(t *testing.T) {
   465  		fd := column.FieldData()
   466  		assert.NotNil(t, fd)
   467  		assert.Equal(t, fd.GetFieldName(), columnName)
   468  	})
   469  
   470  	t.Run("test column value by idx", func(t *testing.T) {
   471  		_, err := column.ValueByIdx(-1)
   472  		assert.NotNil(t, err)
   473  		_, err = column.ValueByIdx(columnLen)
   474  		assert.NotNil(t, err)
   475  		for i := 0; i < columnLen; i++ {
   476  			v, err := column.ValueByIdx(i)
   477  			assert.Nil(t, err)
   478  			assert.Equal(t, column.values[i], v)
   479  		}
   480  	})
   481  }
   482  
   483  func TestFieldDataInt64Column(t *testing.T) {
   484  	len := rand.Intn(10) + 8
   485  	name := fmt.Sprintf("fd_Int64_%d", rand.Int())
   486  	fd := &schema.FieldData{
   487  		Type: schema.DataType_Int64,
   488  		FieldName: name,
   489  	}
   490  
   491  	t.Run("normal usage", func(t *testing.T) {
   492  		fd.Field = &schema.FieldData_Scalars{
   493  			Scalars: &schema.ScalarField{
   494  				Data: &schema.ScalarField_LongData{
   495  					LongData: &schema.LongArray{
   496  						Data: make([]int64, len),
   497  					},
   498  				},
   499  			},
   500  		}
   501  		column, err := FieldDataColumn(fd, 0, len)
   502  		assert.Nil(t, err)
   503  		assert.NotNil(t, column)
   504   
   505  		assert.Equal(t, name, column.Name())
   506  		assert.Equal(t, len, column.Len())
   507  		assert.Equal(t, FieldTypeInt64, column.Type())
   508  
   509  		var ev int64
   510  		err = column.AppendValue(ev)
   511  		assert.Equal(t, len+1, column.Len())
   512  		assert.Nil(t, err)
   513  
   514  		err = column.AppendValue(struct{}{})
   515  		assert.Equal(t, len+1, column.Len())
   516  		assert.NotNil(t, err)
   517  	})
   518  
   519  	
   520  	t.Run("nil data", func(t *testing.T) {
   521  		fd.Field = nil
   522  		_, err := FieldDataColumn(fd, 0, len)
   523  		assert.NotNil(t, err)
   524  	})
   525  	
   526  	t.Run("get all data", func(t *testing.T) {
   527  		fd.Field = &schema.FieldData_Scalars{
   528  			Scalars: &schema.ScalarField{
   529  				Data: &schema.ScalarField_LongData{
   530  					LongData: &schema.LongArray{
   531  						Data: make([]int64, len),
   532  					},
   533  				},
   534  			},
   535  		}
   536  		column, err := FieldDataColumn(fd, 0, -1)
   537  		assert.Nil(t, err)
   538  		assert.NotNil(t, column)
   539  		
   540  		assert.Equal(t, name, column.Name())
   541  		assert.Equal(t, len, column.Len())
   542  		assert.Equal(t, FieldTypeInt64, column.Type())
   543  	})
   544  }
   545  
   546  func TestColumnFloat(t *testing.T) {
   547  	rand.Seed(time.Now().UnixNano())
   548  	columnName := fmt.Sprintf("column_Float_%d", rand.Int())
   549  	columnLen := 8 + rand.Intn(10)
   550  
   551  	v := make([]float32, columnLen)
   552  	column := NewColumnFloat(columnName, v)
   553  
   554  	t.Run("test meta", func(t *testing.T) {
   555  		ft := FieldTypeFloat
   556  		assert.Equal(t, "Float", ft.Name())
   557  		assert.Equal(t, "float32", ft.String())
   558  		pbName, pbType := ft.PbFieldType()
   559  		assert.Equal(t, "Float", pbName)
   560  		assert.Equal(t, "float32", pbType)
   561  	})
   562  
   563  	t.Run("test column attribute", func(t *testing.T) {
   564  		assert.Equal(t, columnName, column.Name())
   565  		assert.Equal(t, FieldTypeFloat, column.Type())
   566  		assert.Equal(t, columnLen, column.Len())
   567  		assert.EqualValues(t, v, column.Data())
   568  	})
   569  
   570  	t.Run("test column field data", func(t *testing.T) {
   571  		fd := column.FieldData()
   572  		assert.NotNil(t, fd)
   573  		assert.Equal(t, fd.GetFieldName(), columnName)
   574  	})
   575  
   576  	t.Run("test column value by idx", func(t *testing.T) {
   577  		_, err := column.ValueByIdx(-1)
   578  		assert.NotNil(t, err)
   579  		_, err = column.ValueByIdx(columnLen)
   580  		assert.NotNil(t, err)
   581  		for i := 0; i < columnLen; i++ {
   582  			v, err := column.ValueByIdx(i)
   583  			assert.Nil(t, err)
   584  			assert.Equal(t, column.values[i], v)
   585  		}
   586  	})
   587  }
   588  
   589  func TestFieldDataFloatColumn(t *testing.T) {
   590  	len := rand.Intn(10) + 8
   591  	name := fmt.Sprintf("fd_Float_%d", rand.Int())
   592  	fd := &schema.FieldData{
   593  		Type: schema.DataType_Float,
   594  		FieldName: name,
   595  	}
   596  
   597  	t.Run("normal usage", func(t *testing.T) {
   598  		fd.Field = &schema.FieldData_Scalars{
   599  			Scalars: &schema.ScalarField{
   600  				Data: &schema.ScalarField_FloatData{
   601  					FloatData: &schema.FloatArray{
   602  						Data: make([]float32, len),
   603  					},
   604  				},
   605  			},
   606  		}
   607  		column, err := FieldDataColumn(fd, 0, len)
   608  		assert.Nil(t, err)
   609  		assert.NotNil(t, column)
   610   
   611  		assert.Equal(t, name, column.Name())
   612  		assert.Equal(t, len, column.Len())
   613  		assert.Equal(t, FieldTypeFloat, column.Type())
   614  
   615  		var ev float32
   616  		err = column.AppendValue(ev)
   617  		assert.Equal(t, len+1, column.Len())
   618  		assert.Nil(t, err)
   619  
   620  		err = column.AppendValue(struct{}{})
   621  		assert.Equal(t, len+1, column.Len())
   622  		assert.NotNil(t, err)
   623  	})
   624  
   625  	
   626  	t.Run("nil data", func(t *testing.T) {
   627  		fd.Field = nil
   628  		_, err := FieldDataColumn(fd, 0, len)
   629  		assert.NotNil(t, err)
   630  	})
   631  	
   632  	t.Run("get all data", func(t *testing.T) {
   633  		fd.Field = &schema.FieldData_Scalars{
   634  			Scalars: &schema.ScalarField{
   635  				Data: &schema.ScalarField_FloatData{
   636  					FloatData: &schema.FloatArray{
   637  						Data: make([]float32, len),
   638  					},
   639  				},
   640  			},
   641  		}
   642  		column, err := FieldDataColumn(fd, 0, -1)
   643  		assert.Nil(t, err)
   644  		assert.NotNil(t, column)
   645  		
   646  		assert.Equal(t, name, column.Name())
   647  		assert.Equal(t, len, column.Len())
   648  		assert.Equal(t, FieldTypeFloat, column.Type())
   649  	})
   650  }
   651  
   652  func TestColumnDouble(t *testing.T) {
   653  	rand.Seed(time.Now().UnixNano())
   654  	columnName := fmt.Sprintf("column_Double_%d", rand.Int())
   655  	columnLen := 8 + rand.Intn(10)
   656  
   657  	v := make([]float64, columnLen)
   658  	column := NewColumnDouble(columnName, v)
   659  
   660  	t.Run("test meta", func(t *testing.T) {
   661  		ft := FieldTypeDouble
   662  		assert.Equal(t, "Double", ft.Name())
   663  		assert.Equal(t, "float64", ft.String())
   664  		pbName, pbType := ft.PbFieldType()
   665  		assert.Equal(t, "Double", pbName)
   666  		assert.Equal(t, "float64", pbType)
   667  	})
   668  
   669  	t.Run("test column attribute", func(t *testing.T) {
   670  		assert.Equal(t, columnName, column.Name())
   671  		assert.Equal(t, FieldTypeDouble, column.Type())
   672  		assert.Equal(t, columnLen, column.Len())
   673  		assert.EqualValues(t, v, column.Data())
   674  	})
   675  
   676  	t.Run("test column field data", func(t *testing.T) {
   677  		fd := column.FieldData()
   678  		assert.NotNil(t, fd)
   679  		assert.Equal(t, fd.GetFieldName(), columnName)
   680  	})
   681  
   682  	t.Run("test column value by idx", func(t *testing.T) {
   683  		_, err := column.ValueByIdx(-1)
   684  		assert.NotNil(t, err)
   685  		_, err = column.ValueByIdx(columnLen)
   686  		assert.NotNil(t, err)
   687  		for i := 0; i < columnLen; i++ {
   688  			v, err := column.ValueByIdx(i)
   689  			assert.Nil(t, err)
   690  			assert.Equal(t, column.values[i], v)
   691  		}
   692  	})
   693  }
   694  
   695  func TestFieldDataDoubleColumn(t *testing.T) {
   696  	len := rand.Intn(10) + 8
   697  	name := fmt.Sprintf("fd_Double_%d", rand.Int())
   698  	fd := &schema.FieldData{
   699  		Type: schema.DataType_Double,
   700  		FieldName: name,
   701  	}
   702  
   703  	t.Run("normal usage", func(t *testing.T) {
   704  		fd.Field = &schema.FieldData_Scalars{
   705  			Scalars: &schema.ScalarField{
   706  				Data: &schema.ScalarField_DoubleData{
   707  					DoubleData: &schema.DoubleArray{
   708  						Data: make([]float64, len),
   709  					},
   710  				},
   711  			},
   712  		}
   713  		column, err := FieldDataColumn(fd, 0, len)
   714  		assert.Nil(t, err)
   715  		assert.NotNil(t, column)
   716   
   717  		assert.Equal(t, name, column.Name())
   718  		assert.Equal(t, len, column.Len())
   719  		assert.Equal(t, FieldTypeDouble, column.Type())
   720  
   721  		var ev float64
   722  		err = column.AppendValue(ev)
   723  		assert.Equal(t, len+1, column.Len())
   724  		assert.Nil(t, err)
   725  
   726  		err = column.AppendValue(struct{}{})
   727  		assert.Equal(t, len+1, column.Len())
   728  		assert.NotNil(t, err)
   729  	})
   730  
   731  	
   732  	t.Run("nil data", func(t *testing.T) {
   733  		fd.Field = nil
   734  		_, err := FieldDataColumn(fd, 0, len)
   735  		assert.NotNil(t, err)
   736  	})
   737  	
   738  	t.Run("get all data", func(t *testing.T) {
   739  		fd.Field = &schema.FieldData_Scalars{
   740  			Scalars: &schema.ScalarField{
   741  				Data: &schema.ScalarField_DoubleData{
   742  					DoubleData: &schema.DoubleArray{
   743  						Data: make([]float64, len),
   744  					},
   745  				},
   746  			},
   747  		}
   748  		column, err := FieldDataColumn(fd, 0, -1)
   749  		assert.Nil(t, err)
   750  		assert.NotNil(t, column)
   751  		
   752  		assert.Equal(t, name, column.Name())
   753  		assert.Equal(t, len, column.Len())
   754  		assert.Equal(t, FieldTypeDouble, column.Type())
   755  	})
   756  }
   757  
   758  func TestColumnString(t *testing.T) {
   759  	rand.Seed(time.Now().UnixNano())
   760  	columnName := fmt.Sprintf("column_String_%d", rand.Int())
   761  	columnLen := 8 + rand.Intn(10)
   762  
   763  	v := make([]string, columnLen)
   764  	column := NewColumnString(columnName, v)
   765  
   766  	t.Run("test meta", func(t *testing.T) {
   767  		ft := FieldTypeString
   768  		assert.Equal(t, "String", ft.Name())
   769  		assert.Equal(t, "string", ft.String())
   770  		pbName, pbType := ft.PbFieldType()
   771  		assert.Equal(t, "String", pbName)
   772  		assert.Equal(t, "string", pbType)
   773  	})
   774  
   775  	t.Run("test column attribute", func(t *testing.T) {
   776  		assert.Equal(t, columnName, column.Name())
   777  		assert.Equal(t, FieldTypeString, column.Type())
   778  		assert.Equal(t, columnLen, column.Len())
   779  		assert.EqualValues(t, v, column.Data())
   780  	})
   781  
   782  	t.Run("test column field data", func(t *testing.T) {
   783  		fd := column.FieldData()
   784  		assert.NotNil(t, fd)
   785  		assert.Equal(t, fd.GetFieldName(), columnName)
   786  	})
   787  
   788  	t.Run("test column value by idx", func(t *testing.T) {
   789  		_, err := column.ValueByIdx(-1)
   790  		assert.NotNil(t, err)
   791  		_, err = column.ValueByIdx(columnLen)
   792  		assert.NotNil(t, err)
   793  		for i := 0; i < columnLen; i++ {
   794  			v, err := column.ValueByIdx(i)
   795  			assert.Nil(t, err)
   796  			assert.Equal(t, column.values[i], v)
   797  		}
   798  	})
   799  }
   800  
   801  func TestFieldDataStringColumn(t *testing.T) {
   802  	len := rand.Intn(10) + 8
   803  	name := fmt.Sprintf("fd_String_%d", rand.Int())
   804  	fd := &schema.FieldData{
   805  		Type: schema.DataType_String,
   806  		FieldName: name,
   807  	}
   808  
   809  	t.Run("normal usage", func(t *testing.T) {
   810  		fd.Field = &schema.FieldData_Scalars{
   811  			Scalars: &schema.ScalarField{
   812  				Data: &schema.ScalarField_StringData{
   813  					StringData: &schema.StringArray{
   814  						Data: make([]string, len),
   815  					},
   816  				},
   817  			},
   818  		}
   819  		column, err := FieldDataColumn(fd, 0, len)
   820  		assert.Nil(t, err)
   821  		assert.NotNil(t, column)
   822   
   823  		assert.Equal(t, name, column.Name())
   824  		assert.Equal(t, len, column.Len())
   825  		assert.Equal(t, FieldTypeString, column.Type())
   826  
   827  		var ev string
   828  		err = column.AppendValue(ev)
   829  		assert.Equal(t, len+1, column.Len())
   830  		assert.Nil(t, err)
   831  
   832  		err = column.AppendValue(struct{}{})
   833  		assert.Equal(t, len+1, column.Len())
   834  		assert.NotNil(t, err)
   835  	})
   836  
   837  	
   838  	t.Run("nil data", func(t *testing.T) {
   839  		fd.Field = nil
   840  		_, err := FieldDataColumn(fd, 0, len)
   841  		assert.NotNil(t, err)
   842  	})
   843  	
   844  	t.Run("get all data", func(t *testing.T) {
   845  		fd.Field = &schema.FieldData_Scalars{
   846  			Scalars: &schema.ScalarField{
   847  				Data: &schema.ScalarField_StringData{
   848  					StringData: &schema.StringArray{
   849  						Data: make([]string, len),
   850  					},
   851  				},
   852  			},
   853  		}
   854  		column, err := FieldDataColumn(fd, 0, -1)
   855  		assert.Nil(t, err)
   856  		assert.NotNil(t, column)
   857  		
   858  		assert.Equal(t, name, column.Name())
   859  		assert.Equal(t, len, column.Len())
   860  		assert.Equal(t, FieldTypeString, column.Type())
   861  	})
   862  }
   863