Typical Scenario: Exporting Data from HDFS to MOTService
Scenario
In MOTService, tables need to be updated based on the data version field in the tables. Tables outside MOTService do not support Upsert statements. You can use Loader to export these tables from HDFS to MOTService to update their data in batches.
Prerequisites
- You have obtained the username and password of the relational database.
- The input data must be in CSV format.
- You have created a human-machine user, for example, Loaderuser, and added the user to user groups hive (primary) and hadoop, and associated the user with the Manager_administrator role on FusionInsight Manager.
Procedure
Make preparations.
- Log in to the node where RTDServer is installed as user root and obtain the driver JAR file corresponding to the relational database, for example, opengaussjdbc-V500R002C00.jar in this scenario.
cd ${BIGDATA_HOME}/FusionInsight_FARMER_RTD_*/install/FusionInsight-RTD-*/RTD/rtdservice/WEB-INF/lib
- Save the JAR file obtained in 1 to the ${BIGDATA_HOME}/FusionInsight_Porter_*/install/FusionInsight-Sqoop-*/FusionInsight-Sqoop-*/server/webapps/loader/WEB-INF/ext-lib directory on the active and standby Loader nodes.
- Run the following command on the active and standby nodes as user root to modify the permission on the JAR file:
cd ${BIGDATA_HOME}/FusionInsight_Porter_*/install/FusionInsight-Sqoop-*/FusionInsight-Sqoop-*/server/webapps/loader/WEB-INF/ext-lib
chown omm:wheel JAR file name
chmod 600 JAR file name
- Log in to FusionInsight Manager and choose Cluster > Services > Loader. On the Dashboard tab page that is displayed, click More and select Restart Service. In the displayed dialog box, enter the administrator password to restart the Loader service.
- Create a version control table in MOTService and add specific fields to the table for version control. If there is such a table, you do not need to create one. All MOT jobs (full or incremental) share the same table. The reference commands are as follows:
CREATE TABLE T_RTD_TBL_CUR_VER_INFO (
TBL_NAME varchar NOT NULL,
CUR_VER_FLAG tinyint DEFAULT '0' NOT NULL,
CONSTRAINT PK_T_RTD_TBL_CUR_VER_INFO PRIMARY KEY (TBL_NAME)
);
Configure basic job information.
- Access the Loader web UI.
- Log in to FusionInsight Manager.
- Choose Cluster > Services > Loader.
- Click LoaderServer(Node name, Active). The Loader web UI is displayed.
Figure 1 Loader web UI
- Click New Job. Configure basic job parameters on the Basic Information page displayed.
Figure 2 Basic Information page
- Enter a job name in Name.
- Set Type to Export.
- Set Group to the group to which the job belongs. There is no group created by default. Click Add, enter the group name, and click OK.
- Set Queue to the Yarn queue that executes the job. The default value is root.default.
- Set Priority to the priority of the Yarn queue that executes the job. The default value is NORMAL. The options are VERY_LOW, LOW, NORMAL, HIGH, and VERY_HIGH.
- In the Connection area, click Add to create a connection, set Connector to generic-jdbc-connector, set connection parameters, and click Test to verify whether the connection is available. When "Test Success" is displayed, click OK.
Table 1 generic-jdbc-connector connection parameters Parameter
Description
Example Value
Name
Name of a relational database connection
dbName
JDBC Driver Class
Name of a JDBC driver class
com.xxx.opengauss.jdbc.Driver
JDBC Connection String
JDBC connection string, in the following format:
jdbc:opengauss://Database IP address:Database port number/Database name
jdbc:opengauss://10.10.10.10:15400/test
Username
Username for connecting to the database
omm
Password
Password for connecting to the database
xxxx
JDBC Connection Properties
JDBC connection attribute. Click Add to manually add the attribute.
- Name: connection attribute name
- Value: connection attribute value
- Name: socketTimeout
- Value: 20
NOTE:
Log in to FusionInsight Manager and choose Cluster > Services > MOTService. Click Configurations then All Configurations, and search for the REQUIRE_SSL parameter. If the parameter value is true, add a JDBC connection attribute whose name is ssl.enable and value is true. Otherwise, you do not need to add this connection attribute.
Configure data source information.
- Click Next. On the From page displayed, set Source type to HDFS.
Table 2 Data source parameters Parameter
Description
Example Value
Input directory
Input path when data is exported from HDFS
NOTE:You can use macros to define path parameters. For details, see Using Macro Definitions in Configuration Items.
/user/test
Path filter
Wildcard for filtering the directories in the input paths of the source files. Input directory is not used for filtering. Use commas (,) to separate multiple filter criteria. If this parameter is left blank, directories are not filtered. Regular expression filtering is not supported.
- ? matches a single character.
- * indicates multiple characters.
- Adding ^ before the condition indicates negated filtering, that is, file filtering.
*
File filter
Wildcard for filtering the file names of the source files. Use commas (,) to separate multiple filter criteria. This parameter cannot be left blank. Regular expression filtering is not supported.
- ? matches a single character.
- * indicates multiple characters.
- Adding ^ before the condition indicates negated filtering, that is, file filtering.
*
File type
File import type. The options are as follows:
- TEXT_FILE: imports a text file and saves it as a text file.
- SEQUENCE_FILE: imports a text file and saves it as a sequence file.
- BINARY_FILE: imports files of any format using binary streams but not to process the files.
NOTE:When the file import type is set to TEXT_FILE or SEQUENCE_FILE, Loader automatically selects a decompression method based on the file name extension to decompress a file.
TEXT_FILE
File split type
Whether to split source files by file name or size. The files obtained after the splitting are used as the input files of each Map in the MapReduce task for data export.
- FILE: indicates that the source file is split by file. That is, each Map processes one or multiple complete files, the same source file cannot be allocated to different Maps, and the source file directory structure is retained after data import.
- SIZE: indicates that the source file is split by size. That is, each Map processes input files of a certain size, and a source file can be divided and processed by multiple Maps. After data is stored in the output directory, the number of saved files is the same as that of Maps. The file name format is import_part_xxxx, where xxxx is a unique random number generated by the system.
FILE
Extractors
Number of Maps that are started at the same time in a MapReduce task of a data configuration operation. This parameter cannot be set when Extractor size is set. The value must be less than or equal to 3000.
20
Extractor size
Size of data processed by Maps that are started in a MapReduce task of a data configuration operation. The unit is MB. The value must be greater than or equal to 100. The recommended value is 1000. This parameter cannot be set when Extractors is set. When a relational database connector is used, Extractor Size is unavailable. You need to set Extractors.
-
Configure data transformation.
- Click Next. On the displayed Transform page, set the transformation operations in the data transformation process. For details about how to select operators and set parameters, see Operator Help and Table 3.
Table 3 Input and output parameters of the operator Input Type
Output Type
CSV File Input
Table Output
In input, drag CSV File Input to the grid. In output, drag Table Output to the grid. Use an arrow to connect CSV File Input to Table Output.
Set data storage information and execute the job.
- Click Next. Configure the parameters on the To page displayed.
Table 4 Output parameters Parameter
Description
Example Value
Schema name
Database schema name
dbo
Table name
Name of a database table that is used to save the final data of the transmission
test
Stage table name
Name of a temporary database table that is used to temporarily store data during transmission. The fields in the temporary table must be the same as those in the table specified by Table Name.
db_test
DB type
Type of the database. The options are MOT and other databases that can be connected through JDBC.
MOT
MOT insert type
This parameter is available only when Database Type is set to MOT. Select an import mode based on service requirements.
NOTE:- Mode of importing data to the database. The options are TOTAL, INCREMENT, and INSERT.
TOTAL: full import. The data version is 0 by default. The version of newly written data is 1. When new data is imported to the database, data with the same primary key is updated, data with different primary keys is inserted, and all original data whose version is 0 is deleted. The version of the data that is newly written next time is 0, and the data versions are updated alternately in sequence.
INCREMENT: incremental import. Data with the same primary key is updated, data with different primary keys is inserted, and the original data is retained.
INSERT: common import. Data is inserted. If the primary key is duplicate, the task fails.
- If this parameter is set to TOTAL or INCREMENT, ensure that there is the CUR_VER_FLAG field available in the service data table for version control. For example:
CREATE TABLE F_ACCOUNT1 (
ORG_NBR smallint NOT NULL,
ACT_NBR varchar NOT NULL,
CLT_NBR varchar NOT NULL,
BRF_NAM varchar,
CUR_VER_FLAG tinyint DEFAULT '0' NOT NULL,
CONSTRAINT IDX_F_ACCOUNT1_PKEY PRIMARY KEY (CLT_NBR,ORG_NBR)
);
TOTAL
- Mode of importing data to the database. The options are TOTAL, INCREMENT, and INSERT.
- Click Save and Run to save and run the job.
View the job execution result.
- Go to the Loader web UI. When Status is Succeeded, the job is complete.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot