- Running the database in Docker containers
- Using MinIO for Object Storage
- Configuring the database for shared-data
- Loading two public datasets
- Analyzing the data with SELECT and JOIN
- Basic data transformation (the T in ETL)
- Allow the reader to load data in a shared-data deployment and analyze that data.
- Provide the configuration details for shared-data deployments.
- Explain the basics of data transformation during loading.
Prerequisites
Docker
- Docker
- 4Ā GB RAM assigned to Docker
- 20 GB free disk space assigned to Docker
SQL client
You can use the SQL client provided in the Docker environment, or use one on your system. Many MySQL compatible clients will work, and this guide covers the configuration of DBeaver and MySQL Workbench.curl
curl is used to issue the data load job to the database, and to download the datasets. Check to see if you have it installed by running curl or curl.exe at your OS prompt. If curl is not installed, get curl here.
MinIO AIStor license
This guide uses MinIO AIStor for object storage, which requires a license. A free tier license is sufficient. The instructions for acquiring a license are provided later in this guide./etc/hosts
The ingest method used in this guide is Stream Load. Stream Load connects to the FE service to start the ingest job. The FE then assigns the job to a backend node, the CN in this guide. In order for the ingest job to connect to the CN the name of the CN must be available to your operating system. Add this line to /etc/hosts:
Terminology
FE
Frontend nodes are responsible for metadata management, client connection management, query planning, and query scheduling. Each FE stores and maintains a complete copy of metadata in its memory, which guarantees indiscriminate services among the FEs.CN
Compute Nodes are responsible for executing query plans in shared-data deployments.BE
Backend nodes are responsible for both data storage and executing query plans in shared-nothing deployments. Note This guide does not use BEs, this information is included here so that you understand the difference between BEs and CNs.Edit your hosts file
The ingest method used in this guide is Stream Load. Stream Load connects to the FE service to start the ingest job. The FE then assigns the job to a backend nodeāthe CN in this guide. In order for the ingest job to connect to the CN, the name of the CN must be available to your operating system. Add this line to/etc/hosts:
Download the lab files
There are three files to download:- The Docker Compose file that deploys the database and MinIO environment
- New York City crash data
- Weather data
Create a directory to store the lab files
Download the Docker Compose file
Download the data
Download these two datasets:New York City crash data
Weather data
Acquire a MinIO AIStor license
MinIO AIStor requires a license to run. You can use an existing license, or you can request a new MinIO AIStor Free Tier license. To request a new MinIO AIStor Free Tier license, go to the MinIO AIStor pricing page and select Get Started under the Free tier to obtain a free license. The free tier license allows you to run MinIO AIStor on a single compute resource with one or more drives. Save the license file asminio.license in the same directory as the docker-compose.yml file. The Docker Compose file mounts minio.license into the MinIO AIStor container. Without a valid license, MinIO AIStor starts but denies all S3 operations.
Deploy the database and MinIO
quickstart-minio_mc-1 container will show a status of Waiting and also an exit code. An exit code of 0 indicates success.
MinIO
This quick start uses MinIO for shared storage.Verify the MinIO credentials
To use MinIO for Object Storage with the database, the database needs a MinIO access key. The access key was generated during the startup of the Docker services. To help you better understand the way that the database connects to MinIO you should verify that the key exists. Browse to http://localhost:9001/console/identity The username and password are specified in the Docker compose file, and areminiouser and miniopassword. You should see that there is one access key. The Key is AAAAAAAAAAAAAAAAAAAA, you cannot see the secret in the MinIO Console, but it is in the Docker compose file and is BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB:

minio_mc service:
minio_mc pod:
Create a bucket for your data
When you create a storage volume in the database you will specify theLOCATION for the data:
my-starrocks-bucket. Accept the defaults for the three listed options.
SQL Clients
These three clients are tested with this tutorial, you only need one:
- mysql CLI: You can run this from the Docker environment or your machine.
- DBeaver is available as a community version and a Pro version.
- MySQL Workbench
Configuring the client
mysql CLI The easiest way to use the mysql CLI is to run it from the containerstarrocks-fe:
docker compose commands must be run from the directory containing the docker-compose.yml file.
If you would like to install the mysql CLI expand mysql client install below:
mysql client install
- macOS: If you use Homebrew and do not need MySQL Server run
brew install mysql-client@8.0to install the CLI. - Linux: Check your repository system for the
mysqlclient. For example,yum install mariadb. - Microsoft Windows: Install the MySQL Community Server and run the provided client, or run
mysqlfrom WSL.
- Install DBeaver, and add a connection:

