AutoMQ enables real-time data import to StarRocks, leveraging Kafka compatibility for integration and cloud-native scalability. Achieve efficient, high-concurrency analysis.
StarRocks is a high-performance analytical data warehouse that leverages advanced technologies such as vectorization, MPP architecture, CBO, intelligent materialized views, and a real-time updatable columnar storage engine. It supports multidimensional, real-time, and high-concurrency data analysis.This article will introduce how to use StarRocks Routine Load to import data from AutoMQ into StarRocks, with the relevant Routine Load configuration shown in the following steps.
Ensure that a usable StarRocks cluster is already prepared. For demonstration purposes, you can install a demonstration StarRocks cluster on a Linux machine.Create test tables for the database and primary key model:
create database automq_db;create table users ( id bigint NOT NULL, name string NOT NULL, timestamp string NULL, status string NULL) PRIMARY KEY (id)DISTRIBUTED BY HASH(id)PROPERTIES ( "replication_num" = "1", "enable_persistent_index" = "true");
Refer to Deploy Multi-Nodes Cluster on Linux▸ to deploy AutoMQ and ensure network connectivity between AutoMQ and StarRocks.Quickly create a topic named example_topic in AutoMQ and write a test JSON data to it following these steps.
Use the Apache Kafka® command-line tool to create a topic. Ensure you have access to the Kafka environment and that the Kafka service is running. Below is an example command to create a topic:
Use Kafka’s command-line tools or programming methods to write test data into a Topic named example_topic. Here is an example using the command-line tool:
If you need to specify a mapping and conversion relationship between the source data and the target table columns, you can configure the COLUMNS and jsonpaths parameters. In COLUMNS, the column names correspond to the column names of the target table, and the order of columns corresponds to the order of columns in source data. The jsonpaths parameter is used to extract the necessary field data from the JSON data, similar to newly generated CSV data. Subsequently, the COLUMNS parameter will temporarily name the fields in the order specified by jsonpaths.
If each line contains a JSON object where the names and number of keys correspond to the columns in the target table (order does not need to match), the COLUMNS configuration is not required.
First, check the status of the Routine Load import job to ensure the task is running.
show routine load\G;
And then querying the relevant tables in the StarRocks database, you can see that the data has been successfully imported.
StarRocks > select * from users;+------+--------------+---------------------+--------+| id | name | timestamp | status |+------+--------------+---------------------+--------+| 1 | Test User | 2023-11-10T12:00:00 | active || 2 | Test User | 2023-11-10T12:00:00 | active |+------+--------------+---------------------+--------+2 rows in set (0.01 sec)