开发者社区> 问答> 正文

How to execute multi SQL in one job

I have multi batch SQL commands separated by semicolon(;). The SQL commands need to be executed in order(In other cases, the SQL command may share sources or sinks). I want to execute them in one job. When I use tableEnv.executeSql(multiSQL), it will throw errors. How can I execute them in one job? Thanks.*来自志愿者整理的flink邮件归档

展开
收起
彗星halation 2021-12-02 17:27:40 579 0
1 条回答
写回答
取消 提交回答
  • Hi, you can do like this:

    val statementSet = tableEnv.createStatementSet()
    val insertSqlBuffer = ListBuffer.empty[String]
    
    val calciteParser = new CalciteParser(SqlUtil.getSqlParserConfig(tableEnv.getConfig))
    sqlArr
    .foreach(item => {
    println(item)
    val itemNode = calciteParser.parse(item)
    
    itemNode match {
    case sqlSet: SqlSet => {
    configuration.setString(sqlSet.getKeyString, sqlSet.getValueString)
    }
    case _: RichSqlInsert => insertSqlBuffer += item
    case _ => {
    println(item)
    val itemResult = tableEnv.executeSql(item)
    itemResult.print()
    }
    }
    })
    
    // execute batch inserts
    if (insertSqlBuffer.size > 0) {
    insertSqlBuffer.foreach(item => {
    println("insert sql: " + item)
    statementSet.addInsertSql(item)
    })
    val explain = statementSet.explain()
    println(explain)
    statementSet.execute()
    }
    
    ```*来自志愿者整理的FLINK邮件归档
    2021-12-02 17:44:14
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载