- Configure the port, IP, and username. Test the connection, and click Finish if the test succeeds:

- Install the MySQL Workbench, and add a connection.
- Configure the port, IP, and username and then test the connection:

- You will see warnings from the Workbench as it is checking for a specific MySQL version. You can ignore the warnings and when prompted, you can configure Workbench to stop displaying the warnings:

The database configuration for shared-data
At this point you have the database running, and you have MinIO running. The MinIO access key is used to connect the database and Minio. This is the part of theFE configuration that specifies that the database deployment will use shared data. This was added to the file fe.conf when Docker Compose created the deployment.
quickstart directory and looking at the end of the file:
Connect to the database with a SQL client
Tip Run this command from the directory containing thedocker-compose.yml file.
If you are using a client other than the MySQL Command-Line Client, open that now.
Examine the storage volumes
Create a shared-data storage volume
Earlier you created a bucket in MinIO namedmy-starrocks-volume, and you verified that MinIO has an access key named AAAAAAAAAAAAAAAAAAAA. The following SQL will create a storage volume in the MionIO bucket using the access key and secret.
\G instead
of a semicolon. The \G causes the mysql CLI to render the query results vertically.
Many SQL clients do not interpret vertical formatting output, so you should replace \G with ;.
Set the default storage volume
Create a database
quickstart is using the storage volume s3_volume:
Create some tables
Create a database
Type these two lines in at theStarRocks > prompt and press enter after each:
Create two tables
Crashdata
The crash dataset contains many more fields than these, the schema has been trimmed down to include only the fields that might be useful to answer questions about the impact weather has on driving conditions.Weatherdata
Similar to the crash data, the weather dataset has many more columns (a total of 125 columns) and only the ones that are expected to answer the questions are included in the database.Load two datasets
There are many ways to load data into the database. For this tutorial the simplest way is to use curl and Stream Load. Tip Run these curl commands from the directory where you downloaded the dataset. You will be prompted for a password. You probably have not assigned a password to the MySQLroot user, so just hit enter.
The curl commands look complex, but they are explained in detail at the end of the tutorial. For now, we recommend running the commands and running some SQL to analyze the data, and then reading about the data loading details at the end.
New York City collision data - Crashes
starrocks-cn). Because you added an entry for starrocks-cn to the /etc/hosts file, you should be able to navigate to it and read the error message.
Expand the summary for the content seen while developing this tutorial:
Reading error messages in the browser
Weather data
Load the weather dataset in the same manner as you loaded the crash data.Verify that data is stored in MinIO
Open MinIO http://localhost:9001/console/browser/my-starrocks-bucket and verify that you have entries belowmy-starrocks-bucket/
Tip
The folder names below my-starrocks-bucket/ are generated when you load the data. You should see a single directory below my-starrocks-bucket, and then two more below that. In those directories you will find the data, metadata, or schema entries.

