From 3e47f904601e2b0b3373bd3889f80a9800291998 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 9 Dec 2015 14:56:50 +0100 Subject: [PATCH] Remove XContentParser.estimatedNumberType(). The goal of this method is to know whether the xcontent impl knows how to differenciate floats from doubles or longs from ints or if it's just guessing. However, all implementations return true (which is correct for yaml and json, but cbor and smile should be able to differenciate). I first tried to implement this method correctly but it raised many issues because eg. most impls write a long as an integer when it is small enough. So I suggest that we remove this method and just treat cbor and smile like yaml and json, which is already what is happening today anyway. --- .../common/xcontent/XContentParser.java | 6 ---- .../xcontent/json/JsonXContentParser.java | 5 --- .../index/mapper/DocumentParser.java | 35 ++----------------- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java index b68d3e11f14..d647c5f0134 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java @@ -178,12 +178,6 @@ public interface XContentParser extends Releasable { NumberType numberType() throws IOException; - /** - * Is the number type estimated or not (i.e. an int might actually be a long, its just low enough - * to be an int). - */ - boolean estimatedNumberType(); - short shortValue(boolean coerce) throws IOException; int intValue(boolean coerce) throws IOException; diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java index 787c28324de..c3aca7626b7 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java @@ -68,11 +68,6 @@ public class JsonXContentParser extends AbstractXContentParser { return convertNumberType(parser.getNumberType()); } - @Override - public boolean estimatedNumberType() { - return true; - } - @Override public String currentName() throws IOException { return parser.getCurrentName(); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java b/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java index ce2cbd4e931..b0ad972d575 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java @@ -560,44 +560,13 @@ class DocumentParser implements Closeable { return builder; } else if (token == XContentParser.Token.VALUE_NUMBER) { XContentParser.NumberType numberType = context.parser().numberType(); - if (numberType == XContentParser.NumberType.INT) { - if (context.parser().estimatedNumberType()) { - Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "long"); - if (builder == null) { - builder = MapperBuilders.longField(currentFieldName); - } - return builder; - } else { - Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "integer"); - if (builder == null) { - builder = MapperBuilders.integerField(currentFieldName); - } - return builder; - } - } else if (numberType == XContentParser.NumberType.LONG) { + if (numberType == XContentParser.NumberType.INT || numberType == XContentParser.NumberType.LONG) { Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "long"); if (builder == null) { builder = MapperBuilders.longField(currentFieldName); } return builder; - } else if (numberType == XContentParser.NumberType.FLOAT) { - if (context.parser().estimatedNumberType()) { - Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "double"); - if (builder == null) { - // no templates are defined, we use float by default instead of double - // since this is much more space-efficient and should be enough most of - // the time - builder = MapperBuilders.floatField(currentFieldName); - } - return builder; - } else { - Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "float"); - if (builder == null) { - builder = MapperBuilders.floatField(currentFieldName); - } - return builder; - } - } else if (numberType == XContentParser.NumberType.DOUBLE) { + } else if (numberType == XContentParser.NumberType.FLOAT || numberType == XContentParser.NumberType.DOUBLE) { Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "double"); if (builder == null) { // no templates are defined, we use float by default instead of double