|
19 | 19 | package org.elasticsearch.search.aggregations;
|
20 | 20 |
|
21 | 21 | import org.apache.lucene.document.BinaryDocValuesField;
|
| 22 | +import org.apache.lucene.document.HalfFloatPoint; |
22 | 23 | import org.apache.lucene.document.InetAddressPoint;
|
23 | 24 | import org.apache.lucene.document.LatLonDocValuesField;
|
24 | 25 | import org.apache.lucene.document.SortedNumericDocValuesField;
|
|
41 | 42 | import org.apache.lucene.search.Weight;
|
42 | 43 | import org.apache.lucene.store.Directory;
|
43 | 44 | import org.apache.lucene.util.BytesRef;
|
| 45 | +import org.apache.lucene.util.NumericUtils; |
44 | 46 | import org.elasticsearch.Version;
|
45 | 47 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
46 | 48 | import org.elasticsearch.common.breaker.CircuitBreaker;
|
|
74 | 76 | import org.elasticsearch.index.mapper.Mapper;
|
75 | 77 | import org.elasticsearch.index.mapper.Mapper.BuilderContext;
|
76 | 78 | import org.elasticsearch.index.mapper.MapperService;
|
| 79 | +import org.elasticsearch.index.mapper.NumberFieldMapper; |
77 | 80 | import org.elasticsearch.index.mapper.ObjectMapper;
|
78 | 81 | import org.elasticsearch.index.mapper.ObjectMapper.Nested;
|
79 | 82 | import org.elasticsearch.index.mapper.RangeFieldMapper;
|
@@ -605,7 +608,7 @@ protected AggregationBuilder createAggBuilderForTypeTest(MappedFieldType fieldTy
|
605 | 608 | *
|
606 | 609 | * Exception types/messages are not currently checked, just presence/absence of an exception.
|
607 | 610 | */
|
608 |
| - public void testSupportedFieldTypes() throws IOException { |
| 611 | + public final void testSupportedFieldTypes() throws IOException { |
609 | 612 | MapperRegistry mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
|
610 | 613 | Settings settings = Settings.builder().put("index.version.created", Version.CURRENT.id).build();
|
611 | 614 | String fieldName = "typeTestFieldName";
|
@@ -675,67 +678,78 @@ public void testSupportedFieldTypes() throws IOException {
|
675 | 678 | */
|
676 | 679 | private void writeTestDoc(MappedFieldType fieldType, String fieldName, RandomIndexWriter iw) throws IOException {
|
677 | 680 |
|
678 |
| - if (fieldType.getValuesSourceType().equals(CoreValuesSourceType.NUMERIC)) { |
| 681 | + String typeName = fieldType.typeName(); |
| 682 | + ValuesSourceType vst = fieldType.getValuesSourceType(); |
| 683 | + |
| 684 | + if (vst.equals(CoreValuesSourceType.NUMERIC)) { |
679 | 685 | // TODO note: once VS refactor adds DATE/BOOLEAN, this conditional will go away
|
680 |
| - if (fieldType.typeName().equals(DateFieldMapper.CONTENT_TYPE) |
681 |
| - || fieldType.typeName().equals(DateFieldMapper.DATE_NANOS_CONTENT_TYPE)) { |
| 686 | + if (typeName.equals(DateFieldMapper.CONTENT_TYPE) || typeName.equals(DateFieldMapper.DATE_NANOS_CONTENT_TYPE)) { |
682 | 687 | iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomNonNegativeLong())));
|
683 |
| - } else if (fieldType.typeName().equals(BooleanFieldMapper.CONTENT_TYPE)) { |
| 688 | + } else if (typeName.equals(BooleanFieldMapper.CONTENT_TYPE)) { |
684 | 689 | iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomBoolean() ? 0 : 1)));
|
| 690 | + } else if (typeName.equals(NumberFieldMapper.NumberType.DOUBLE.typeName())) { |
| 691 | + long encoded = NumericUtils.doubleToSortableLong(Math.abs(randomDouble())); |
| 692 | + iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, encoded))); |
| 693 | + } else if (typeName.equals(NumberFieldMapper.NumberType.FLOAT.typeName())) { |
| 694 | + long encoded = NumericUtils.floatToSortableInt(Math.abs(randomFloat())); |
| 695 | + iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, encoded))); |
| 696 | + } else if (typeName.equals(NumberFieldMapper.NumberType.HALF_FLOAT.typeName())) { |
| 697 | + long encoded = HalfFloatPoint.halfFloatToSortableShort(Math.abs(randomFloat())); |
| 698 | + iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, encoded))); |
685 | 699 | } else {
|
686 |
| - iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomLong()))); |
| 700 | + iw.addDocument(singleton(new SortedNumericDocValuesField(fieldName, randomNonNegativeLong()))); |
687 | 701 | }
|
688 |
| - } else if (fieldType.getValuesSourceType().equals(CoreValuesSourceType.BYTES)) { |
689 |
| - if (fieldType.typeName().equals(BinaryFieldMapper.CONTENT_TYPE)) { |
| 702 | + } else if (vst.equals(CoreValuesSourceType.BYTES)) { |
| 703 | + if (typeName.equals(BinaryFieldMapper.CONTENT_TYPE)) { |
690 | 704 | iw.addDocument(singleton(new BinaryFieldMapper.CustomBinaryDocValuesField(fieldName, new BytesRef("a").bytes)));
|
691 |
| - } else if (fieldType.typeName().equals(IpFieldMapper.CONTENT_TYPE)) { |
| 705 | + } else if (typeName.equals(IpFieldMapper.CONTENT_TYPE)) { |
692 | 706 | // TODO note: once VS refactor adds IP, this conditional will go away
|
693 | 707 | boolean v4 = randomBoolean();
|
694 | 708 | iw.addDocument(singleton(new SortedSetDocValuesField(fieldName, new BytesRef(InetAddressPoint.encode(randomIp(v4))))));
|
695 | 709 | } else {
|
696 | 710 | iw.addDocument(singleton(new SortedSetDocValuesField(fieldName, new BytesRef("a"))));
|
697 | 711 | }
|
698 |
| - } else if (fieldType.getValuesSourceType().equals(CoreValuesSourceType.RANGE)) { |
| 712 | + } else if (vst.equals(CoreValuesSourceType.RANGE)) { |
699 | 713 | Object start;
|
700 | 714 | Object end;
|
701 | 715 | RangeType rangeType;
|
702 | 716 |
|
703 |
| - if (fieldType.typeName().equals(RangeType.DOUBLE.typeName())) { |
| 717 | + if (typeName.equals(RangeType.DOUBLE.typeName())) { |
704 | 718 | start = randomDouble();
|
705 | 719 | end = RangeType.DOUBLE.nextUp(start);
|
706 | 720 | rangeType = RangeType.DOUBLE;
|
707 |
| - } else if (fieldType.typeName().equals(RangeType.FLOAT.typeName())) { |
| 721 | + } else if (typeName.equals(RangeType.FLOAT.typeName())) { |
708 | 722 | start = randomFloat();
|
709 | 723 | end = RangeType.FLOAT.nextUp(start);
|
710 | 724 | rangeType = RangeType.DOUBLE;
|
711 |
| - } else if (fieldType.typeName().equals(RangeType.IP.typeName())) { |
| 725 | + } else if (typeName.equals(RangeType.IP.typeName())) { |
712 | 726 | boolean v4 = randomBoolean();
|
713 | 727 | start = randomIp(v4);
|
714 | 728 | end = RangeType.IP.nextUp(start);
|
715 | 729 | rangeType = RangeType.IP;
|
716 |
| - } else if (fieldType.typeName().equals(RangeType.LONG.typeName())) { |
| 730 | + } else if (typeName.equals(RangeType.LONG.typeName())) { |
717 | 731 | start = randomLong();
|
718 | 732 | end = RangeType.LONG.nextUp(start);
|
719 | 733 | rangeType = RangeType.LONG;
|
720 |
| - } else if (fieldType.typeName().equals(RangeType.INTEGER.typeName())) { |
| 734 | + } else if (typeName.equals(RangeType.INTEGER.typeName())) { |
721 | 735 | start = randomInt();
|
722 | 736 | end = RangeType.INTEGER.nextUp(start);
|
723 | 737 | rangeType = RangeType.INTEGER;
|
724 |
| - } else if (fieldType.typeName().equals(RangeType.DATE.typeName())) { |
| 738 | + } else if (typeName.equals(RangeType.DATE.typeName())) { |
725 | 739 | start = randomNonNegativeLong();
|
726 | 740 | end = RangeType.DATE.nextUp(start);
|
727 | 741 | rangeType = RangeType.DATE;
|
728 | 742 | } else {
|
729 |
| - throw new IllegalStateException("Unknown type of range [" + fieldType.typeName() + "]"); |
| 743 | + throw new IllegalStateException("Unknown type of range [" + typeName + "]"); |
730 | 744 | }
|
731 | 745 |
|
732 | 746 | final RangeFieldMapper.Range range = new RangeFieldMapper.Range(rangeType, start, end, true, true);
|
733 | 747 | iw.addDocument(singleton(new BinaryDocValuesField(fieldName, rangeType.encodeRanges(Collections.singleton(range)))));
|
734 | 748 |
|
735 |
| - } else if (fieldType.getValuesSourceType().equals(CoreValuesSourceType.GEOPOINT)) { |
| 749 | + } else if (vst.equals(CoreValuesSourceType.GEOPOINT)) { |
736 | 750 | iw.addDocument(singleton(new LatLonDocValuesField(fieldName, randomDouble(), randomDouble())));
|
737 | 751 | } else {
|
738 |
| - throw new IllegalStateException("Unknown field type [" + fieldType.typeName() + "]"); |
| 752 | + throw new IllegalStateException("Unknown field type [" + typeName + "]"); |
739 | 753 | }
|
740 | 754 | }
|
741 | 755 |
|
|
0 commit comments