elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.58k stars 24.63k forks source link

precision lost when selecting scaled_float field with SQL #99569

Open alisanguo opened 1 year ago

alisanguo commented 1 year ago

Elasticsearch Version

6.8.2

Installed Plugins

xpack

Java Version

openjdk version "17.0.5" 2022-10-18

OS Version

Linux th-shopee-10-66-133-110 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

a test_index mapping: { "test_index":{ "mappings":{ "type":{ "properties":{ "interest":{ "type":"scaled_float", "scaling_factor":10000000000 }, } } } } }

query by DSL get result: { "took":4, "timed_out":false, "_shards":{ "total":20, "successful":20, "skipped":0, "failed":0 }, "hits":{ "total":1, "max_score":1, "hits":[ { "_index":"test_index", "_type":"type", "_id":"1700800855601029208", "_score":1, "_source":{ "interest":0.96 } } ] } }

however, select by sql get result: { "columns":[ { "name":"interest", "type":"scaled_float" } ], "rows":[ [ 0.9600000000000001 ] ] }

Steps to Reproduce

1.create test_index with mapping: { "test_index":{ "mappings":{ "type":{ "properties":{ "interest":{ "type":"scaled_float", "scaling_factor":10000000000 }, } } } } }

2.add a doc: { "interest":"0.96" }

  1. query by DSL: GET /test_index/_search { "query": { "match_all": {} } }

  2. select by sql : curl -XPOST http://xxx/_xpack/sql?format=json -H 'Content-Type: application/json' -d ' { "query": "select * from test_index limit 1" }'

  3. compare 4 with 5

Logs (if relevant)

No response

elasticsearchmachine commented 1 year ago

Pinging @elastic/es-ql (Team:QL)

elasticsearchmachine commented 8 months ago

Pinging @elastic/es-analytics-geo (Team:Analytics)