BulkLoad Configuration File
Configuring a Custom Combined Rowkey
You can customize combined rowkeys when using the BulkLoad tool to import HBase data in batches. The BulkLoad combines rowkeys by applying rules to process multiple column names and generate new rowkeys.
The column name consists of letters, digits, and underscores (_) and cannot contain any special characters.
The combined rowkey in the configuration.xml file has three parts: for example, the three characters starting from the second character of SMS_ID and SMS_NAME and SMS_SERAIL in reverse order. Each part is connected by an underscore (_).
<columns> <column index="1" type="int">SMS_ID</column> <column index="2" type="string">SMS_NAME</column> <column index="3" type="string">SMS_ADDRESS</column> </columns> <rowkey> SMS_ID+'_'+substring(SMS_NAME,1,4)+'_'+reverse(SMS_ADDRESS) </rowkey>
Syntax |
Description |
Example Value |
---|---|---|
format(data,"DataType") |
Used to format string data. |
For example, format(data,"0.000") is used to input data in "0.000" format. |
converse(data,"yyyy-MM-dd","yyyyMMdd") |
Used to convert the date format. |
For example, converse(data,"yyyy-MM-dd","yyyyMMdd") is used change the date format from "yyyy-MM-dd" to "yyyyMMdd". |
rand |
Used to generate a random number. Only the int type is supported. |
None |
replace(data,"A","B") |
Used to replace data. |
For example, replace(data,"A","B") is used to replace A with B. |
reverse(data) |
Used to reverse a character string. |
For example, reverse(ABC) is used to reverse "ABC" to "CBA". |
substring(data,Length1,Length2), or substring(data,Length3) |
Used to subtract a string. |
For example, substring(data,1,5) or substring(data,3) is used to subtract [1,5) or [3,data.length) from the string. |
to_number("data") |
Used to convert a string into a numeric value. The Long type numeric value is supported. |
For example, to_number("123") is used to convert "123" into 123. data must be a numeric value. |
Configuring Custom Rowkeys
You can customize combined rowkeys when using the BulkLoad tool to import HBase data in batches. You can write RowKey implementation code to import data based on the combined RowKeys.
To configure a custom rowkey, perform the following steps:
- When you use the implementation class of a custom RowKey, inherit the interface. The JAR file path of the interface is Client installation directory/HBase/hbase/lib/hbase-it-bulk-load-*.jar.
[com.huawei.hadoop.hbase.tools.bulkload.RowkeyHandlerInterface],
Implement the method in the interface:
byte[] getRowkeyBytes(String[] colsValues, RegulationDomain regulation)
- colsValues indicates a collection of one original data row. Each element is a column.
- regulation indicates information about the configuration file to be imported. (Typically, this parameter is not used.)
- Compress the implementation class and its dependent package into a JAR file, save the file to any location on the node where the HBase client is installed, and ensure that the user who executes the command has the permission to read and execute the JAR file.
- When you run the import command, add the following two configuration items:
-Dimport.rowkey.jar=Full path of the JAR file in step 2
-Dimport.rowkey.class=Full class name of the user implementation class
Configuring a Custom Combined Field
You can customize combined fields using BulkLoad. Multiple columns are combined into one column in append mode.
The column name consists of letters, digits, and underscores (_) and cannot contain any special characters.
In the following example, the combined field H_COMBINE_1 consists of the SMS_ADDRESS and SMS_SNAME fields.
<!-- Define composite columns --> <composite family="f2"> <!-- Define the class name of the concatenated field. The class must not exist in the application.-->; <qualifier class="com.huawei.H_COMBINE_1">H_COMBINE_1</qualifier> <columns> <column>SMS_ADDRESS</column> <column>SMS_NAME</column> </columns> </composite>
Specifying Field Data Types
HBase BulkLoad can read native data files, map the data file fields to HBase fields, and define data types of these fields.
You can define multiple methods in configuration.xml for importing data in batches.
The column name consists of letters, digits, and underscores (_) and cannot contain any special characters.
The following shows the configuration of specifying the data type of a field. In this example, the data types of the SMS_ID, SMS_NAME, and SMS_ADDRESS columns are specified.
<columns> <column index="1" type="int">SMS_ID</column> <column index="2" type="string">SMS_NAME</column> <column index="3" type="string">SMS_ADDRESS</column> </columns>
Supported data types are: short, int, long, float, double, boolean, and string.
Defining Inapplicable Data Rows
BulkLoad allows you to specify data rows that are not applicable. These rows are stored in a separate file, rather than in HBase.
You can define multiple methods in configuration.xml for importing data in batches.
The column name consists of letters, digits, and underscores (_) and cannot contain any special characters.
Define the applicable data rows. The following is a configuration example: SMS_ID < 7000 && SMS_NAME = = 'HBase'.
<!-- Define bad line filter rule --> <badlines>SMS_ID < 7000 && SMS_NAME == 'HBase'</badlines>
Table 2 describes the operators and parameter data types in the <badlines> tag.
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