Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: flink sql 读取已存在的表报错
TiDB version 6.1
Flink version 1.15.2
The data in TiDB was written by Flink SQL last time, and there is a problem when querying today.
Below is the table creation statement on the Flink side:
CREATE TABLE MyUserTable (
id STRING,
name STRING,
age STRING,
status STRING,
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:mysql://10.19.36.83:4000/fromflink152',
'table-name' = 'users',
'username' = 'root',
'password' = 'NU75_KVk6#R813c@!p'
);
This error looks like a syntax error. You can check the corresponding TiDB log, which should contain specific SQL information.
Post the code so we can take a look; it’s showing a syntax error.
Here is an example:
cat tidb.log
[2022/10/10 14:09:29.732 +08:00] [INFO] [conn.go:1165] ["command dispatched failed"] [conn=6079643992671126491] [connInfo="id:6079643992671126491, addr:127.0.0.1:12790 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="select * form t"] [txn_mode=PESSIMISTIC] [timestamp=0] [err="[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 13 near \"form t\" "]
On the Flink SQL side, I created a table based on the existing TiDB table with data and executed the statement “select count(*) from MyUserTable.”
Additionally, “select * from MyUserTable;” works fine. Is it that Flink SQL cannot directly execute “select count(*)” on the table, or am I missing some conditions when creating the table on the Flink side?
Directly go to the TiDB server or dashboard to match and find the relevant SQL. The keyword is: command dispatched failed. It should be in the tidb.log log.
The query “select count(id) from MyUserTable;” also doesn’t work, the corresponding collect job keeps restarting. However, “select count(distinct id) from MyUserTable;” works and returns results quickly.
This image shows some logs of select count(*) above. It doesn’t seem to be a syntax error. “users” is the name of the table on the TiDB side, and “MyUserTable” is the table name on the Flink SQL side.
It’s already very obvious, there’s no * between select and from.
This log actually corresponds to select count(*) from MyUserTable;
In other words, after this SQL is input on the Flink side, it is finally parsed as select from users
on the TiDB side, right?
This is not the database parsing into this SQL; the SQL sent by the application is like this. The database cannot parse it, so the problem lies earlier.
Yes, it seems that the problem lies with Flink and the SQL I used. I’ll try again later with a different scenario and integration with Flink.
Will there be any issues if the data source is switched to MySQL?
It shouldn’t be, it’s compatible.
It is indeed related to the Flink version. It is estimated that using the released version would not have this problem. However, I used a self-compiled version of Flink 1.15.2 from some time ago, and this situation occurs whether querying MySQL or TiDB with Flink SQL. It should be easy to reproduce.
Then it’s much simpler if it’s confirmed to be Flink. Since you’re using 1.15, it probably isn’t a production environment. I still recommend using 1.14 or below.
Try using the stable version of Flink 1.14.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.