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

[Bug]: load data inline does not work when specifying fields enclosed by '"' by throwing an error ERROR 20301 (HY000): invalid input: csvParser error: unterminated quoted field #16794

Closed
1 task done
aronchanisme opened this issue Jun 11, 2024 · 9 comments
Assignees
Labels
kind/bug Something isn't working phase/testing severity/s0 Extreme impact: Cause the application to break down and seriously affect the use
Milestone

Comments

@aronchanisme
Copy link
Contributor

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

1.2-dev

Commit ID

a5c552e

Other Environment Information

- Hardware parameters: 8c 16g ssd
- OS type: Debian 12 (kernal: 6.1.0-18-amd64)
- Others: none

Actual Behavior

load data inline does not work when specifying fields enclosed by '"' by throwing an error ERROR 20301 (HY000): invalid input: csvParser error: unterminated quoted field

MySQL [test]> drop table user;
Query OK, 0 rows affected (0.016 sec)

MySQL [test]> create table user (name varchar(25), age int, city varchar(25));
Query OK, 0 rows affected (0.013 sec)

MySQL [test]> system cat /tmp/1.csv
"A","23","Hello"
MySQL [test]> load data local infile '/tmp/1.csv' into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
Query OK, 1 row affected (0.011 sec)

MySQL [test]> select * from user;
+------+------+-------+
| name | age  | city  |
+------+------+-------+
| A    |   23 | Hello |
+------+------+-------+
1 row in set (0.004 sec)

MySQL [test]> load data inline format='csv', data=$XXX$
    -> "zhangsan","26","Shanxi;Xian" $XXX$
    -> into table user
    -> fields terminated by ',' enclosed by '"'
    -> lines terminated by '\n'
    -> (name,age,city);
ERROR 20301 (HY000): invalid input: csvParser error: unterminated quoted field
MySQL [test]> load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi;Xian" $XXX$ into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
ERROR 20301 (HY000): invalid input: csvParser error: unterminated quoted field
MySQL [test]> load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi" $XXX$ into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
ERROR 20301 (HY000): invalid input: csvParser error: unterminated quoted field
MySQL [test]> system vi /tmp/2.csv
MySQL [test]> load data local infile '/tmp/2.csv' into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
Query OK, 1 row affected (0.004 sec)

MySQL [test]> system cat /tmp/2.csv
"zhangsan","26","Shanxi;Xian"
MySQL [test]> select * from test.user;
+----------+------+-------------+
| name     | age  | city        |
+----------+------+-------------+
| A        |   23 | Hello       |
| zhangsan |   26 | Shanxi;Xian |
+----------+------+-------------+
2 rows in set (0.001 sec)

MySQL [test]> select git_version();
+---------------+
| git_version() |
+---------------+
| a5c552ef5     |
+---------------+
1 row in set (0.001 sec)

Expected Behavior

Given an csv file, which contains content like this

"zhangsan","26","Shanxi;Xian"

Both mo and mysql can load data local infile from the csv file and put data into the table successfully, however mo's load data inline way to load the data directly from sql statement failed. The expectation is below sql works

load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi" $XXX$ into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi;XiAn" $XXX$ into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);

Expected result of a select * from test.user after the load:

MySQL [test]> select * from test.user;
+------------+------+-------------+
| name       | age  | city        |
+------------+------+-------------+
| zhangsan   |   26 | Shanxi|
| zhangsan   |   26 | Shanxi;Xian |
+------------+------+-------------+
2 rows in set (0.001 sec)

Steps to Reproduce

create database if not exists test;
use test;
drop table if exists user;
create table user (name varchar(25), age int, city varchar(25));
load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi" $XXX$ into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi;XiAn" $XXX$ into table test.user fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
select * from user;

Additional information

#16790

@aronchanisme aronchanisme added kind/bug Something isn't working needs-triage severity/s0 Extreme impact: Cause the application to break down and seriously affect the use mysql-compability labels Jun 11, 2024
@aronchanisme aronchanisme added this to the 1.2.1 milestone Jun 11, 2024
@aronchanisme
Copy link
Contributor Author

#16790 is stuck by this issue.

@jensenojs
Copy link
Contributor

image

@aronchanisme load data infile是能正确支持的, 我看了一下文档load data inline是没有那些 terminated by enclosed by lines terminated by 之类的说明的, load data inline可能是没有做这些解析的. 莫尘当时做这个东西的时候可能就没打算支持这些东西

@aronchanisme aronchanisme modified the milestones: 1.2.1, 1.2.2 Jun 12, 2024
@aressu1985 aressu1985 modified the milestones: 1.2.2, 1.3.0 Jul 7, 2024
@jensenojs
Copy link
Contributor

not working ont it

@jensenojs jensenojs assigned huby2358 and unassigned jensenojs Aug 15, 2024
@huby2358
Copy link
Contributor

image

@huby2358
Copy link
Contributor

之前改的有问题,csvparser这块还要再看一下

@huby2358
Copy link
Contributor

这个load data inline失败,load data infile成功,是因为$XXX$ "zhangsan","26","Shanxi" $XXX$, 是因为数据data前后有空格,如果是$XXX$"zhangsan","26","Shanxi"$XXX$, 这个load 成功,这个data才和上面load data infile的内容相同,如果load data infile里面第一个字段内容后最后一个有空格,也会报错。

@aronchanisme
Copy link
Contributor Author

Syntax issue. Doc needs to be updated.

root@test0:~# mo_ctl connect
2024-08-28 15:55:00.321 UTC+0800    [INFO]    Checking connectivity
2024-08-28 15:55:00.368 UTC+0800    [INFO]    Ok, connecting for user ... 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9087
Server version: 8.0.30-MatrixOne-v1.2.2 MatrixOne

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table t2(name varchar(25),age int,city varchar(25));
Query OK, 0 rows affected (0.02 sec)

mysql> load data inline format='csv', data=$XXX$"zhangsan","26","Shanxi;XiAn"$XXX$ into table t2 fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
Query OK, 1 row affected (0.01 sec)

mysql> select * from t2;
+----------+------+-------------+
| name     | age  | city        |
+----------+------+-------------+
| zhangsan |   26 | Shanxi;XiAn |
+----------+------+-------------+
1 row in set (0.00 sec)

mysql> load data inline format='csv', data=$XXX$ "zhangsan","26","Shanxi;XiAn" $XXX$ into table t2 fields terminated by ',' enclosed by '"'  lines terminated by '\n' (name,age,city);
ERROR 20301 (HY000): invalid input: csvParser error: unterminated quoted field

mysql> select git_version();
+---------------+
| git_version() |
+---------------+
| 74f81f7       |
+---------------+
1 row in set (0.00 sec)

@huby2358
Copy link
Contributor

跟产品和测试对齐了,保持现状,不用修改了

@aronchanisme
Copy link
Contributor Author

Doc request : matrixorigin/matrixorigin.io#589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working phase/testing severity/s0 Extreme impact: Cause the application to break down and seriously affect the use
Projects
None yet
Development

No branches or pull requests

6 participants