github.com/weaviate/weaviate@v1.24.6/entities/schema/nested_properties_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 schema_test 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/weaviate/weaviate/entities/models" 19 "github.com/weaviate/weaviate/entities/schema" 20 "github.com/weaviate/weaviate/entities/schema/test_utils" 21 ) 22 23 func Test_MergeRecursivelyNestedProperties(t *testing.T) { 24 vFalse := false 25 vTrue := true 26 27 emptyProps := []*models.NestedProperty{} 28 nestedProps1 := []*models.NestedProperty{ 29 { 30 Name: "nested_int", 31 DataType: schema.DataTypeInt.PropString(), 32 IndexFilterable: &vTrue, 33 IndexSearchable: &vFalse, 34 Tokenization: "", 35 }, 36 { 37 Name: "nested_text", 38 DataType: schema.DataTypeText.PropString(), 39 IndexFilterable: &vTrue, 40 IndexSearchable: &vTrue, 41 Tokenization: models.PropertyTokenizationWord, 42 }, 43 { 44 Name: "nested_objects", 45 DataType: schema.DataTypeObjectArray.PropString(), 46 IndexFilterable: &vTrue, 47 IndexSearchable: &vFalse, 48 Tokenization: "", 49 NestedProperties: []*models.NestedProperty{ 50 { 51 Name: "nested_bool_lvl2", 52 DataType: schema.DataTypeBoolean.PropString(), 53 IndexFilterable: &vTrue, 54 IndexSearchable: &vFalse, 55 Tokenization: "", 56 }, 57 { 58 Name: "nested_numbers_lvl2", 59 DataType: schema.DataTypeNumberArray.PropString(), 60 IndexFilterable: &vTrue, 61 IndexSearchable: &vFalse, 62 Tokenization: "", 63 }, 64 }, 65 }, 66 } 67 nestedProps2 := []*models.NestedProperty{ 68 { 69 Name: "nested_number", 70 DataType: schema.DataTypeNumber.PropString(), 71 IndexFilterable: &vTrue, 72 IndexSearchable: &vFalse, 73 Tokenization: "", 74 }, 75 { 76 Name: "nested_text", 77 DataType: schema.DataTypeText.PropString(), 78 IndexFilterable: &vTrue, 79 IndexSearchable: &vTrue, 80 Tokenization: models.PropertyTokenizationField, // different setting than (1) 81 }, 82 { 83 Name: "nested_objects", 84 DataType: schema.DataTypeObjectArray.PropString(), 85 IndexFilterable: &vTrue, 86 IndexSearchable: &vFalse, 87 Tokenization: "", 88 NestedProperties: []*models.NestedProperty{ 89 { 90 Name: "nested_date_lvl2", 91 DataType: schema.DataTypeDate.PropString(), 92 IndexFilterable: &vTrue, 93 IndexSearchable: &vFalse, 94 Tokenization: "", 95 }, 96 { 97 Name: "nested_numbers_lvl2", 98 DataType: schema.DataTypeNumberArray.PropString(), 99 IndexFilterable: &vFalse, // different setting than (1) 100 IndexSearchable: &vFalse, 101 Tokenization: "", 102 }, 103 }, 104 }, 105 } 106 107 mergedProps_1_2 := []*models.NestedProperty{ 108 { 109 Name: "nested_int", 110 DataType: schema.DataTypeInt.PropString(), 111 IndexFilterable: &vTrue, 112 IndexSearchable: &vFalse, 113 Tokenization: "", 114 }, 115 { 116 Name: "nested_number", 117 DataType: schema.DataTypeNumber.PropString(), 118 IndexFilterable: &vTrue, 119 IndexSearchable: &vFalse, 120 Tokenization: "", 121 }, 122 { 123 Name: "nested_text", 124 DataType: schema.DataTypeText.PropString(), 125 IndexFilterable: &vTrue, 126 IndexSearchable: &vTrue, 127 Tokenization: models.PropertyTokenizationWord, // from (1) 128 }, 129 { 130 Name: "nested_objects", 131 DataType: schema.DataTypeObjectArray.PropString(), 132 IndexFilterable: &vTrue, 133 IndexSearchable: &vFalse, 134 Tokenization: "", 135 NestedProperties: []*models.NestedProperty{ 136 { 137 Name: "nested_bool_lvl2", 138 DataType: schema.DataTypeBoolean.PropString(), 139 IndexFilterable: &vTrue, 140 IndexSearchable: &vFalse, 141 Tokenization: "", 142 }, 143 { 144 Name: "nested_date_lvl2", 145 DataType: schema.DataTypeDate.PropString(), 146 IndexFilterable: &vTrue, 147 IndexSearchable: &vFalse, 148 Tokenization: "", 149 }, 150 { 151 Name: "nested_numbers_lvl2", 152 DataType: schema.DataTypeNumberArray.PropString(), 153 IndexFilterable: &vTrue, // from (1) 154 IndexSearchable: &vFalse, 155 Tokenization: "", 156 }, 157 }, 158 }, 159 } 160 161 mergedProps_2_1 := []*models.NestedProperty{ 162 { 163 Name: "nested_int", 164 DataType: schema.DataTypeInt.PropString(), 165 IndexFilterable: &vTrue, 166 IndexSearchable: &vFalse, 167 Tokenization: "", 168 }, 169 { 170 Name: "nested_number", 171 DataType: schema.DataTypeNumber.PropString(), 172 IndexFilterable: &vTrue, 173 IndexSearchable: &vFalse, 174 Tokenization: "", 175 }, 176 { 177 Name: "nested_text", 178 DataType: schema.DataTypeText.PropString(), 179 IndexFilterable: &vTrue, 180 IndexSearchable: &vTrue, 181 Tokenization: models.PropertyTokenizationField, // from (2) 182 }, 183 { 184 Name: "nested_objects", 185 DataType: schema.DataTypeObjectArray.PropString(), 186 IndexFilterable: &vTrue, 187 IndexSearchable: &vFalse, 188 Tokenization: "", 189 NestedProperties: []*models.NestedProperty{ 190 { 191 Name: "nested_bool_lvl2", 192 DataType: schema.DataTypeBoolean.PropString(), 193 IndexFilterable: &vTrue, 194 IndexSearchable: &vFalse, 195 Tokenization: "", 196 }, 197 { 198 Name: "nested_date_lvl2", 199 DataType: schema.DataTypeDate.PropString(), 200 IndexFilterable: &vTrue, 201 IndexSearchable: &vFalse, 202 Tokenization: "", 203 }, 204 { 205 Name: "nested_numbers_lvl2", 206 DataType: schema.DataTypeNumberArray.PropString(), 207 IndexFilterable: &vFalse, // from (2) 208 IndexSearchable: &vFalse, 209 Tokenization: "", 210 }, 211 }, 212 }, 213 } 214 215 t.Run("empty + nested", func(t *testing.T) { 216 nestedProps, merged := schema.MergeRecursivelyNestedProperties(emptyProps, nestedProps1) 217 218 assert.True(t, merged) 219 assert.Equal(t, nestedProps1, nestedProps) 220 }) 221 222 t.Run("nested + empty", func(t *testing.T) { 223 nestedProps, merged := schema.MergeRecursivelyNestedProperties(nestedProps1, emptyProps) 224 225 assert.False(t, merged) 226 assert.Equal(t, nestedProps1, nestedProps) 227 }) 228 229 t.Run("2 x nested", func(t *testing.T) { 230 nestedProps, merged := schema.MergeRecursivelyNestedProperties(nestedProps1, nestedProps1) 231 232 assert.False(t, merged) 233 assert.Equal(t, nestedProps1, nestedProps) 234 }) 235 236 t.Run("nested1 + nested2", func(t *testing.T) { 237 nestedProps, merged := schema.MergeRecursivelyNestedProperties(nestedProps1, nestedProps2) 238 239 assert.True(t, merged) 240 assert.NotEqual(t, nestedProps1, nestedProps) 241 assert.NotEqual(t, nestedProps2, nestedProps) 242 test_utils.AssertNestedPropsMatch(t, mergedProps_1_2, nestedProps) 243 }) 244 245 t.Run("nested2 + nested1", func(t *testing.T) { 246 nestedProps, merged := schema.MergeRecursivelyNestedProperties(nestedProps2, nestedProps1) 247 248 assert.True(t, merged) 249 assert.NotEqual(t, nestedProps1, nestedProps) 250 assert.NotEqual(t, nestedProps2, nestedProps) 251 test_utils.AssertNestedPropsMatch(t, mergedProps_2_1, nestedProps) 252 }) 253 }