MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value
always return 1 Analysis: Implementation used double to store value. longlong is better choice Fix: Use longlong for multiple_of and the value to store it and num_flag to check for decimals.
This commit is contained in:
parent
2c4c7c8b02
commit
4b67ff3b25
@ -4634,4 +4634,19 @@ ERROR HY000: Invalid value for keyword maxLength
|
|||||||
SET @schema= '{ "items" : ["str1"]}';
|
SET @schema= '{ "items" : ["str1"]}';
|
||||||
SELECT JSON_SCHEMA_VALID(@schema, '[]');
|
SELECT JSON_SCHEMA_VALID(@schema, '[]');
|
||||||
ERROR HY000: Invalid value for keyword items
|
ERROR HY000: Invalid value for keyword items
|
||||||
|
#
|
||||||
|
# MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value always return 1
|
||||||
|
#
|
||||||
|
SET @schema = '{
|
||||||
|
"multipleOf": 2
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000001');
|
||||||
|
JSON_SCHEMA_VALID(@schema, '9007900000000001')
|
||||||
|
0
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000060');
|
||||||
|
JSON_SCHEMA_VALID(@schema, '9007900000000060')
|
||||||
|
1
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000061');
|
||||||
|
JSON_SCHEMA_VALID(@schema, '9007900000000061')
|
||||||
|
0
|
||||||
# End of 11.1 test
|
# End of 11.1 test
|
||||||
|
@ -3533,4 +3533,15 @@ SET @schema= '{ "items" : ["str1"]}';
|
|||||||
SELECT JSON_SCHEMA_VALID(@schema, '[]');
|
SELECT JSON_SCHEMA_VALID(@schema, '[]');
|
||||||
|
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value always return 1
|
||||||
|
--echo #
|
||||||
|
SET @schema = '{
|
||||||
|
"multipleOf": 2
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000001');
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000060');
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema, '9007900000000061');
|
||||||
|
|
||||||
|
|
||||||
--echo # End of 11.1 test
|
--echo # End of 11.1 test
|
||||||
|
@ -771,13 +771,25 @@ bool Json_schema_multiple_of::validate(const json_engine_t *je,
|
|||||||
|
|
||||||
if (je->value_type != JSON_VALUE_NUMBER)
|
if (je->value_type != JSON_VALUE_NUMBER)
|
||||||
return false;
|
return false;
|
||||||
|
if (je->num_flags & JSON_NUM_FRAC_PART)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
double val= je->s.cs->strntod((char *) je->value,
|
double val= je->s.cs->strntod((char *) je->value,
|
||||||
je->value_len, &end, &err);
|
je->value_len, &end, &err);
|
||||||
double temp= val / multiple_of;
|
double temp= val / multiple_of;
|
||||||
bool res= (temp - (long long int)temp) == 0;
|
bool res= (temp - (long long int)temp) == 0;
|
||||||
|
||||||| parent of 628ce9d4f44... MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value
|
||||||
|
double val= je->s.cs->strntod((char *) je->value,
|
||||||
|
je->value_len, &end, &err);
|
||||||
|
double temp= val / this->value;
|
||||||
|
bool res= (temp - (long long int)temp) == 0;
|
||||||
|
=======
|
||||||
|
longlong val= je->s.cs->strntoll((char *) je->value,
|
||||||
|
je->value_len, 10, &end, &err);
|
||||||
|
>>>>>>> 628ce9d4f44... MDEV-30705: JSON_SCHEMA_VALID: schema with multipleOf for big value
|
||||||
|
|
||||||
return !res;
|
return val % multiple_of;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je,
|
bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je,
|
||||||
@ -789,19 +801,16 @@ bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je,
|
|||||||
int err= 0;
|
int err= 0;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
if (je->value_type != JSON_VALUE_NUMBER)
|
if (je->value_type != JSON_VALUE_NUMBER || (je->num_flags & JSON_NUM_FRAC_PART))
|
||||||
{
|
{
|
||||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
|
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double val= je->s.cs->strntod((char *) je->value,
|
longlong val= je->s.cs->strntoll((char *) je->value,
|
||||||
je->value_len, &end, &err);
|
je->value_len, 10, &end, &err);
|
||||||
if (val <= 0)
|
if (val <= 0)
|
||||||
{
|
|
||||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
|
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
multiple_of= val;
|
multiple_of= val;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -228,7 +228,8 @@ class Json_schema_minimum : public Json_schema_keyword
|
|||||||
class Json_schema_multiple_of : public Json_schema_keyword
|
class Json_schema_multiple_of : public Json_schema_keyword
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
double multiple_of;
|
longlong multiple_of;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool validate(const json_engine_t *je, const uchar *k_start= NULL,
|
bool validate(const json_engine_t *je, const uchar *k_start= NULL,
|
||||||
const uchar *k_end= NULL) override;
|
const uchar *k_end= NULL) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user