|
10 | 10 | package org.elasticsearch.index.mapper; |
11 | 11 |
|
12 | 12 | import org.apache.lucene.tests.geo.GeoTestUtil; |
| 13 | +import org.elasticsearch.cluster.metadata.IndexMetadata; |
13 | 14 | import org.elasticsearch.common.geo.GeoPoint; |
14 | 15 | import org.elasticsearch.common.geo.SimpleFeatureFactory; |
| 16 | +import org.elasticsearch.common.settings.Settings; |
15 | 17 | import org.elasticsearch.geometry.Point; |
16 | 18 | import org.elasticsearch.geometry.utils.WellKnownBinary; |
| 19 | +import org.elasticsearch.index.IndexMode; |
| 20 | +import org.elasticsearch.index.IndexSettings; |
17 | 21 | import org.elasticsearch.index.IndexVersion; |
18 | 22 | import org.elasticsearch.script.ScriptCompiler; |
19 | 23 |
|
20 | 24 | import java.io.IOException; |
21 | 25 | import java.nio.ByteOrder; |
22 | 26 | import java.util.ArrayList; |
| 27 | +import java.util.Collections; |
23 | 28 | import java.util.List; |
24 | 29 | import java.util.Map; |
25 | 30 |
|
26 | 31 | import static org.hamcrest.Matchers.equalTo; |
| 32 | +import static org.hamcrest.Matchers.instanceOf; |
| 33 | +import static org.mockito.Mockito.doReturn; |
| 34 | +import static org.mockito.Mockito.mock; |
27 | 35 |
|
28 | 36 | public class GeoPointFieldTypeTests extends FieldTypeTestCase { |
29 | 37 |
|
@@ -147,4 +155,171 @@ public void testFetchVectorTile() throws IOException { |
147 | 155 | assertThat(sourceValue.size(), equalTo(1)); |
148 | 156 | assertThat(sourceValue.get(0), equalTo(featureFactory.points(geoPoints))); |
149 | 157 | } |
| 158 | + |
| 159 | + public void testBlockLoaderWhenDocValuesAreEnabledAndThePreferenceIsToUseDocValues() { |
| 160 | + // given |
| 161 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType("potato"); |
| 162 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 163 | + doReturn(MappedFieldType.FieldExtractPreference.DOC_VALUES).when(blContextMock).fieldExtractPreference(); |
| 164 | + |
| 165 | + // when |
| 166 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 167 | + |
| 168 | + // then |
| 169 | + // verify that we use the correct block value reader |
| 170 | + assertThat(loader, instanceOf(BlockDocValuesReader.LongsBlockLoader.class)); |
| 171 | + } |
| 172 | + |
| 173 | + public void testBlockLoaderWhenDocValuesAreEnabledAndThereIsNoPreference() { |
| 174 | + // given |
| 175 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType("potato"); |
| 176 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 177 | + doReturn(MappedFieldType.FieldExtractPreference.NONE).when(blContextMock).fieldExtractPreference(); |
| 178 | + |
| 179 | + // when |
| 180 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 181 | + |
| 182 | + // then |
| 183 | + // verify that we use the correct block value reader |
| 184 | + assertThat(loader, instanceOf(BlockDocValuesReader.LongsBlockLoader.class)); |
| 185 | + } |
| 186 | + |
| 187 | + public void testBlockLoaderWhenFieldIsStoredAndThePreferenceIsToUseStoredFields() { |
| 188 | + // given |
| 189 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType( |
| 190 | + "potato", |
| 191 | + true, |
| 192 | + true, |
| 193 | + false, |
| 194 | + null, |
| 195 | + null, |
| 196 | + null, |
| 197 | + Collections.emptyMap(), |
| 198 | + TimeSeriesParams.MetricType.COUNTER, |
| 199 | + IndexMode.LOGSDB, |
| 200 | + false |
| 201 | + ); |
| 202 | + |
| 203 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 204 | + doReturn(MappedFieldType.FieldExtractPreference.STORED).when(blContextMock).fieldExtractPreference(); |
| 205 | + |
| 206 | + // when |
| 207 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 208 | + |
| 209 | + // then |
| 210 | + // verify that we use the correct block value reader |
| 211 | + assertThat(loader, instanceOf(BlockStoredFieldsReader.BytesFromStringsBlockLoader.class)); |
| 212 | + } |
| 213 | + |
| 214 | + public void testBlockLoaderWhenFieldIsStoredAndThereIsNoPreference() { |
| 215 | + // given |
| 216 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType( |
| 217 | + "potato", |
| 218 | + true, |
| 219 | + true, |
| 220 | + false, |
| 221 | + null, |
| 222 | + null, |
| 223 | + null, |
| 224 | + Collections.emptyMap(), |
| 225 | + TimeSeriesParams.MetricType.COUNTER, |
| 226 | + IndexMode.LOGSDB, |
| 227 | + false |
| 228 | + ); |
| 229 | + |
| 230 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 231 | + doReturn(MappedFieldType.FieldExtractPreference.NONE).when(blContextMock).fieldExtractPreference(); |
| 232 | + |
| 233 | + // when |
| 234 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 235 | + |
| 236 | + // then |
| 237 | + // verify that we use the correct block value reader |
| 238 | + assertThat(loader, instanceOf(BlockStoredFieldsReader.BytesFromStringsBlockLoader.class)); |
| 239 | + } |
| 240 | + |
| 241 | + public void testBlockLoaderWhenSyntheticSourceIsEnabledAndFieldIsStoredInIgnoredSource() { |
| 242 | + // given |
| 243 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType( |
| 244 | + "potato", |
| 245 | + true, |
| 246 | + false, |
| 247 | + false, |
| 248 | + null, |
| 249 | + null, |
| 250 | + null, |
| 251 | + Collections.emptyMap(), |
| 252 | + TimeSeriesParams.MetricType.COUNTER, |
| 253 | + IndexMode.LOGSDB, |
| 254 | + true |
| 255 | + ); |
| 256 | + |
| 257 | + Settings settings = Settings.builder() |
| 258 | + .put("index.mapping.source.mode", "synthetic") |
| 259 | + .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
| 260 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 261 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) |
| 262 | + .build(); |
| 263 | + IndexSettings indexSettings = new IndexSettings(IndexMetadata.builder("index").settings(settings).build(), settings); |
| 264 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 265 | + doReturn(MappedFieldType.FieldExtractPreference.NONE).when(blContextMock).fieldExtractPreference(); |
| 266 | + doReturn(indexSettings).when(blContextMock).indexSettings(); |
| 267 | + |
| 268 | + // when |
| 269 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 270 | + |
| 271 | + // then |
| 272 | + // verify that we use the correct block value reader |
| 273 | + assertThat(loader, instanceOf(FallbackSyntheticSourceBlockLoader.class)); |
| 274 | + } |
| 275 | + |
| 276 | + public void testBlockLoaderWhenSyntheticSourceAndDocValuesAreEnabled() { |
| 277 | + // given |
| 278 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType( |
| 279 | + "potato", |
| 280 | + true, |
| 281 | + false, |
| 282 | + true, |
| 283 | + null, |
| 284 | + null, |
| 285 | + null, |
| 286 | + Collections.emptyMap(), |
| 287 | + TimeSeriesParams.MetricType.COUNTER, |
| 288 | + IndexMode.LOGSDB, |
| 289 | + true |
| 290 | + ); |
| 291 | + |
| 292 | + Settings settings = Settings.builder() |
| 293 | + .put("index.mapping.source.mode", "synthetic") |
| 294 | + .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
| 295 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 296 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) |
| 297 | + .build(); |
| 298 | + IndexSettings indexSettings = new IndexSettings(IndexMetadata.builder("index").settings(settings).build(), settings); |
| 299 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 300 | + doReturn(MappedFieldType.FieldExtractPreference.NONE).when(blContextMock).fieldExtractPreference(); |
| 301 | + doReturn(indexSettings).when(blContextMock).indexSettings(); |
| 302 | + |
| 303 | + // when |
| 304 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 305 | + |
| 306 | + // then |
| 307 | + // verify that we use the correct block value reader |
| 308 | + assertThat(loader, instanceOf(BlockDocValuesReader.LongsBlockLoader.class)); |
| 309 | + } |
| 310 | + |
| 311 | + public void testBlockLoaderFallsBackToSource() { |
| 312 | + // given |
| 313 | + GeoPointFieldMapper.GeoPointFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType("potato"); |
| 314 | + MappedFieldType.BlockLoaderContext blContextMock = mock(MappedFieldType.BlockLoaderContext.class); |
| 315 | + doReturn(MappedFieldType.FieldExtractPreference.EXTRACT_SPATIAL_BOUNDS).when(blContextMock).fieldExtractPreference(); |
| 316 | + |
| 317 | + // when |
| 318 | + BlockLoader loader = fieldType.blockLoader(blContextMock); |
| 319 | + |
| 320 | + // then |
| 321 | + // verify that we use the correct block value reader |
| 322 | + assertThat(loader, instanceOf(BlockSourceReader.GeometriesBlockLoader.class)); |
| 323 | + } |
| 324 | + |
150 | 325 | } |
0 commit comments