Answer some questions
These queries can be run in your SQL client. All of the queries use the
quickstart database.
How many crashes are there per hour in NYC?
What is the average temperature in NYC?
Is it safe to drive in NYC when visibility is poor?
Letās look at the number of crashes when visibility is poor (between 0 and 1.0 miles). To answer this question use a JOIN across the two tables on the DATETIME column.- February 3rd 2014 was a Monday
- 8AM is rush hour
- It was raining (0.12 inches or precipitation that hour)
- The temperature is 32 degrees F (the freezing point for water)
- Visibility is bad at 0.25 miles, normal for NYC is 10 miles
What about driving in icy conditions?
Water vapor can desublimate to ice at 40 degrees F; this query looks at temps between 0 and 40 degrees F.Configuring the database for shared-data
Now that you have experienced using the database with shared-data it is important to understand the configuration.CN configuration
The CN configuration used here is the default, as the CN is designed for shared-data use. The default configuration is shown below. You do not need to make any changes.FE configuration
The FE configuration is slightly different from the default as the FE must be configured to expect that data is stored in Object Storage rather than on local disks on BE nodes. Thedocker-compose.yml file generates the FE configuration in the command.
s3_. This prefix is used for all Amazon S3 compatible storage types (for example: S3, GCS, and MinIO). When using Azure Blob Storage the prefix is azure_.
run_mode=shared_data
This enables shared-data use.
cloud_native_storage_type=S3
This specifies whether S3 compatible storage or Azure Blob Storage is used. For MinIO this is always S3.
Details of CREATE storage volume
aws_s3_endpoint=minio:9000
The MinIO endpoint, including port number.
aws_s3_path=starrocks
The bucket name.
aws_s3_access_key=AAAAAAAAAAAAAAAAAAAA
The MinIO access key.
aws_s3_secret_key=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
The MinIO access key secret.
aws_s3_use_instance_profile=false
When using MinIO an access key is used, and so instance profiles are not used with MinIO.
aws_s3_use_aws_sdk_default_behavior=false
When using MinIO this parameter is always set to false.
Configuring FQDN mode
The command to start the FE is also changed. The FE service command in the Docker Compose file has the option--host_type FQDN added. By setting host_type to FQDN the Stream Load job is forwarded to the fully qualified domain name of the CN pod, rather than the IP address. This is done because the IP address is in a range assigned to the Docker environment, and is not typically available from the host machine.
These three changes allow traffic between the host network and the CN:
- setting
--host_typetoFQDN - exposing the CN port 8040 to the host network
- adding an entry to the hosts file for
starrocks-cnpointing to127.0.0.1
Summary
In this tutorial you:- Deployed the database and Minio in Docker
- Created a MinIO access key
- Configured a database Storage Volume that uses MinIO
- Loaded crash data provided by New York City and weather data provided by NOAA
- Analyzed the data using SQL JOINs to find out that driving in low visibility or icy streets is a bad idea
Notes on the curl commands
Stream Load and curl take many arguments. Only the ones used in this tutorial are described here, the rest will be linked to in the more information section.
--location-trusted
This configures curl to pass credentials to any redirected URLs.
-u root
The username used to log in to the database
-T filename
T is for transfer, the filename to transfer.
label:name-num
The label to associate with this Stream Load job. The label must be unique, so if you run the job multiple times you can add a number and keep incrementing that.
column_separator:,
If you load a file that uses a single , then set it as shown above, if you use a different delimiter then set that delimiter here. Common choices are \t, ,, and |.
skip_header:1
Some CSV files have a single header row with all of the column names listed, and some add a second line with datatypes. Set skip_header to 1 or 2 if you have one or two header lines, and set it to 0 if you have none.
enclose:\"
It is common to enclose strings that contain embedded commas with double-quotes. The sample datasets used in this tutorial have geo locations that contain commas and so the enclose setting is set to \". Remember to escape the " with a \.
max_filter_ratio:1
This allows some errors in the data. Ideally this would be set to 0 and the job would fail with any errors. It is set to 1 to allow all rows to fail during debugging.
columns:
The mapping of CSV file columns to table columns. You will notice that there are many more columns in the CSV files than columns in the table. Any columns that are not included in the table are skipped.
You will also notice that there is some transformation of data included in the columns: line for the crash dataset. It is very common to find dates and times in CSV files that do not conform to standards. This is the logic for converting the CSV data for the time and date of the crash to a DATETIME type:
The columns line
This is the beginning of one data record. The date is inMM/DD/YYYY format, and the time is HH:MI. Since DATETIME is generally YYYY-MM-DD HH:MI:SS we need to transform this data.
columns: parameter:
- Assign the content of the first column of the CSV file to
tmp_CRASH_DATE - Assign the content of the second column of the CSV file to
tmp_CRASH_TIME concat_ws()concatenatestmp_CRASH_DATEandtmp_CRASH_TIMEtogether with a space between themstr_to_date()creates a DATETIME from the concatenated string- store the resulting DATETIME in the column
CRASH_DATE