[ 
https://issues.apache.org/jira/browse/FLINK-25337?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17461167#comment-17461167
 ] 

vim-wang commented on FLINK-25337:
----------------------------------

英文不好,我用中文描述一下哈。

是想实现对一段sql做语法检测的功能,比如下面这段sql:

CREATE TABLE datagen (
  f1 BIGINT,
  f2 STRING
) WITH (
  'connector' = 'datagen',
  'rows-per-second' = '1'
);
CREATE TABLE print_table (
  f1 BIGINT,
  f2 STRING
) WITH (
  'connector' = 'print'
);
INSERT INTO print_table
SELECT 
  f1,
  f2
FROM datagen;

 

原本的实现方式是:

SqlParser sqlParser = SqlParser.create(sqls, sqlparserConfig); //sqls就是指上面那段sql
List<SqlNode> sqlNodeList = sqlParser.parseStmtList().getList();

for (SqlNode sqlNode : sqlNodeList) {
    Operation operation = 
SqlToOperationConverter.convert(planner.createFlinkPlanner(),catalogManager, 
sqlNode).get();

}

 

这样做就存在之前描述中的问题,INSERT INTO 
print_table,print_table写成任何值SqlToOperationConverter.convert都不会报异常。所以我后来把operation也做了处理,比如modifyOperations调用planner.translate(modifyOperations),这样功能也能实现,但多了不少代码。

想问问针对这个场景,有便捷的实现方式吗?希望大佬指点。

> Check whether the target table is valid when 
> SqlToOperationConverter.convertSqlInsert
> -------------------------------------------------------------------------------------
>
>                 Key: FLINK-25337
>                 URL: https://issues.apache.org/jira/browse/FLINK-25337
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table SQL / Planner
>    Affects Versions: 1.14.0
>            Reporter: vim-wang
>            Priority: Major
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> when I execute insert sql like "insert into t1 select ...", 
> If the t1 is not defined,sql will not throw an exception after 
> SqlToOperationConverter.convertSqlInsert(), I think this is unreasonable, why 
> not use catalogManager to check whether the target table is valid?



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

Reply via email to