-
Notifications
You must be signed in to change notification settings - Fork 439
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
[BUG] myloader of table with json column fails when mydumper uses --load-data #574
Comments
I think the issue is this: select into outfile escapes control characters inside strings. ie. backslash becomes double backslash. That's really the only difference I can see when I compare a .dat file produced via both methods. |
@matthewlenz, Can you test using --fields-escaped-by with a different character? |
@davidducos sorry, not sure what you are asking. Is there a reason why you wouldn't want the default .dat export functionality from mydumper to match what mysql does by default? |
@matthewlenz I was not able to reproduce your issue. Can you provide a test case? And let us know what version of database are you using. |
I found the REAL issue. mydumper --load-data dumps NULL fields as NULL. select into outfile dumps NULL as \N Edit: I'm running the newest Percona mysql 8.0.26 release. One other thing and I don't know if it matters but I am running latin1 for everything on this db. |
Actually, I just looked at the data in all the tables. It's just inserting null and table defaults into every record. hmm. |
It says that you have a problem in the column data in the row 0, if I didn't read the error message incorrectly. |
Mydumper without --load-data + myloader = works |
Hi @matthewlenz sorry to hear that, but Can you provide a test case? just one small table where this is falling will help me to reproduce and fix MyDumper. |
Yeah, I can try. It doesn't seem to be consistent though and it's driving me batty. Do you think it has anything to do with the server being set to character-set-server = latin1 and collation-server = latin1_swedish_ci ? |
If data can not be inserted, it should be a consistent issue. It might be related to character set and collations, but I think that once that we have a test case, we are going to be able to find the solution. |
Well. This isn't fixed. Reopening while I do more debugging. I thought it was due to the compression of the .dat files (per the new bug) but it's not. |
@davidducos see if this causes an issue with your test server:
With mine I get:
EDIT: If I do the following:
then the load is successful. |
@davidducos even crazier. Mysql only seems to care if json fields use \N instead of NULL:
Try myloader without and with:
Keep in mind this only adjusts the json value. Not the int that defaults to null as well. |
Oh!!! so, when it is JSON needs to be \N and when it is other needs to be NULL... that is a simple fix... please, confirm and will be doing the fix later today. |
For load data NULL always needs to be \N. I overlooked this but if you use the string NULL for any field you get inconsistent results. I overlooked this but If you use my example above and let that single 'someint' value remain as NULL in the .dat file then it gets set to "0" instead of NULL in the db.
Results in the correct import (see that I removed the eol anchor $ from the regexp). |
@matthewlenz, Can you check branch https://github.com/mydumper/mydumper/tree/fix_574 ? |
Oooof. I just looked at a text field that allows NULL as well and it actually put the string "NULL" in the text field rather than setting it to NULL. |
That looks right to me. Did you need me to try to build it from source? |
FYI, according to the mysql site these are the defaults that mysql uses for load data and select into outfile:
It also states that any escape characters themselves must be escaped for proper importing. That might explain why there are differences in the escaping between default mydumper --load-data and mysql select into outfile defaults. EDIT: put in code block because it wasn't showing the double backslash on escaped by. |
No worries, I already test it. BTW, with string
|
that's really odd. Maybe it's the server character set thing or a difference in mysql versions (percona mysql 8.0.26-17 for me). Or maybe it's to do with allowing NULL vs defaulting to NULL? What was the schema on that table? |
Oh god... I'm reviewing https://dev.mysql.com/doc/refman/8.0/en/load-data.html for NULL values, and there are lots of cases depending in the options of LOAD data. mydumper is only appending those options if they are selected but I'm not going to add the logic to determine the right value (NULL or \N) that represents NULL values. |
Yeah, it's incredibly confusing. The details are spread across multiple pages as well. Honestly I think the best solution is to use the same defaults as mysql and make sure that mydumper/loader (by default) matches mysql select into outfile defaults. I think the main differences I see right now are the NULL issue (which you are fixing) and how mysql select into outfile defaults to the |
@davidducos I thought we'd figured this one out but it appears not. |
Difference appears to be maybe the quoting? Do you use the same escaping defaults as mysql?
|
Actually this doesn't appear to be related to this bug. You were tracking it on #437 |
@matthewlenz is this resolved? has #437 fixed it? do you need more work on my side? |
I'll try to load some data that used --load-data tomorrow when I get into the office and report back. |
Still fails with mydumper0.13.1-1, built against MySQL 5.7.40-43 with SSL support with GZIP Cannot create a JSON value from a string with CHARACTER SET 'binary'. |
@davidducos thanks! I'll check it out next release and report back if I find any issues. |
@matthewlenz no need, I finally understood what is the issue... not sure how we are going to be able to sort it out |
What issue did you identify? Did mydumper always set names to binary when doing dump? or was that something that was added more recently? |
@matthewlenz we need to do the same CONVERT that we do when we create the INSERT INTO statement. I already have a fix for it, actually, it was simpler than I thought. |
Mysql bug or myloader?
** (myloader:12325): CRITICAL **: 11:09:25.761: Error occours between lines: 6 and 8 on file db_name.tbDoc.00000.sql.gz: Invalid JSON text: "Invalid value." at position 0 in value for column 'table_name.data'.
The text was updated successfully, but these errors were encountered: