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

Inconsistent behavior for '0000-00-00 00:00:00' garbage dates #210

Closed
osheroff opened this issue Apr 4, 2018 · 10 comments
Closed

Inconsistent behavior for '0000-00-00 00:00:00' garbage dates #210

osheroff opened this issue Apr 4, 2018 · 10 comments

Comments

@osheroff
Copy link
Collaborator

osheroff commented Apr 4, 2018

Hey guys,
I'm poking around on zendesk/maxwell#928 -- one of those issues where yeah, it sucks that mysql ever allowed '0000-00-00' dates, but with maxwell I tend towards "reproduce it faithfully, even if it's garbage".

binlog-connector has some differing behavior for timestamp/datetime columns when encountering these columns (note that I'm using deserializeDateAndTimeAsLong):

  • timestamps come back "I guess it's right" - it comes back as OL.
  • datetimes come back NULL, which seems wrong. See the checks in asUnixTime.

I guess I'd like it if they all came back as OL

Anyway, hope y'all are doing well.

@shyiko
Copy link
Owner

shyiko commented Apr 5, 2018

Hi Ben.

Makes sense. Fixed in 0.14.0 🐦.

To activate:

EventDeserializer eventDeserializer = new EventDeserializer();
eventDeserializer.setCompatibilityMode(CompatibilityMode.INVALID_DATE_AND_TIME_AS_ZERO, 
    ...rest/* order doesn't matter */);
binaryLogClient.setEventDeserializer(eventDeserializer);

🙇‍♂️

@shyiko shyiko closed this as completed Apr 5, 2018
@osheroff
Copy link
Collaborator Author

osheroff commented Apr 5, 2018

thanks Stanley! you are, as they say, the man.

@osheroff
Copy link
Collaborator Author

osheroff commented Apr 7, 2018

bah, sorry @shyiko, but after poking into some failing tests I realize that with this new behavior I can't distinguish between 0000-00-00 00:00:00 and 1970-01-01 00:00:00. guh. Maybe we represent 0000-00-00 as -1L?

@shyiko
Copy link
Owner

shyiko commented Apr 7, 2018

I don't think there is a way to distinguish between these two:

create table `test` (
   id int unsigned not null,
   test_timestamp timestamp
);

insert into test values(1, '0000-00-00 00:00:00');
insert into test values(2, '1970-01-01 00:00:00');
insert into test values(3, null);

select * from test;

+----+---------------------+
| id | test_timestamp |
+----+---------------------+
| 1 | 0000-00-00 00:00:00 |
| 2 | 0000-00-00 00:00:00 |
| 3 | 2018-04-05 06:15:35 |
+----+---------------------+
3 rows in set (0.00 sec)

(binlog contains zeros in both cases)

@osheroff
Copy link
Collaborator Author

osheroff commented Apr 7, 2018

ah, yes. that's true in the case of timestamps, but not in the case of datetime

@shyiko
Copy link
Owner

shyiko commented Apr 7, 2018

Alrighty :)

EventDeserializer eventDeserializer = new EventDeserializer();
eventDeserializer.setCompatibilityMode(
    CompatibilityMode.INVALID_DATE_AND_TIME_AS_NEGATIVE_ONE, 
    ...rest/* order doesn't matter */
);
binaryLogClient.setEventDeserializer(eventDeserializer);

(available in 0.15.0)
(Maven Central sync might take up to 25 minutes)

🎉

@osheroff
Copy link
Collaborator Author

ok @shyiko now you're really gonna kill me. I realize too late that 1969-12-31 23:59:59.999999 is -1. Do I care? argh. no. but do I want to get it right? argh. yes.

How about Long.MIN_VALUE instead? that is definitely not a valid datetime.

A millllllion apologies.

@shyiko
Copy link
Owner

shyiko commented Apr 12, 2018

:D No worries, Ben. I can't believe I haven't thought of this myself. I'll publish another release at 12pm, PDT (today).

@shyiko
Copy link
Owner

shyiko commented Apr 12, 2018

EventDeserializer eventDeserializer = new EventDeserializer();
eventDeserializer.setCompatibilityMode(
    CompatibilityMode.INVALID_DATE_AND_TIME_AS_MIN_VALUE, 
    ...rest/* order doesn't matter */
);
binaryLogClient.setEventDeserializer(eventDeserializer);

(0.16.0 published)

@shyiko shyiko reopened this Apr 12, 2018
@shyiko shyiko closed this as completed Apr 12, 2018
@shyiko
Copy link
Owner

shyiko commented Apr 12, 2018

@osheroff 0.16.1

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

2 participants