github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/sorter/fakes_for_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package sorter
    13  
    14  import (
    15  	"time"
    16  
    17  	"github.com/go-openapi/strfmt"
    18  	"github.com/weaviate/weaviate/entities/models"
    19  	"github.com/weaviate/weaviate/entities/schema"
    20  	"github.com/weaviate/weaviate/entities/storobj"
    21  )
    22  
    23  const testClassName = "MyFavoriteClass"
    24  
    25  func getMyFavoriteClassSchemaForTests() schema.Schema {
    26  	return schema.Schema{
    27  		Objects: &models.Schema{
    28  			Classes: []*models.Class{
    29  				{
    30  					Class: testClassName,
    31  					Properties: []*models.Property{
    32  						{
    33  							Name:     "textProp",
    34  							DataType: []string{string(schema.DataTypeText)},
    35  						},
    36  						{
    37  							Name:     "textPropArray",
    38  							DataType: []string{string(schema.DataTypeTextArray)},
    39  						},
    40  						{
    41  							Name:     "intProp",
    42  							DataType: []string{string(schema.DataTypeInt)},
    43  						},
    44  						{
    45  							Name:     "numberProp",
    46  							DataType: []string{string(schema.DataTypeNumber)},
    47  						},
    48  						{
    49  							Name:     "intPropArray",
    50  							DataType: []string{string(schema.DataTypeIntArray)},
    51  						},
    52  						{
    53  							Name:     "numberPropArray",
    54  							DataType: []string{string(schema.DataTypeNumberArray)},
    55  						},
    56  						{
    57  							Name:     "boolProp",
    58  							DataType: []string{string(schema.DataTypeBoolean)},
    59  						},
    60  						{
    61  							Name:     "boolPropArray",
    62  							DataType: []string{string(schema.DataTypeBooleanArray)},
    63  						},
    64  						{
    65  							Name:     "dateProp",
    66  							DataType: []string{string(schema.DataTypeDate)},
    67  						},
    68  						{
    69  							Name:     "datePropArray",
    70  							DataType: []string{string(schema.DataTypeDateArray)},
    71  						},
    72  						{
    73  							Name:     "phoneProp",
    74  							DataType: []string{string(schema.DataTypePhoneNumber)},
    75  						},
    76  						{
    77  							Name:     "geoProp",
    78  							DataType: []string{string(schema.DataTypeGeoCoordinates)},
    79  						},
    80  						{
    81  							Name:         "emptyStringProp",
    82  							DataType:     schema.DataTypeText.PropString(),
    83  							Tokenization: models.PropertyTokenizationWhitespace,
    84  						},
    85  						{
    86  							Name:     "emptyBoolProp",
    87  							DataType: []string{string(schema.DataTypeBoolean)},
    88  						},
    89  						{
    90  							Name:     "emptyNumberProp",
    91  							DataType: []string{string(schema.DataTypeNumber)},
    92  						},
    93  						{
    94  							Name:     "emptyIntProp",
    95  							DataType: []string{string(schema.DataTypeInt)},
    96  						},
    97  						{
    98  							Name:     "crefProp",
    99  							DataType: []string{string(schema.DataTypeCRef)},
   100  						},
   101  					},
   102  				},
   103  			},
   104  		},
   105  	}
   106  }
   107  
   108  func createMyFavoriteClassObject() *storobj.Object {
   109  	return storobj.FromObject(
   110  		&models.Object{
   111  			Class:              testClassName,
   112  			CreationTimeUnix:   900000000001,
   113  			LastUpdateTimeUnix: 900000000002,
   114  			ID:                 strfmt.UUID("73f2eb5f-5abf-447a-81ca-74b1dd168247"),
   115  			Properties: map[string]interface{}{
   116  				"textProp":        "text",
   117  				"textPropArray":   []string{"text", "text"},
   118  				"intProp":         float64(100),
   119  				"numberProp":      float64(17),
   120  				"intPropArray":    []float64{10, 20, 30},
   121  				"numberPropArray": []float64{1, 2, 3},
   122  				"boolProp":        true,
   123  				"boolPropArray":   []bool{true, false, true},
   124  				"dateProp":        "1980-01-01T00:00:00+02:00",
   125  				"datePropArray":   []string{"1980-01-01T00:00:00+02:00"},
   126  				"phoneProp": &models.PhoneNumber{
   127  					CountryCode:            49,
   128  					DefaultCountry:         "DE",
   129  					Input:                  "0171 1000000",
   130  					Valid:                  true,
   131  					InternationalFormatted: "+49 171 1000000",
   132  					National:               1000000,
   133  					NationalFormatted:      "0171 1000000",
   134  				},
   135  				"geoProp": &models.GeoCoordinates{
   136  					Longitude: ptrFloat32(1),
   137  					Latitude:  ptrFloat32(2),
   138  				},
   139  			},
   140  		},
   141  		[]float32{1, 2, 0.7},
   142  		nil,
   143  	)
   144  }
   145  
   146  func sorterCitySchema() schema.Schema {
   147  	return schema.Schema{
   148  		Objects: &models.Schema{
   149  			Classes: []*models.Class{
   150  				{
   151  					Class: "City",
   152  					Properties: []*models.Property{
   153  						{
   154  							Name:         "name",
   155  							DataType:     schema.DataTypeText.PropString(),
   156  							Tokenization: models.PropertyTokenizationWhitespace,
   157  						},
   158  						{
   159  							Name:     "country",
   160  							DataType: []string{string(schema.DataTypeText)},
   161  						},
   162  						{
   163  							Name:     "population",
   164  							DataType: []string{string(schema.DataTypeInt)},
   165  						},
   166  						{
   167  							Name:     "cityArea",
   168  							DataType: []string{string(schema.DataTypeNumber)},
   169  						},
   170  						{
   171  							Name:     "cityRights",
   172  							DataType: []string{string(schema.DataTypeDate)},
   173  						},
   174  						{
   175  							Name:         "timezones",
   176  							DataType:     schema.DataTypeTextArray.PropString(),
   177  							Tokenization: models.PropertyTokenizationWhitespace,
   178  						},
   179  						{
   180  							Name:     "timezonesUTC",
   181  							DataType: []string{string(schema.DataTypeTextArray)},
   182  						},
   183  						{
   184  							Name:     "isCapital",
   185  							DataType: []string{string(schema.DataTypeBoolean)},
   186  						},
   187  						{
   188  							Name:     "isCapitalArray",
   189  							DataType: []string{string(schema.DataTypeBooleanArray)},
   190  						},
   191  						{
   192  							Name:     "favoriteNumbers",
   193  							DataType: []string{string(schema.DataTypeNumberArray)},
   194  						},
   195  						{
   196  							Name:     "favoriteInts",
   197  							DataType: []string{string(schema.DataTypeIntArray)},
   198  						},
   199  						{
   200  							Name:     "favoriteDates",
   201  							DataType: []string{string(schema.DataTypeDateArray)},
   202  						},
   203  						{
   204  							Name:     "phoneNumber",
   205  							DataType: []string{string(schema.DataTypePhoneNumber)},
   206  						},
   207  						{
   208  							Name:     "location",
   209  							DataType: []string{string(schema.DataTypeGeoCoordinates)},
   210  						},
   211  					},
   212  				},
   213  			},
   214  		},
   215  	}
   216  }
   217  
   218  func sorterCitySchemaDistances() []float32 {
   219  	return []float32{0.1, 0.0, 0.2, 0.3, 0.4, 0.0}
   220  }
   221  
   222  func sorterCitySchemaObjects() []*storobj.Object {
   223  	return []*storobj.Object{cityWroclaw, cityNil2, cityBerlin, cityNewYork, cityAmsterdam, cityNil}
   224  }
   225  
   226  var (
   227  	cityWroclaw = &storobj.Object{
   228  		Object: models.Object{
   229  			Class:              "City",
   230  			ID:                 strfmt.UUID("f10018a7-ad67-4774-a9ac-86a04df51cb6"),
   231  			CreationTimeUnix:   9000000006,
   232  			LastUpdateTimeUnix: 9100000006,
   233  			Properties: map[string]interface{}{
   234  				"name":            "Wroclaw",
   235  				"country":         "Poland",
   236  				"population":      float64(641928),
   237  				"cityArea":        float64(292.23),
   238  				"cityRights":      "1214-01-01T00:00:00+02:00",
   239  				"timezones":       []string{"CET", "CEST"},
   240  				"timezonesUTC":    []string{"UTC+1", "UTC+2"},
   241  				"isCapital":       false,
   242  				"isCapitalArray":  []bool{false, false},
   243  				"favoriteNumbers": []float64{0, 0, 0},
   244  				"favoriteInts":    []float64{0, 0, 0},
   245  				"favoriteDates":   []string{"1214-01-01T00:00:00+02:00", "1214-01-01T00:00:00+02:00"},
   246  				"phoneNumber": &models.PhoneNumber{
   247  					CountryCode: 0,
   248  					National:    400500600,
   249  				},
   250  				"location": &models.GeoCoordinates{
   251  					Latitude:  ptrFloat32(51.11),
   252  					Longitude: ptrFloat32(17.022222),
   253  				},
   254  			},
   255  		},
   256  	}
   257  	cityBerlin = &storobj.Object{
   258  		Object: models.Object{
   259  			Class:              "City",
   260  			ID:                 strfmt.UUID("b06bb8a7-ad67-4774-a9ac-86a04df51cb6"),
   261  			CreationTimeUnix:   9000000002,
   262  			LastUpdateTimeUnix: 9100000002,
   263  			Properties: map[string]interface{}{
   264  				"name":            "Berlin",
   265  				"country":         "Germany",
   266  				"population":      float64(3664088),
   267  				"cityArea":        float64(891.95),
   268  				"cityRights":      "1400-01-01T00:00:00+02:00",
   269  				"timezones":       []string{"CET", "CEST"},
   270  				"timezonesUTC":    []string{"UTC+1", "UTC+2"},
   271  				"isCapital":       true,
   272  				"isCapitalArray":  []bool{false, false, true},
   273  				"favoriteNumbers": []float64{0, 10, 1},
   274  				"favoriteInts":    []float64{0, 10, 1},
   275  				"favoriteDates":   []string{"1400-01-01T00:00:00+02:00"},
   276  				"phoneNumber": &models.PhoneNumber{
   277  					CountryCode: 33,
   278  					National:    400500610,
   279  				},
   280  				"location": &models.GeoCoordinates{
   281  					Latitude:  ptrFloat32(52.518611),
   282  					Longitude: ptrFloat32(13.408333),
   283  				},
   284  			},
   285  		},
   286  	}
   287  	cityNewYork = &storobj.Object{
   288  		Object: models.Object{
   289  			Class:              "City",
   290  			ID:                 strfmt.UUID("e06bb8a7-ad67-4774-a9ac-86a04df51cb6"),
   291  			CreationTimeUnix:   9000000003,
   292  			LastUpdateTimeUnix: 9100000003,
   293  			Properties: map[string]interface{}{
   294  				"name":            "New York",
   295  				"country":         "USA",
   296  				"population":      float64(8336817),
   297  				"cityArea":        float64(1223.59),
   298  				"cityRights":      "1653-01-01T00:00:00+02:00",
   299  				"timezones":       []string{"EST", "EDT"},
   300  				"timezonesUTC":    []string{"UTC-5", "UTC-4"},
   301  				"isCapital":       false,
   302  				"isCapitalArray":  []bool{true, true, true},
   303  				"favoriteNumbers": []float64{-100000.23, -8.909},
   304  				"favoriteInts":    []float64{-100000, -8},
   305  				"favoriteDates":   []string{"1400-01-01T00:00:00+02:00", "1653-01-01T00:00:00+02:00"},
   306  				"phoneNumber": &models.PhoneNumber{
   307  					CountryCode: 33,
   308  					National:    400500609,
   309  				},
   310  				"location": &models.GeoCoordinates{
   311  					Latitude:  ptrFloat32(40.716667),
   312  					Longitude: ptrFloat32(-74),
   313  				},
   314  			},
   315  		},
   316  	}
   317  	cityAmsterdam = &storobj.Object{
   318  		Object: models.Object{
   319  			Class:              "City",
   320  			ID:                 strfmt.UUID("a06bb8a7-ad67-4774-a9ac-86a04df51cb6"),
   321  			CreationTimeUnix:   9000000001,
   322  			LastUpdateTimeUnix: 9100000001,
   323  			Properties: map[string]interface{}{
   324  				"name":            "Amsterdam",
   325  				"country":         "The Netherlands",
   326  				"population":      float64(905234),
   327  				"cityArea":        float64(219.32),
   328  				"cityRights":      "1100-01-01T00:00:00+02:00",
   329  				"timezones":       []string{"CET", "CEST"},
   330  				"timezonesUTC":    []string{"UTC+1", "UTC+2"},
   331  				"isCapital":       true,
   332  				"isCapitalArray":  []bool{true},
   333  				"favoriteNumbers": []float64{1, 2, 3, 4, 5, 6, 8.8, 9.9},
   334  				"favoriteInts":    []float64{1, 2, 3, 4, 5, 6, 8, 9},
   335  				"favoriteDates":   []string{"1100-01-01T00:00:00+02:00"},
   336  				"phoneNumber": &models.PhoneNumber{
   337  					CountryCode: 33,
   338  					National:    400500602,
   339  				},
   340  				"location": &models.GeoCoordinates{
   341  					Latitude:  ptrFloat32(52.366667),
   342  					Longitude: ptrFloat32(4.9),
   343  				},
   344  			},
   345  		},
   346  	}
   347  	cityNil = &storobj.Object{
   348  		Object: models.Object{
   349  			Class:              "City",
   350  			ID:                 strfmt.UUID("f00018a7-ad67-4774-a9ac-86a04df51cb6"),
   351  			CreationTimeUnix:   9000000004,
   352  			LastUpdateTimeUnix: 9100000004,
   353  			Properties: map[string]interface{}{
   354  				"name": "Nil",
   355  			},
   356  		},
   357  	}
   358  	cityNil2 = &storobj.Object{
   359  		Object: models.Object{
   360  			Class:              "City",
   361  			ID:                 strfmt.UUID("f00028a7-ad67-4774-a9ac-86a04df51cb6"),
   362  			CreationTimeUnix:   9000000005,
   363  			LastUpdateTimeUnix: 9100000005,
   364  			Properties: map[string]interface{}{
   365  				"name": "Nil2",
   366  			},
   367  		},
   368  	}
   369  )
   370  
   371  func ptrString(s string) *string {
   372  	return &s
   373  }
   374  
   375  func ptrStringArray(sa ...string) *[]string {
   376  	return &sa
   377  }
   378  
   379  func ptrFloat32(f float32) *float32 {
   380  	return &f
   381  }
   382  
   383  func ptrFloat64(f float64) *float64 {
   384  	return &f
   385  }
   386  
   387  func ptrFloat64Array(fa ...float64) *[]float64 {
   388  	return &fa
   389  }
   390  
   391  func ptrBool(b bool) *bool {
   392  	return &b
   393  }
   394  
   395  func ptrBoolArray(ba ...bool) *[]bool {
   396  	return &ba
   397  }
   398  
   399  func ptrTime(s string) *time.Time {
   400  	t, _ := time.Parse(time.RFC3339, s)
   401  	return &t
   402  }
   403  
   404  func ptrTimeArray(sa ...string) *[]time.Time {
   405  	res := make([]time.Time, len(sa))
   406  	for i := range sa {
   407  		t, _ := time.Parse(time.RFC3339, sa[i])
   408  		res[i] = t
   409  	}
   410  	return &res
   411  }