Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static table question #313

Open
KenXgh opened this issue Mar 16, 2015 · 5 comments
Open

static table question #313

KenXgh opened this issue Mar 16, 2015 · 5 comments

Comments

@KenXgh
Copy link

KenXgh commented Mar 16, 2015

Hello Modyllic Team,

We have a static table. Modyllic indicated that only specific rows changed and produced update statements against those rows.

We thought static tables were always completely dropped and then recreated. Are we wrong?

Here is the issue: it looks like the rows that Modyllic wants to change may not have actually changed, but that there is a number/decimal problem.

The current row says:

+-----------+-----------+----------------+
| currencyA | currencyB | conversionRate |
+-----------+-----------+----------------+
| USD       | AED       |          3.673 |
+-----------+-----------+----------------+

Modyllic wants to change it to 3.673 which we found curious, so we looked at our schema file. The value there is 3.6729999999999996. It appears Modyllic is doing some rounding on its own, our data looks different to what Modyllic things it should be, and Modyllic tries to change it again.

Can you look into this decimal/rounding issue? Thanks!

@aredridel
Copy link
Contributor

Modyllic actually calculates updates, because just trashing and reloading isn't safe given the presence of triggers and constraints.

@aredridel
Copy link
Contributor

The rounding looks like it's because the number is treated as a number inside PHP, which can't represent something to that precision:

php > echo 3.6729999999999996;
3.673

@iarna
Copy link
Contributor

iarna commented Apr 8, 2015

It looks like that conversion is also what the MySQL database does:

mysql> create table t (f float);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (3.6729999999999996);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+-------+
| f     |
+-------+
| 3.673 |
+-------+
1 row in set (0.00 sec)

@iarna
Copy link
Contributor

iarna commented Apr 8, 2015

So the question is why doesn't Modyllic consider them equivalent. It should be doing the same normalization on both of them and only then comparing. So even if it's normalization was bogus (and it doesn't appear to be) it should still have considered them equal.

Now, equality with floating point is always a bit sticky (MySQL considers that db value to be equal to neither 3.673 nor to 3.6729999999999996), so I think what we want to do is do a string compare, as PHP's equality operators are so magic as to be detrimental.

@iarna
Copy link
Contributor

iarna commented Apr 8, 2015

So comparison for the purposes of diffing is handled by Modyllic\Expression::equal_to.

Normalization goes to Modyllic\Expression\Value::normalize which in turn is going to use Modyllic\Type\Float::normalize which then explicitly makes the value a number by adding 0, for better or worse.

I think what we want to do is change the == in equal_to into a … strcmp … == 0 as strcmp will do string comparison, which will be the path of least surprise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants