SHOW LOAD.
NOTICE
- Only users with the INSERT privilege on a table can load data into this table. You can follow the instructions provided in GRANT to grant the required privilege.
- Spark Load can not be used to load data into a Primary Key table.
Terminology explanation
- Spark ETL: Mainly responsible for ETL of data in the import process, including global dictionary construction (BITMAP type), partitioning, sorting, aggregation, etc.
- Broker: Broker is an independent stateless process. It encapsulates the file system interface and provides the database with the ability to read files from remote storage systems.
- Global Dictionary: Saves the data structure that maps data from the original value to the encoded value. The original value can be any data type, while the encoded value is an integer. The global dictionary is mainly used in scenarios where exact count distinct is precomputed.
Fundamentals
The user submits a Spark type import job through the MySQL client;the FE records the metadata and returns the submission result. The execution of the spark load task is divided into the following main phases.- The user submits the spark load job to the FE.
- The FE schedules the submission of the ETL task to the Apache Spark™ cluster for execution.
- The Apache Spark™ cluster executes the ETL task that includes global dictionary construction (BITMAP type), partitioning, sorting, aggregation, etc.
- After the ETL task is completed, the FE gets the data path of each preprocessed slice and schedules the relevant BE to execute the Push task.
- The BE reads data through Broker process from HDFS and converts it into the database storage format.
If you choose not to use Broker process, the BE reads data from HDFS directly.
- The FE schedules the effective version and completes the import job.

Global Dictionary
Applicable Scenarios
Currently, the BITMAP column in the database is implemented using the Roaringbitmap, which only has integer to be the input data type. So if you want to implement precomputation for the BITMAP column in the import process, then you need to convert the input data type to integer. In the existing import process of the database, the data structure of the global dictionary is implemented based on the Hive table, which saves the mapping from the original value to the encoded value.Build Process
- Read the data from the upstream data source and generate a temporary Hive table, named
hive-table. - Extract the values of the de-emphasized fields of
hive-tableto generate a new Hive table nameddistinct-value-table. - Create a new global dictionary table named
dict-tablewith one column for the original values and one column for the encoded values. - Left join between
distinct-value-tableanddict-table, and then use the window function to encode this set. Finally both the original value and the encoded value of the de-duplicated column are written back todict-table. - Join between
dict-tableandhive-tableto finish the job of replacing the original value inhive-tablewith the integer encoded value. hive-tablewill be read by the next time data pre-processing, and then imported into the database after calculation.
Data Pre-processing
The basic process of data pre-processing is as follows:- Read data from the upstream data source (HDFS file or Hive table).
- Complete field mapping and calculation for the read data, then generate
bucket-idbased on the partition information. - Generate RollupTree based on the Rollup metadata of table.
- Iterate through the RollupTree and perform hierarchical aggregation operations. The Rollup of the next hierarchy can be calculated from the Rollup of the previous hierarchy.
- Each time the aggregation calculation is completed, the data is bucketed according to
bucket-idand then written to HDFS. - The subsequent Broker process will pull the files from HDFS and import them into the database BE node.
Basic Operations
Configuring ETL Clusters
Apache Spark™ is used as an external computational resource in the database for ETL work. There may be other external resources added to the database, such as Spark/GPU for query, HDFS/S3 for external storage, MapReduce for ETL, etc. Therefore, we introduceResource Management to manage these external resources used by the database.
Before submitting a Apache Spark™ import job, configure the Apache Spark™ cluster for performing ETL tasks. The syntax for operation is as follows:
- Create resource
resource-name is the name of the Apache Spark™ resource configured in the database.
PROPERTIES includes parameters relating to the Apache Spark™ resource, as follows:
Note For detailed description of Apache Spark™ resource PROPERTIES, please see CREATE RESOURCE
-
Spark related parameters:
type: Resource type, required, currently only supportsspark.spark.master: Required, currently only supportsyarn.spark.submit.deployMode: The deployment mode of the Apache Spark™ program, required, currently supports bothclusterandclient.spark.hadoop.fs.defaultFS: Required if master is yarn.- Parameters related to yarn resource manager, required.
-
one ResourceManager on a single node
spark.hadoop.yarn.resourcemanager.address: Address of the single point resource manager. -
ResourceManager HA
You can choose to specify ResourceManager’s hostname or address.
spark.hadoop.yarn.resourcemanager.ha.enabled: Enable the resource manager HA, set totrue.spark.hadoop.yarn.resourcemanager.ha.rm-ids: list of resource manager logical ids.spark.hadoop.yarn.resourcemanager.hostname.rm-id: For each rm-id, specify the hostname corresponding to the resource manager.spark.hadoop.yarn.resourcemanager.address.rm-id: For each rm-id, specifyhost:portfor the client to submit jobs to.
-
one ResourceManager on a single node
-
*working_dir: The directory used by ETL. Required if Apache Spark™ is used as an ETL resource. For example:hdfs://host:port/tmp/starrocks. -
Broker related parameters:
broker: Broker name. Required if Apache Spark™ is used as an ETL resource. You need to use theALTER SYSTEM ADD BROKERcommand to complete the configuration in advance.broker.property_key: Information (e.g.authentication information) to be specified when Broker process reads the intermediate file generated by the ETL.
- You do not need to specify
broker. - If you need to configure user authentication, and HA for NameNode nodes, you need to configure the parameters in the hdfs-site.xml file in the HDFS cluster, see broker_properties for descriptions of parameters. and you need to move the hdfs-site.xml file under BE_HOME/conf for each BE.
Note If the HDFS file can only be accessed by a specific user, you still need to specify the HDFS username inbroker.nameand the user password inbroker.password.
- View resources
USAGE-PRIV access. The root and admin accounts can view all resources.
- Resource Permissions
GRANT REVOKE, which currently only supports USAGE-PRIV permissions. You can give USAGE-PRIV permissions to a user or a role.
Configuring Spark Client
Configure the Spark client for FE so that the latter can submit Spark tasks by executing thespark-submit command. It is recommended to use the official version of Spark2 2.4.5 or above spark download address. After downloading, please use the following steps to complete the configuration.
- Configure
SPARK-HOME
spark_home_default_dir in the FE configuration file to this directory, which by default is the lib/spark2x path in the FE root directory, and cannot be empty.
- Configure SPARK dependency package
spark_resource_path item in the FE configuration to this zip file. If this configuration is empty, the FE will try to find the lib/spark2x/jars/spark-2x.zip file in the FE root directory. If the FE fails to find it, it will report an error.
When the spark load job is submitted, the archived dependency files will be uploaded to the remote repository. The default repository path is under the working_dir/{cluster_id} directory named with --spark-repository--{resource-name}, which means that a resource in the cluster corresponds to a remote repository. The directory structure is referenced as follows:
spark-2x.zip by default), the FE also uploads the DPP dependencies to the remote repository. If all the dependencies submitted by the spark load already exist in the remote repository, then there is no need to upload the dependencies again, saving the time of repeatedly uploading a large number of files each time.
Configuring YARN Client
Configure the yarn client for FE so that the FE can execute yarn commands to get the status of the running application or kill it.It is recommended to use the official version of Hadoop2 2.5.2 or above (hadoop download address). After downloading, please use the following steps to complete the configuration:- Configure the YARN executable path
yarn_client_path item in the FE configuration file to the binary executable file of yarn, which by default is the lib/yarn-client/hadoop/bin/yarn path in the FE root directory.
- Configure the path to the configuration file needed to generate YARN (optional)
lib/yarn-config path of the FE root directory This path can be modified by configuring the yarn_config_dir entry in the FE configuration file, which currently includes core-site.xml and yarn-site.xml.
Create Import Job
Syntax:- Step 1: Create a new hive resource
- Step 2: Create a new hive external table
- Step 3: Submit the load command, requiring that the columns in the imported table exist in the hive external table.
- Label
- Data description class parameters
- Import Job Parameters
opt_properties section of the import statement. These parameters are applicable to the entire import job. The rules are the same as broker load.
- Spark Resource Parameters
- Import when the data source is Hive
Hive type and then specify its name when submitting the import command.
- Import process to build a global dictionary
StarRocks field name=bitmap_dict(hive table field name) Note that currently the global dictionary is only supported when the upstream data source is a Hive table.
- Load binary type data
StarRocks field name=bitmap_from_binary(Hive table field name). This eliminates the need for building a global dictionary.
Viewing Import Jobs
The Spark load import is asynchronous, as is the broker load. The user must record the label of the import job and use it in theSHOW LOAD command to view the import results. The command to view the import is common to all import methods. The example is as follows.
Refer to Broker Load for a detailed explanation of returned parameters.The differences are as follows.
- State
CANCELLED and FINISHED, both indicating the load job is completed. CANCELLED indicates import failure and FINISHED indicates import success.
- Progress
- The range of progress for LOAD is 0~100%.
LOAD progress = the number of currently completed tablets of all replications imports / the total number of tablets of this import job * 100%.
- If all tables have been imported, the LOAD progress is 99%, and changes to 100% when the import enters the final validation phase.
- The import progress is not linear. If there is no change in progress for a period of time, it does not mean that the import is not executing.
- Type
- CreateTime/EtlStartTime/EtlFinishTime/LoadStartTime/LoadFinishTime
- JobDetails
- URL
View Apache Spark™ Launcher commit logs
Sometimes users need to view the detailed logs generated during a Apache Spark™ job commit. By default, the logs are saved in the pathlog/spark_launcher_log in the FE root directory named as spark-launcher-{load-job-id}-{label}.log. The logs are saved in this directory for a period of time and will be erased when the import information in FE metadata is cleaned up. The default retention time is 3 days.
Cancel Import
When the Spark load job status is notCANCELLED or FINISHED, it can be cancelled manually by the user by specifying the Label of the import job.
Related System Configurations
FE Configuration: The following configuration is the system-level configuration of Spark load, which applies to all Spark load import jobs. The configuration values can be adjusted mainly by modifyingfe.conf.
- enable-spark-load: Enable Spark load and resource creation with a default value of false.
- spark-load-default-timeout-second: The default timeout for the job is 259200 seconds (3 days).
- spark-home-default-dir: The Spark client path (
fe/lib/spark2x). - spark-resource-path: The path to the packaged S park dependency file (empty by default).
- spark-launcher-log-dir: The directory where the commit log of the Spark client is stored (
fe/log/spark-launcher-log). - yarn-client-path: The path to the yarn binary executable (
fe/lib/yarn-client/hadoop/bin/yarn). - yarn-config-dir: Yarn’s configuration file path (
fe/lib/yarn-config).
Best Practices
The most suitable scenario for using Spark load is when the raw data is in the file system (HDFS) and the data volume is in the tens of GB to TB level. Use Stream Load or Broker Load for smaller data volumes. For the full spark load import example, refer to the demo on github: https://github.com/StarRocks/demo/blob/master/docs/03_sparkLoad2StarRocks.mdFAQs
Error: When running with master 'yarn' either HADOOP-CONF-DIR or YARN-CONF-DIR must be set in the environment.
HADOOP-CONF-DIR environment variable in spark-env.sh of the Spark client.
Error: Cannot run program "xxx/bin/spark-submit": error=2, No such file or directory
spark_home_default_dir configuration item does not specify the Spark client root directory when using Spark Load.
Error: File xxx/jars/spark-2x.zip does not exist.
spark-resource-path configuration item does not point to the packed zip file when using Spark load.
Error: yarn client does not exist in path: xxx/yarn-client/hadoop/bin/yarn
ERROR: Cannot execute hadoop-yarn/bin/... /libexec/yarn-config.sh
HADOOP_LIBEXEC_DIR environment variable.
Since hadoop-yarn and hadoop directories are different, the default libexec directory will look for hadoop-yarn/bin/... /libexec, while libexec is in the hadoop directory.
The ```yarn application status“ command to get the Spark task status reported an error causing the import job to fail.