JDBC Engine

This article mainly introduces the configuration, deployment and use of JDBC EngineConn in Linkis1.0.

If you want to use the JDBC EngineConn on your server, you need to prepare the JDBC connection information, such as the connection address, user name and password of the MySQL database, etc.

The JDBC EngineConn does not need to be compiled by the user, and the compiled JDBC EngineConn plug-in package can be used directly. Drivers that have been provided include MySQL, PostgreSQL, etc.

Here you can use the default loading method to use it normally, just install it according to the standard version.

Here you can use the default dml.sql to insert it and it can be used normally.

You need to configure JDBC connection information, including connection address information and user name and password.

JDBC Engine - 图1

Figure 3-1 JDBC configuration information

You can also specify in the RuntimeMap of the submitted task

  1. wds.linkis.jdbc.connect.url
  2. wds.linkis.jdbc.driver
  3. wds.linkis.jdbc.username
  4. wds.linkis.jdbc.password

You can also set parameters on the task submission interface.

  1. http request params example
  2. {
  3. "executionContent": {"code": "show databases;", "runType": "jdbc"},
  4. "params": {
  5. "variable": {},
  6. "configuration": {
  7. "runtime": {
  8. "wds.linkis.jdbc.connect.url":"jdbc:mysql://127.0.0.1:3306/test",
  9. "wds.linkis.jdbc.driver":"com.mysql.jdbc.Driver",
  10. "wds.linkis.jdbc.username":"test",
  11. "wds.linkis.jdbc.password":"test23"
  12. }
  13. }
  14. },
  15. "source": {"scriptPath": "file:///mnt/bdp/hadoop/1.sql"},
  16. "labels": {
  17. "engineType": "jdbc-4",
  18. "userCreator": "hadoop-IDE"
  19. }
  20. }

Linkis provides a client method to call jdbc tasks. The call method is through the SDK provided by LinkisClient. We provide java and scala two ways to call, the specific usage can refer to JAVA SDK Manual. If you use Hive, you only need to make the following changes:

  1. Map<String, Object> labels = new HashMap<String, Object>();
  2. labels.put(LabelKeyConstant.ENGINE_TYPE_KEY, "jdbc-4"); // required engineType Label
  3. labels.put(LabelKeyConstant.USER_CREATOR_TYPE_KEY, "hadoop-IDE");// required execute user and creator
  4. labels.put(LabelKeyConstant.CODE_TYPE_KEY, "jdbc"); // required codeType

After Linkis 1.0, you can submit tasks through cli. We only need to specify the corresponding EngineConn and CodeType tag types. The use of JDBC is as follows:

  1. sh ./bin/linkis-cli -engineType jdbc-4 -codeType jdbc -code "show tables" -submitUser hadoop -proxyUser hadoop

The specific usage can refer to Linkis CLI Manual.

The way to use Scriptis is the simplest. You can go directly to Scriptis, right-click the directory and create a new JDBC script, write JDBC code and click Execute.

The execution principle of JDBC is to load the JDBC Driver and submit sql to the SQL server for execution and obtain the result set and return.

JDBC Engine - 图2

Figure 3-2 Screenshot of the execution effect of JDBC

Linkis provides data source management function after 1.2.0, we can manage different data sources in the console. Address: Login management desktop —> DataSource Manage —> Add Source

JDBC Engine - 图3

Figure 3-3 DataSource Manage

JDBC Engine - 图4

Figure 3-4 DataSource Conn Test

After the data source is completed, you can use the JDBC multi-data source switch to add, there are functional methods:

  1. Specify the data source name parameter through the interface parameter, as shown below: JDBC Engine - 图5

Parameter example:

  1. {
  2. "executionContent": {"code": "show databases", "runType": "jdbc"},
  3. "params": {"variable": {}, "configuration": {"startup":{},
  4. "runtime":
  5. {
  6. "dataSources": {"wds.linkis.engine.runtime.datasource": "test_mysql"
  7. }
  8. }}},
  9. "source": {"scriptPath": ""},
  10. "labels": {
  11. "engineType": "jdbc-4",
  12. "userCreator": "linkis-IDE"
  13. }
  14. }

Parameter: wds.linkis.engine.runtime.datasource is a configuration with a fixed name, do not modify the name definition arbitrarily

  1. Through the Scripts code submission entry of DSS, drop down and filter the data sources to be submitted, as shown in the following figure: JDBC Engine - 图6

Currently dss-1.1.0 does not yet support drop-down selection of data source name, PR is under development, you can wait for subsequent releases or pay attention to related PRs: (https://github.com/WeBankFinTech/DataSphereStudio/issues/940)

Function description of multiple data sources:

1) In the previous version, the JDBC engine’s support for data sources was not perfect, especially when used with Scripts, the jdbc script type can only bind a set of JDBC engine parameters of the console. When we need to switch multiple data sources, we can only modify the connection parameters of the jdbc engine, which is troublesome.

2) With the data source management, we introduce the multi-data source switching function of the JDBC engine, which can realize that only by setting the data source name, the job can be submitted to different JDBC services, and ordinary users do not need to It maintains the connection information of the data source, avoids the complicated configuration, and also meets the security requirements of the data source connection password and other configurations.

3) The data source set in the multi-data source management can be loaded by the JDBC engine only after it is published, and the data source that has not expired, otherwise, different types of exception prompts will be fed back to the user.

4) The loading priority of jdbc engine parameters is: task submission parameters > select data source parameters > console JDBC engine parameters

JDBC user settings are mainly JDBC connection information, but it is recommended that users encrypt and manage this password and other information.