Giter Site home page Giter Site logo

Comments (9)

sanikolaev avatar sanikolaev commented on May 26, 2024

@Nick-S-2018 As discussed on today's dev call, please check if type casting works in this case and how applicable it is to be used in the clients.

from manticoresearch.

sanikolaev avatar sanikolaev commented on May 26, 2024

double(f.a) doesn't work:

mysql> drop table if exists t; create table t(f json); insert into t(id,f) values(1,'{"a":2.5}'); select * from t where double(f.a) <= 2;
--------------
drop table if exists t
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
create table t(f json)
--------------

Query OK, 0 rows affected (0.00 sec)

--------------
insert into t(id,f) values(1,'{"a":2.5}')
--------------

Query OK, 1 row affected (0.00 sec)

--------------
select * from t where double(f.a) <= 2
--------------

+------+----------------+
| id   | f              |
+------+----------------+
|    1 | {"a":2.500000} |
+------+----------------+
1 row in set (0.00 sec)
--- 1 out of 1 results in 0ms ---

from manticoresearch.

tomatolog avatar tomatolog commented on May 26, 2024

seems the right form that works now is the

select * from t where f.a <= 2.0;
Empty set (0.00 sec)
--- 0 out of 0 results in 0ms ---

from manticoresearch.

Nick-S-2018 avatar Nick-S-2018 commented on May 26, 2024

It looks like the correct float comparison can be guaranteed for int numbers with less than 7 digits; the limit is 2097152 (the first 22-bit number in binary format). For the numbers less than that conversion to float should work fine, like in the example above; for the larger numbers precision loss appears.

from manticoresearch.

sanikolaev avatar sanikolaev commented on May 26, 2024

It looks like the correct float comparison can be guaranteed for int numbers with less than 7 digits

Is this what you mean by the general theory of float comparison or you mean our specific case?

from manticoresearch.

sanikolaev avatar sanikolaev commented on May 26, 2024

mysql > select * from t where f.a <= 2;

Nick has an idea of converting N to N.0 in this case when N is in a specific range. @Nick-S-2018 pls provide more details.

from manticoresearch.

Nick-S-2018 avatar Nick-S-2018 commented on May 26, 2024

Unfortunately, this idea guarantees only the precision for values with a certain number of digits. E.g., '+-2097152' range would fix the issue only for values with one digit after decimal point, like in the original example. The more digits after the point a stored value has, the lesser such range would became. So, this approach does not look effective.

from manticoresearch.

Nick-S-2018 avatar Nick-S-2018 commented on May 26, 2024

Elastic always converts the compared value to the data type of the compared field. In case of a JSON object attribute, its type is defined by the detected type of the first inserted value, unless it has been set explicitly on the index creation . By default, Elastic detects numbers with floating points as 'floats', so the compared numeric value will be converted to 'float'. However, if 'double' has been set as the attribute data type, the compared value will be treated as 'double' too.

from manticoresearch.

sanikolaev avatar sanikolaev commented on May 26, 2024

As discussed, we'll implement support for where double(f.a) <= 2.

from manticoresearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.