You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "chouc (Jira)" <ji...@apache.org> on 2022/04/16 07:53:00 UTC

[jira] [Created] (FLINK-27268) build sql query error in JdbcDynamicTableSource

chouc created FLINK-27268:
-----------------------------

             Summary: build sql query error in JdbcDynamicTableSource
                 Key: FLINK-27268
                 URL: https://issues.apache.org/jira/browse/FLINK-27268
             Project: Flink
          Issue Type: Improvement
          Components: Connectors / JDBC
    Affects Versions: 1.16.0
            Reporter: chouc
             Fix For: 1.16.0


h1. # Condidtion

build sql query error in JdbcDynamicTableSource

 
{code:java}
//代码占位符
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
        String createMysqlTableMapping = "CREATE TABLE table(\n" +
            "id int \n" +
            " )  WITH (\n" +
            "    'connector' = 'jdbc',\n" +
            "    'url' = 'jdbc:mysql://s1:3306/db',\n" +
            "    'username' = '',\n" +
            "    'password' = '',\n" +
            "    'table-name' = 'table_name'" +
            ")\n";        String countSql = "select count(1) from t_ds_task_instance";
        tenv.executeSql(createMysqlTableMapping).print();
        tenv.executeSql(countSql).print(); {code}
h1. ERROR
{code:java}
//代码占位符
Caused by: java.lang.IllegalArgumentException: open() failed.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `table`' at line 1
  at org.apache.flink.connector.jdbc.table.JdbcRowDataInputFormat.open(JdbcRowDataInputFormat.java:207)
  at org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction.run(InputFormatSourceFunction.java:84)
  at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:110)
  at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:67)
  at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:332)
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `table`' at line 1
  at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
  at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
  at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1009)
  at org.apache.flink.connector.jdbc.table.JdbcRowDataInputFormat.open(JdbcRowDataInputFormat.java:204)
  ... 4 more {code}
 
h1. Reason

because constants cann't be push to jdbc sql as columns, when user query single constants in a table,and result to build sql state error

 

 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)