This topic describes how to create a MaxCompute sink connector to synchronize data from a source topic in your ApsaraMQ for Kafka instance to a table in MaxCompute.
Prerequisites
For information about the prerequisites, see Prerequisites.Usage notes
If you want to use the partition feature of MaxCompute, you must create an additional partition key column whose name is time and type is string when you create a table.
Step 1: Create MaxCompute resources
Create a table on the MaxCompute client. For more information, see Create tables.
In this example, a table named kafka_to_maxcompute is created. The table contains three columns, and the partition feature is enabled. The following code shows the statement that is executed to create the table:
CREATE TABLE IF NOT EXISTS kafka_to_maxcompute(topic STRING,valueName STRING,valueAge BIGINT) PARTITIONED by (time STRING);
The following code shows the statement that is executed to create the table if the partition feature is disabled:
CREATE TABLE IF NOT EXISTS kafka_to_maxcompute(topic STRING,valueName STRING,valueAge BIGINT);
If the statement is successfully executed, the following result is displayed.
On the Table Management page, view the information about the created table.
Step 2: Create and start a MaxCompute sink connector
- Log on to the ApsaraMQ for Kafka console. In the Resource Distribution section of the Overview page, click the name of the region where your instance is deployed.
- In the left-side navigation pane, choose .
- On the Message Outflow page, click Create Task.
- In the Create Message Outflow Task panel, configure the parameters and click Confirm. After you perform the preceding operations, go to the Message Outflow page, find the MaxCompute sink connector that you created, and then click Start in the Actions column. When the status in the Status column changes from Starting to Running, the connector is created.
Step 3: Test the MaxCompute sink connector
- On the Message Outflow page, find the MaxCompute sink connector that you created and click the name of the source topic in the Event Source column.
- On the Topic Details page, click Send Message.
- In the Start to Send and Consume Message panel, configure the parameters based on the following figure and click OK.
- Go to the MaxCompute console and execute the following SQL statement to query the information about the partition.
show PARTITIONS kafka_to_maxcompute;
The following figure shows the query result. - Execute the following statement based on the partition information to query the data in the partition:
SELECT * FROM kafka_to_maxcompute WHERE time="2023-04-13 17";
The following figure shows the query result.