Use Druid to split sql (#15367)
This commit is contained in:
parent
c3ffb1330d
commit
bf2cdc5300
|
|
@ -34,7 +34,7 @@
|
|||
<java-websocket.version>1.5.1</java-websocket.version>
|
||||
<mybatis-plus.version>3.5.2</mybatis-plus.version>
|
||||
<quartz.version>2.3.2</quartz.version>
|
||||
<druid.version>1.2.4</druid.version>
|
||||
<druid.version>1.2.20</druid.version>
|
||||
<curator-test.version>2.12.0</curator-test.version>
|
||||
<jetcd.version>0.5.11</jetcd.version>
|
||||
<jetcd.test.version>0.7.1</jetcd.test.version>
|
||||
|
|
|
|||
|
|
@ -140,5 +140,11 @@
|
|||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -29,12 +29,14 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import java.sql.Connection;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
|
|
@ -128,4 +130,9 @@ public abstract class AbstractDataSourceProcessor implements DataSourceProcessor
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.other);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.spi.enums.DbType;
|
|||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public interface DataSourceProcessor {
|
||||
|
||||
|
|
@ -113,4 +114,6 @@ public interface DataSourceProcessor {
|
|||
* get datasource processor
|
||||
*/
|
||||
DataSourceProcessor create();
|
||||
|
||||
List<String> splitAndRemoveComment(String sql);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class AbstractDataSourceProcessorTest {
|
|||
doThrow(new IllegalArgumentException()).when(mockDataSourceProcessor).checkOther(other);
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
@Test
|
||||
public void transformOtherParamToMap() {
|
||||
AbstractDataSourceProcessor abstractDataSourceProcessor = new AbstractDataSourceProcessor() {
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -126,6 +127,11 @@ public class ClickHouseDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new ClickHouseDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.clickhouse);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isEmpty(otherMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -132,6 +133,11 @@ public class DamengDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new DamengDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.dm);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> paramMap) {
|
||||
if (MapUtils.isEmpty(paramMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -126,6 +127,11 @@ public class Db2DataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return DataSourceConstants.DB2_VALIDATION_QUERY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.db2);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isEmpty(otherMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
|
|||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
|
@ -122,4 +123,18 @@ public class DorisDataSourceProcessorTest {
|
|||
dorisDatasourceProcessor.getDatasourceUniqueId(dorisConnectionParam, DbType.DORIS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitAndRemoveComment() {
|
||||
String sql =
|
||||
"set enable_unique_key_partial_update = true;\r\n\r\n" +
|
||||
"insert into demo.table\r\n(age,name)\r\nselect 1, 'tom';\r\n\r\n" +
|
||||
"set enable_unique_key_partial_update = false;\r\n\r\n\r\n";
|
||||
List<String> sqls = dorisDatasourceProcessor.splitAndRemoveComment(sql);
|
||||
Assertions.assertEquals(3, sqls.size());
|
||||
Assertions.assertEquals("set enable_unique_key_partial_update = true", sqls.get(0));
|
||||
Assertions.assertEquals("insert into demo.table\r\n(age,name)\r\nselect 1, 'tom'", sqls.get(1));
|
||||
Assertions.assertEquals("set enable_unique_key_partial_update = false", sqls.get(2));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -149,6 +150,11 @@ public class HiveDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new HiveDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.hive);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isEmpty(otherMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dolphinscheduler.plugin.datasource.k8s.param;
|
||||
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.AbstractDataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
|
||||
|
|
@ -38,7 +39,7 @@ import com.google.auto.service.AutoService;
|
|||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
@Slf4j
|
||||
public class K8sDataSourceProcessor implements DataSourceProcessor {
|
||||
public class K8sDataSourceProcessor extends AbstractDataSourceProcessor {
|
||||
|
||||
@Override
|
||||
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.Map;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -152,6 +153,11 @@ public class MySQLDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new MySQLDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.mysql);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> paramMap) {
|
||||
if (MapUtils.isEmpty(paramMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
|
|||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
|
@ -31,6 +32,8 @@ import org.mockito.MockedStatic;
|
|||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MySQLDataSourceProcessorTest {
|
||||
|
||||
|
|
@ -104,4 +107,20 @@ public class MySQLDataSourceProcessorTest {
|
|||
mysqlDatasourceProcessor.getDatasourceUniqueId(mysqlConnectionParam, DbType.MYSQL));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitAndRemoveComment() {
|
||||
String sql = "select * from table1;\nselect * from table2;\nselect * from table3;\r\n";
|
||||
List<String> expect = Lists.newArrayList(
|
||||
"select * from table1",
|
||||
"select * from table2",
|
||||
"select * from table3");
|
||||
Assertions.assertEquals(expect, mysqlDatasourceProcessor.splitAndRemoveComment(sql));
|
||||
|
||||
// Variable
|
||||
sql = "select * from ${table1};";
|
||||
expect = Lists.newArrayList("select * from ${table1}");
|
||||
Assertions.assertEquals(expect, mysqlDatasourceProcessor.splitAndRemoveComment(sql));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.Map;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@Slf4j
|
||||
|
|
@ -188,4 +189,9 @@ public class OceanBaseDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
public DataSourceProcessor create() {
|
||||
return new OceanBaseDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.oceanbase);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,12 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -142,6 +147,13 @@ public class OracleDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new OracleDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
SQLStatementParser parser = new OracleStatementParser(sql, SQLParserFeature.KeepComments);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
return statementList.stream().map(SQLStatement::toString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isEmpty(otherMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.spi.enums.DbConnectType;
|
|||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
|
@ -101,4 +102,66 @@ public class OracleDataSourceProcessorTest {
|
|||
Assertions.assertEquals(DataSourceConstants.ORACLE_VALIDATION_QUERY,
|
||||
oracleDatasourceProcessor.getValidationQuery());
|
||||
}
|
||||
|
||||
@Test
|
||||
void splitAndRemoveComment_PLSQL() {
|
||||
String plSql = "DECLARE\n" +
|
||||
" bonus NUMBER(8,2);\n" +
|
||||
"BEGIN\n" +
|
||||
" SELECT salary * 0.10 INTO bonus\n" +
|
||||
" FROM employees\n" +
|
||||
" WHERE employee_id = 100;\n" +
|
||||
"END;\n" +
|
||||
"\n" +
|
||||
"DBMS_OUTPUT.PUT_LINE('bonus = ' || TO_CHAR(bonus));\n";
|
||||
List<String> sqls = oracleDatasourceProcessor.splitAndRemoveComment(plSql);
|
||||
// We will not split the plsql
|
||||
Assertions.assertEquals(2, sqls.size());
|
||||
Assertions.assertEquals("DECLARE\n" +
|
||||
"\tbonus NUMBER(8, 2);\n" +
|
||||
"BEGIN\n" +
|
||||
"\tSELECT salary * 0.10\n" +
|
||||
"\tINTO bonus\n" +
|
||||
"\tFROM employees\n" +
|
||||
"\tWHERE employee_id = 100;\n" +
|
||||
"END;", sqls.get(0));
|
||||
Assertions.assertEquals("DBMS_OUTPUT.PUT_LINE('bonus = ' || TO_CHAR(bonus));", sqls.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void splitAndRemoveComment_PLSQLWithComment() {
|
||||
String plSql = "DECLARE\n" +
|
||||
" CURSOR my_cursor IS SELECT column1, column2 FROM my_table;\n" +
|
||||
" -- Declare variables to hold column values\n" +
|
||||
"BEGIN\n" +
|
||||
" OPEN my_cursor;\n" +
|
||||
" FETCH my_cursor INTO variable1, variable2;\n" +
|
||||
" -- Process data\n" +
|
||||
" CLOSE my_cursor;\n" +
|
||||
"END;";
|
||||
List<String> sqls = oracleDatasourceProcessor.splitAndRemoveComment(plSql);
|
||||
// We will not split the plsql
|
||||
Assertions.assertEquals(1, sqls.size());
|
||||
Assertions.assertEquals("DECLARE\n" +
|
||||
"\tCURSOR my_cursor IS\n" +
|
||||
"\t\tSELECT column1, column2\n" +
|
||||
"\t\tFROM my_table;\n" +
|
||||
"BEGIN\n" +
|
||||
"\tOPEN my_cursor;\n" +
|
||||
"\tFETCH my_cursor INTO variable1, variable2;\n" +
|
||||
"\tCLOSE my_cursor;\n" +
|
||||
"END;", sqls.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void splitAndRemoveComment_MultipleSql() {
|
||||
String plSql = "select * from test;select * from test2;";
|
||||
List<String> sqls = oracleDatasourceProcessor.splitAndRemoveComment(plSql);
|
||||
// We will not split the plsql
|
||||
Assertions.assertEquals(2, sqls.size());
|
||||
Assertions.assertEquals("SELECT *\n" +
|
||||
"FROM test;", sqls.get(0));
|
||||
Assertions.assertEquals("SELECT *\n" +
|
||||
"FROM test2;", sqls.get(1));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -128,6 +129,11 @@ public class PostgreSQLDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new PostgreSQLDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.postgresql);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isEmpty(otherMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dolphinscheduler.plugin.datasource.sagemaker.param;
|
||||
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.AbstractDataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
|
||||
|
|
@ -36,7 +37,7 @@ import com.google.auto.service.AutoService;
|
|||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
@Slf4j
|
||||
public class SagemakerDataSourceProcessor implements DataSourceProcessor {
|
||||
public class SagemakerDataSourceProcessor extends AbstractDataSourceProcessor {
|
||||
|
||||
@Override
|
||||
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) {
|
||||
|
|
|
|||
|
|
@ -33,8 +33,10 @@ import org.apache.commons.collections4.MapUtils;
|
|||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -124,6 +126,11 @@ public class SQLServerDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new SQLServerDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.sqlserver);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isEmpty(otherMap)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dolphinscheduler.plugin.datasource.ssh.param;
|
||||
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.AbstractDataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
|
||||
|
|
@ -36,7 +37,7 @@ import com.google.auto.service.AutoService;
|
|||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
@Slf4j
|
||||
public class SSHDataSourceProcessor implements DataSourceProcessor {
|
||||
public class SSHDataSourceProcessor extends AbstractDataSourceProcessor {
|
||||
|
||||
@Override
|
||||
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.google.auto.service.AutoService;
|
||||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
|
|
@ -128,6 +129,11 @@ public class TrinoDataSourceProcessor extends AbstractDataSourceProcessor {
|
|||
return new TrinoDataSourceProcessor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> splitAndRemoveComment(String sql) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, com.alibaba.druid.DbType.trino);
|
||||
}
|
||||
|
||||
private String transformOther(Map<String, String> otherMap) {
|
||||
if (MapUtils.isNotEmpty(otherMap)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dolphinscheduler.plugin.datasource.zeppelin.param;
|
||||
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.AbstractDataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
|
||||
|
|
@ -36,7 +37,7 @@ import com.google.auto.service.AutoService;
|
|||
|
||||
@AutoService(DataSourceProcessor.class)
|
||||
@Slf4j
|
||||
public class ZeppelinDataSourceProcessor implements DataSourceProcessor {
|
||||
public class ZeppelinDataSourceProcessor extends AbstractDataSourceProcessor {
|
||||
|
||||
@Override
|
||||
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) {
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
|
|||
datanucleus-core 4.1.17: https://mvnrepository.com/artifact/org.datanucleus/datanucleus-core/4.1.17, Apache 2.0
|
||||
datanucleus-rdbms 4.1.19: https://mvnrepository.com/artifact/org.datanucleus/datanucleus-rdbms/4.1.19, Apache 2.0
|
||||
derby 10.14.2.0: https://github.com/apache/derby, Apache 2.0
|
||||
druid 1.1.14: https://mvnrepository.com/artifact/com.alibaba/druid/1.1.14, Apache 2.0
|
||||
druid 1.2.20: https://mvnrepository.com/artifact/com.alibaba/druid/1.2.20, Apache 2.0
|
||||
metrics-core 4.2.11: https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-core, Apache 2.0
|
||||
error_prone_annotations 2.1.3 https://mvnrepository.com/artifact/com.google.errorprone/error_prone_annotations/2.1.3, Apache 2.0
|
||||
gson 2.9.1: https://github.com/google/gson, Apache 2.0
|
||||
|
|
|
|||
|
|
@ -1,13 +1,201 @@
|
|||
Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
1. Definitions.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
@ -27,6 +27,18 @@
|
|||
<artifactId>dolphinscheduler-task-sql</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
<artifactId>dolphinscheduler-bom</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dolphinscheduler</groupId>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.plugin.task.sql;
|
|||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceClientProvider;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceProcessorProvider;
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.AbstractTask;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.SQLTaskExecutionContext;
|
||||
|
|
@ -37,7 +38,6 @@ import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters;
|
|||
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.UdfFuncParameters;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.resource.ResourceContext;
|
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
|
||||
import org.apache.dolphinscheduler.plugin.task.sql.utils.SqlSplitUtils;
|
||||
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
|
||||
import org.apache.dolphinscheduler.spi.enums.DbType;
|
||||
|
||||
|
|
@ -52,7 +52,6 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -134,9 +133,8 @@ public class SqlTask extends AbstractTask {
|
|||
// get datasource
|
||||
baseConnectionParam = (BaseConnectionParam) DataSourceUtils.buildConnectionParams(dbType,
|
||||
sqlTaskExecutionContext.getConnectionParams());
|
||||
List<String> subSqls =
|
||||
dbType.isSupportMultipleStatement() ? Collections.singletonList(sqlParameters.getSql())
|
||||
: SqlSplitUtils.splitSql(sqlParameters.getSql());
|
||||
List<String> subSqls = DataSourceProcessorProvider.getDataSourceProcessor(dbType)
|
||||
.splitAndRemoveComment(sqlParameters.getSql());
|
||||
|
||||
// ready to execute SQL and parameter entity Map
|
||||
List<SqlBinds> mainStatementSqlBinds = subSqls
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.plugin.task.sql.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SqlSplitUtils {
|
||||
|
||||
private static final String UNIX_SQL_SEPARATOR = ";\n";
|
||||
private static final String WINDOWS_SQL_SEPARATOR = ";\r\n";
|
||||
|
||||
/**
|
||||
* split sql to submit sql.
|
||||
* e.g.
|
||||
* <pre>
|
||||
* select * from table1\n;select * from table2\n;select * from table2\r\n;
|
||||
* </pre>
|
||||
* will be split to
|
||||
* <pre>
|
||||
* select * from table1
|
||||
* select * from table2
|
||||
* </pre>
|
||||
*/
|
||||
public static List<String> splitSql(String sql) {
|
||||
|
||||
return Arrays.stream(sql.replaceAll(WINDOWS_SQL_SEPARATOR, UNIX_SQL_SEPARATOR).split(UNIX_SQL_SEPARATOR))
|
||||
.filter(subSql -> {
|
||||
String trim = subSql.trim();
|
||||
return !trim.isEmpty() && !trim.startsWith("--");
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.plugin.task.sql.utils;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
class SqlSplitUtilsTest {
|
||||
|
||||
@Test
|
||||
void splitSql() {
|
||||
String sql = "select * from table1;\nselect * from table2;\nselect * from table3;\r\n";
|
||||
Assertions.assertEquals(
|
||||
Lists.newArrayList("select * from table1", "select * from table2", "select * from table3"),
|
||||
SqlSplitUtils.splitSql(sql));
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ datanucleus-rdbms-4.1.19.jar
|
|||
datasync-2.17.282.jar
|
||||
derby-10.14.2.0.jar
|
||||
dnsjava-2.1.7.jar
|
||||
druid-1.2.4.jar
|
||||
druid-1.2.20.jar
|
||||
eventstream-1.0.1.jar
|
||||
error_prone_annotations-2.5.1.jar
|
||||
failureaccess-1.0.1.jar
|
||||
|
|
|
|||
Loading…
Reference in New Issue