hi all,

The current sql task cannot support multiple queries, but my project is
very emergency about this feature. I chang this  feature  in my local.but
I'm not sure if my change is reasonable, so i need some help or suggestions。

hive and sql use the same code to execute sql,

executeFuncAndSql(mainSqlBinds, preStatementSqlBinds,
postStatementSqlBinds, createFuncs);

But the problem here is that hive JDBC does not support multiple queries,
mysql mssql supports multiple queries. If both mysql mssql  and hive
supports multiple queries , so I consider the compatibility of the two
here, and modify it to split the sql statement according to the
conventional ";", but execute them one by one.

// support multiQueries 2020/9/16
String[] sqlsplit = mainSqlBinds.getSql().split(";");
if (sqlsplit.length == 0) {
    logger.error("please check sqlscript can splited by ';'");
    return;
}
Map<Integer, Property> sqlParamsMap = mainSqlBinds.getParamsMap();
for (String sqlscript : sqlsplit) {
    executeFuncAndSql(new SqlBinds(sqlscript, sqlParamsMap),
preStatementSqlBinds, postStatementSqlBinds, createFuncs);
}

I don’t know if this change is reasonable, I hope you can give some
reasonable suggestions

https://github.com/apache/incubator-dolphinscheduler/issues/3710

thk!

当前的sql组件支持正常的多条语句同时执行,但是我们项目对这个功能比较着急,我在本地做了修改,但是我不确定我改的是否合理。

希望得到大家的建议或者帮助。

跟踪代码发现,hive 与mysql 使用了同样的执行语句的入口:

executeFuncAndSql(mainSqlBinds, preStatementSqlBinds,
postStatementSqlBinds, createFuncs);


有些数据源可能直接在jdbc 的连接参数加上allowmultiqueries=true就可以,但是hive jdbc是不支持 批量sql支持的这个功能,

我的考虑是在不能确定其它的数据源是否也支持多sql查询的功能,所以使用";"分割sql语句依然保持一条一条的语句执行,这样能

保证这两种情况兼容,同样能够实现基本的功能,代码的改动量很少。修改成这样:

// support multiQueries 2020/9/16
String[] sqlsplit = mainSqlBinds.getSql().split(";");
if (sqlsplit.length == 0) {
    logger.error("please check sqlscript can splited by ';'");
    return;
}
Map<Integer, Property> sqlParamsMap = mainSqlBinds.getParamsMap();
for (String sqlscript : sqlsplit) {
    executeFuncAndSql(new SqlBinds(sqlscript, sqlParamsMap),
preStatementSqlBinds, postStatementSqlBinds, createFuncs);
}

这样修改是否合理,希望能够给予帮助或者建议。

谢谢! https://github.com/apache/incubator-dolphinscheduler/issues/3710

Reply via email to