StarRocks with Helm
目的
このクイックスタートの目的は以下の通りです:
- Helm を使用して StarRocks Kubernetes Operator と StarRocks クラスターをデプロイする
- StarRocks データベースユーザー
root
のパスワードを設定する - 3 つの FE と 3 つの BE を使用して高可用性を提供する
- メタデータを永続ストレージに保存する
- データを永続ストレージに保存する
- Kubernetes クラスター外部から MySQL クライアントが接続できるようにする
- Kubernetes クラスター外部から Stream Load を使用してデータをロードできるようにする
- 一部の公開データセットをロードする
- データをクエリする
データセットとクエリは、Basic Quick Start で使用されているものと同じです。ここでの主な違いは、Helm と StarRocks Operator を使用してデプロイすることです。
使用するデータは、NYC OpenData と National Centers for Environmental Information によって提供されています。
これらのデータセットは大規模であり、このチュートリアルは StarRocks を使用する際の体験を提供することを目的としているため、過去 120 年分のデータをロードすることはありません。3 台の e2-standard-4 マシン(または同等のもの)で構築された GKE Kubernetes クラスターで実行できます。より大規模なデプロイメントについては、他のドキュメントを用意しており、後で提供します。
このドキュメントには多くの情報が含まれており、最初にステップバイステップの内容が提示され、最後に技術的な詳細が記載されています。これは以下の目的を順に達成するためです:
- Helm を使用してシステムをデプロイする。
- 読者が StarRocks にデータをロードし、そのデータを分析できるようにする。
- ロード中のデータ変換の基本を説明する。
前提条件
Kubernetes environment
The Kubernetes environment used while writing this guide consists of three nodes with four vCPUS, and 16GB RAM each (GCP e2-standard-4
machines). The Kubernetes cluster was deployed with this gcloud
command:
This command is for your reference, if you are using AWS, Azure, or any other Kubernetes provider you will need to modify this for your environment. In Google Cloud you will need to specify your own project and an appropriate location.
gcloud container --project enterprise-demo-422514 \
clusters create ee-docs \
--location=southamerica-west1-b \
--machine-type e2-standard-4 --disk-size 80 --num-nodes 3
Helm
Helm is a package manager for Kubernetes that simplifies the deployment and management of applications. In this lab you will use Helm to deploy the CelerData Enterprise Edition Kubernetes operator and the sample StarRocks cluster.
SQL クライアント
Kubernetes 環境で提供される SQL クライアントを使用するか、システム上のクライアントを使用できます。このガイドでは mysql CLI
を使用します。多くの MySQL 互換クライアントが動作します。
curl
curl
は StarRocks にデータロードジョブを発行し、データセットをダウンロードするために使用されます。curl
または curl.exe
を OS のプロンプトで実行してインストールされているか確認してください。curl がインストールされていない場合は、こちらから curl を取得してください.
用語
FE
フロントエンドノードは、メタデータ管理、クライアント接続管理、クエリプランニング、クエリスケジューリングを担当します。各 FE はメモリ内にメタデータの完全なコピーを保持し、FEs 間での無差別なサービスを保証します。
BE
バックエンドノードは、データストレージとクエリプランの実行の両方を担当します。
StarRocks Helm チャートリポジトリを追加する
Helm チャートには、StarRocks Operator とカスタムリソース StarRocksCluster の定義が含まれています。
-
Helm チャートリポジトリを追加します。
helm repo add starrocks https://starrocks.github.io/starrocks-kubernetes-operator
-
Helm チャートリポジトリを最新バージョンに更新します。
helm repo update
-
追加した Helm チャートリポジトリを表示します。
helm search repo starrocks
NAME CHART VERSION APP VERSION DESCRIPTION
starrocks/kube-starrocks 1.9.7 3.2-latest kube-starrocks includes two subcharts, operator...
starrocks/operator 1.9.7 1.9.7 A Helm chart for StarRocks operator
starrocks/starrocks 1.9.7 3.2-latest A Helm chart for StarRocks cluster
starrocks/warehouse 1.9.7 3.2-latest Warehouse is currently a feature of the StarRoc...
データをダウンロードする
これらの 2 つのデータセットをマシンにダウンロードします。
ニューヨーク市のクラッシュデータ
curl -O https://raw.githubusercontent.com/StarRocks/demo/master/documentation-samples/quickstart/datasets/NYPD_Crash_Data.csv
気象データ
curl -O https://raw.githubusercontent.com/StarRocks/demo/master/documentation-samples/quickstart/datasets/72505394728.csv
Helm の値ファイルを作成する
このクイックスタートの目的は以下の通りです:
- StarRocks データベースユーザー
root
のパスワードを設定する - 3 つの FE と 3 つの BE を使用して高可用性を提供する
- メタデータを永続ストレージに保存する
- データを永続ストレージに保存する
- Kubernetes クラスター外部から MySQL クライアントが接続できるようにする
- Kubernetes クラスター外部から Stream Load を使用してデータをロードできるようにする
Helm チャートはこれらの目的を満たすためのオプションを提供しますが、デフォルトでは設定されていません。このセクションの残りでは、これらの目的を達成するために必要な設定をカバーします。完全な値の仕様が提供されますが、まず各 6 つのセクションの詳細を読み、次に完全な仕様をコピーしてください。
1. データベースユーザーのパスワード
この YAML の一部は、StarRocks オペレーターに対して、データベースユーザー root
のパスワードを Kubernetes secret starrocks-root-pass
の password
キーの値に設定するよう指示します。
starrocks:
initPassword:
enabled: true
# Set a password secret, for example:
# kubectl create secret generic starrocks-root-pass --from-literal=password='g()()dpa$$word'
passwordSecret: starrocks-root-pass
-
タスク: Kubernetes secret を作成する
kubectl create secret generic starrocks-root-pass --from-literal=password='g()()dpa$$word'
2. 3 つの FE と 3 つの BE を使用した高可用性
starrocks.starrockFESpec.replicas
を 3 に設定し、starrocks.starrockBeSpec.replicas
を 3 に設定することで、高可用性のために十分な FEs と BEs を確保できます。CPU とメモリのリクエストを低く設定することで、小さな Kubernetes 環境でポッドを作成できます。
starrocks:
starrocksFESpec:
replicas: 3
resources:
requests:
cpu: 1
memory: 1Gi
starrocksBeSpec:
replicas: 3
resources:
requests:
cpu: 1
memory: 2Gi
3. メタデータを永続ストレージに保存する
starrocks.starrocksFESpec.storageSpec.name
に ""
以外の値を設定すると、以下が発生します:
- 永続ストレージが使用される
starrocks.starrocksFESpec.storageSpec.name
の値がサービスのすべてのストレージボリュームのプレフィックスとして使用される
値を fe
に設定することで、これらの PVs が FE 0 に対して作成されます:
fe-meta-kube-starrocks-fe-0
fe-log-kube-starrocks-fe-0
starrocks:
starrocksFESpec:
storageSpec:
name: fe
4. データを永続ストレージに保存する
starrocks.starrocksBeSpec.storageSpec.name
に ""
以外の値を設定すると、以下が発生します:
- 永続ストレージが使用される
starrocks.starrocksBeSpec.storageSpec.name
の値がサービスのすべてのストレージボリュームのプレフィックスとして使用される
値を be
に設定することで、これらの PVs が BE 0 に対して作成されます:
be-data-kube-starrocks-be-0
be-log-kube-starrocks-be-0
storageSize
を 15Gi に設定することで、デフォルトの 1Ti からストレージを削減し、ストレージの小さなクォータに適合させます。
starrocks:
starrocksBeSpec:
storageSpec:
name: be
storageSize: 15Gi
5. MySQL クライアント用の LoadBalancer
デフォルトでは、FE サービスへのアクセスはクラスター IP を通じて行われます。外部アクセスを許可するために、service.type
を LoadBalancer
に設定します。
starrocks:
starrocksFESpec:
service:
type: LoadBalancer
6. 外部データロード用の LoadBalancer
Stream Load では、FEs と BEs の両方への外部アクセスが必要です。リクエストは FE に送信され、その後 FE がアップロードを処理するための BE を割り当てます。curl
コマンドが BE にリダイレクトされることを許可するために、starroclFeProxySpec
を有効にし、タイプを LoadBalancer
に設定する必要があります。
starrocks:
starrocksFeProxySpec:
enabled: true
service:
type: LoadBalancer
完全な値ファイル
上記のスニペットを組み合わせると、完全な値ファイルが提供されます。これを my-values.yaml
に保存してください:
starrocks:
initPassword:
enabled: true
# Set a password secret, for example:
# kubectl create secret generic starrocks-root-pass --from-literal=password='g()()dpa$$word'
passwordSecret: starrocks-root-pass
starrocksFESpec:
replicas: 3
service:
type: LoadBalancer
resources:
requests:
cpu: 1
memory: 1Gi
storageSpec:
name: fe
starrocksBeSpec:
replicas: 3
resources:
requests:
cpu: 1
memory: 2Gi
storageSpec:
name: be
storageSize: 15Gi
starrocksFeProxySpec:
enabled: true
service:
type: LoadBalancer
StarRocks ルートデータベースユーザーパスワードを設定する
Kubernetes クラスター外部からデータをロードするために、StarRocks データベースを外部に公開します。StarRocks データベースユーザー root
のパスワードを設定してください。オペレーターは FE と BE ノードにパスワードを適用します。
kubectl create secret generic starrocks-root-pass --from-literal=password='g()()dpa$$word'
secret/starrocks-root-pass created
オペレーターと StarRocks クラスターをデプロイする
helm install -f my-values.yaml starrocks starrocks/kube-starrocks
NAME: starrocks
LAST DEPLOYED: Wed Jun 26 20:25:09 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Thank you for installing kube-starrocks-1.9.7 kube-starrocks chart.
It will install both operator and starrocks cluster, please wait for a few minutes for the cluster to be ready.
Please see the values.yaml for more operation information: https://github.com/StarRocks/starrocks-kubernetes-operator/blob/main/helm-charts/charts/kube-starrocks/values.yaml
StarRocks クラスターのステータスを確認する
次のコマンドで進行状況を確認できます:
kubectl --namespace default get starrockscluster -l "cluster=kube-starrocks"
NAME PHASE FESTATUS BESTATUS CNSTATUS FEPROXYSTATUS
kube-starrocks reconciling reconciling reconciling reconciling
kubectl get pods
kube-starrocks-initpwd
ポッドは、StarRocks ルートパスワードを設定するために FE と BE ポッドに接続しようとする際に、error
と CrashLoopBackOff
状態を経ることがあります。これらのエラーは無視し、このポッドのステータスが Completed
になるのを待ってください。
NAME READY STATUS RESTARTS AGE
kube-starrocks-be-0 0/1 Running 0 20s
kube-starrocks-be-1 0/1 Running 0 20s
kube-starrocks-be-2 0/1 Running 0 20s
kube-starrocks-fe-0 1/1 Running 0 66s
kube-starrocks-fe-1 0/1 Running 0 65s
kube-starrocks-fe-2 0/1 Running 0 66s
kube-starrocks-fe-proxy-56f8998799-d4qmt 1/1 Running 0 20s
kube-starrocks-initpwd-m84br 0/1 CrashLoopBackOff 3 (50s ago) 92s
kube-starrocks-operator-54ffcf8c5c-xsjc8 1/1 Running 0 92s
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
be-data-kube-starrocks-be-0 Bound pvc-4ae0c9d8-7f9a-4147-ad74-b22569165448 15Gi RWO standard-rwo <unset> 82s
be-data-kube-starrocks-be-1 Bound pvc-28b4dbd1-0c8f-4b06-87e8-edec616cabbc 15Gi RWO standard-rwo <unset> 82s
be-data-kube-starrocks-be-2 Bound pvc-c7232ea6-d3d9-42f1-bfc1-024205a17656 15Gi RWO standard-rwo <unset> 82s
be-log-kube-starrocks-be-0 Bound pvc-6193c43d-c74f-4d12-afcc-c41ace3d5408 1Gi RWO standard-rwo <unset> 82s
be-log-kube-starrocks-be-1 Bound pvc-c01f124a-014a-439a-99a6-6afe95215bf0 1Gi RWO standard-rwo <unset> 82s
be-log-kube-starrocks-be-2 Bound pvc-136df15f-4d2e-43bc-a1c0-17227ce3fe6b 1Gi RWO standard-rwo <unset> 82s
fe-log-kube-starrocks-fe-0 Bound pvc-7eac524e-d286-4760-b21c-d9b6261d976f 5Gi RWO standard-rwo <unset> 2m23s
fe-log-kube-starrocks-fe-1 Bound pvc-38076b78-71e8-4659-b8e7-6751bec663f6 5Gi RWO standard-rwo <unset> 2m23s
fe-log-kube-starrocks-fe-2 Bound pvc-4ccfee60-02b7-40ba-a22e-861ea29dac74 5Gi RWO standard-rwo <unset> 2m23s
fe-meta-kube-starrocks-fe-0 Bound pvc-5130c9ff-b797-4f79-a1d2-4214af860d70 10Gi RWO standard-rwo <unset> 2m23s
fe-meta-kube-starrocks-fe-1 Bound pvc-13545330-63be-42cf-b1ca-3ed6f96a8c98 10Gi RWO standard-rwo <unset> 2m23s
fe-meta-kube-starrocks-fe-2 Bound pvc-609cadd4-c7b7-4cf9-84b0-a75678bb3c4d 10Gi RWO standard-rwo <unset> 2m23s
クラスターが正常であることを確認する
これらは上記と同じコマンドですが、望ましい状態を示しています。
kubectl --namespace default get starrockscluster -l "cluster=kube-starrocks"
NAME PHASE FESTATUS BESTATUS CNSTATUS FEPROXYSTATUS
kube-starrocks running running running running
kubectl get pods
システムは、kube-starrocks-initpwd
を除くすべてのポッドが READY
列で 1/1
を示すときに準備が整います。kube-starrocks-initpwd
ポッドは 0/1
を示し、STATUS
が Completed
であるべきです。
NAME READY STATUS RESTARTS AGE
kube-starrocks-be-0 1/1 Running 0 57s
kube-starrocks-be-1 1/1 Running 0 57s
kube-starrocks-be-2 1/1 Running 0 57s
kube-starrocks-fe-0 1/1 Running 0 103s
kube-starrocks-fe-1 1/1 Running 0 102s
kube-starrocks-fe-2 1/1 Running 0 103s
kube-starrocks-fe-proxy-56f8998799-d4qmt 1/1 Running 0 57s
kube-starrocks-initpwd-m84br 0/1 Completed 4 2m9s
kube-starrocks-operator-54ffcf8c5c-xsjc8 1/1 Running 0 2m9s
EXTERNAL-IP
アドレスは、Kubernetes クラスター外部からの SQL クライアントおよび Stream Load アクセスを提供するために使用されます。
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-starrocks-be-search ClusterIP None <none> 9050/TCP 78s
kube-starrocks-be-service ClusterIP 34.118.228.231 <none> 9060/TCP,8040/TCP,9050/TCP,8060/TCP 78s
kube-starrocks-fe-proxy-service LoadBalancer 34.118.230.176 34.176.12.205 8080:30241/TCP 78s
kube-starrocks-fe-search ClusterIP None <none> 9030/TCP 2m4s
kube-starrocks-fe-service LoadBalancer 34.118.226.82 34.176.215.97 8030:30620/TCP,9020:32461/TCP,9030:32749/TCP,9010:30911/TCP 2m4s
kubernetes ClusterIP 34.118.224.1 <none> 443/TCP 8h
ハイライトされた行から EXTERNAL-IP
アドレスを環境変数に保存しておくと便利です:
export MYSQL_IP=`kubectl get services kube-starrocks-fe-service --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`
export FE_PROXY=`kubectl get services kube-starrocks-fe-proxy-service --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`:8080
SQL クライアントで StarRocks に接続する
mysql CLI 以外のクライアントを使用している場合は、今すぐ開いてください。
このコマンドは Kubernetes ポッドで mysql
コマンドを実行します:
kubectl exec --stdin --tty kube-starrocks-fe-0 -- \
mysql -P9030 -h127.0.0.1 -u root --prompt="StarRocks > "
mysql CLI がローカルにインストールされている場合は、Kubernetes クラスター内のものではなくそれを使用できます:
mysql -P9030 -h $MYSQL_IP -u root --prompt="StarRocks > " -p
テーブルを作成する
mysql -P9030 -h $MYSQL_IP -u root --prompt="StarRocks > " -p
Create a database
Type these two lines in at the StarRocks >
prompt and press enter after each:
CREATE DATABASE IF NOT EXISTS quickstart;
USE quickstart;
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.
CREATE TABLE IF NOT EXISTS crashdata (
CRASH_DATE DATETIME,
BOROUGH STRING,
ZIP_CODE STRING,
LATITUDE INT,
LONGITUDE INT,
LOCATION STRING,
ON_STREET_NAME STRING,
CROSS_STREET_NAME STRING,
OFF_STREET_NAME STRING,
CONTRIBUTING_FACTOR_VEHICLE_1 STRING,
CONTRIBUTING_FACTOR_VEHICLE_2 STRING,
COLLISION_ID INT,
VEHICLE_TYPE_CODE_1 STRING,
VEHICLE_TYPE_CODE_2 STRING
);
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.
CREATE TABLE IF NOT EXISTS weatherdata (
DATE DATETIME,
NAME STRING,
HourlyDewPointTemperature STRING,
HourlyDryBulbTemperature STRING,
HourlyPrecipitation STRING,
HourlyPresentWeatherType STRING,
HourlyPressureChange STRING,
HourlyPressureTendency STRING,
HourlyRelativeHumidity STRING,
HourlySkyConditions STRING,
HourlyVisibility STRING,
HourlyWetBulbTemperature STRING,
HourlyWindDirection STRING,
HourlyWindGustSpeed STRING,
HourlyWindSpeed STRING
);
MySQL クライアントから退出するか、コマンドラインでコマンドを実行してデータをアップロードするために新しいシェルを開きます。
exit
データをアップロードする
StarRocks にデータをロードする方法は多数あります。このチュートリアルでは、最も簡単な方法は curl と StarRocks Stream Load を使用することです。
先ほどダウンロードした 2 つのデータセットをアップロードします。
これらの curl コマンドはオペレーティングシステムのプロンプトで実行されるため、新しいシェルを開いてください。mysql
クライアントではありません。コマンドはダウンロードしたデータセットを参照しているため、ファイルをダウンロードしたディレクトリから実行してください。
これは新しいシェルなので、再度エクスポートコマンドを実行してください:
export MYSQL_IP=`kubectl get services kube-starrocks-fe-service --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`
export FE_PROXY=`kubectl get services kube-starrocks-fe-proxy-service --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`:8080
パスワードを求められます。Kubernetes secret starrocks-root-pass
に追加したパスワードを使用してください。提供されたコマンドを使用した場合、パスワードは g()()dpa$$word
です。
curl
コマンドは複雑に見えますが、チュートリアルの最後で詳細に説明されています。今は、コマンドを実行してデータを分析するための SQL を実行し、その後データロードの詳細について読んでください。
curl --location-trusted -u root \
-T ./NYPD_Crash_Data.csv \
-H "label:crashdata-0" \
-H "column_separator:," \
-H "skip_header:1" \
-H "enclose:\"" \
-H "max_filter_ratio:1" \
-H "columns:tmp_CRASH_DATE, tmp_CRASH_TIME, CRASH_DATE=str_to_date(concat_ws(' ', tmp_CRASH_DATE, tmp_CRASH_TIME), '%m/%d/%Y %H:%i'),BOROUGH,ZIP_CODE,LATITUDE,LONGITUDE,LOCATION,ON_STREET_NAME,CROSS_STREET_NAME,OFF_STREET_NAME,NUMBER_OF_PERSONS_INJURED,NUMBER_OF_PERSONS_KILLED,NUMBER_OF_PEDESTRIANS_INJURED,NUMBER_OF_PEDESTRIANS_KILLED,NUMBER_OF_CYCLIST_INJURED,NUMBER_OF_CYCLIST_KILLED,NUMBER_OF_MOTORIST_INJURED,NUMBER_OF_MOTORIST_KILLED,CONTRIBUTING_FACTOR_VEHICLE_1,CONTRIBUTING_FACTOR_VEHICLE_2,CONTRIBUTING_FACTOR_VEHICLE_3,CONTRIBUTING_FACTOR_VEHICLE_4,CONTRIBUTING_FACTOR_VEHICLE_5,COLLISION_ID,VEHICLE_TYPE_CODE_1,VEHICLE_TYPE_CODE_2,VEHICLE_TYPE_CODE_3,VEHICLE_TYPE_CODE_4,VEHICLE_TYPE_CODE_5" \
-XPUT http://$FE_PROXY/api/quickstart/crashdata/_stream_load
Enter host password for user 'root':
{
"TxnId": 2,
"Label": "crashdata-0",
"Status": "Success",
"Message": "OK",
"NumberTotalRows": 423726,
"NumberLoadedRows": 423725,
"NumberFilteredRows": 1,
"NumberUnselectedRows": 0,
"LoadBytes": 96227746,
"LoadTimeMs": 2483,
"BeginTxnTimeMs": 42,
"StreamLoadPlanTimeMs": 122,
"ReadDataTimeMs": 1610,
"WriteDataTimeMs": 2253,
"CommitAndPublishTimeMs": 65,
"ErrorURL": "http://kube-starrocks-be-2.kube-starrocks-be-search.default.svc.cluster.local:8040/api/_load_error_log?file=error_log_5149e6f80de42bcb_eab2ea77276de4ba"
}
curl --location-trusted -u root \
-T ./72505394728.csv \
-H "label:weather-0" \
-H "column_separator:," \
-H "skip_header:1" \
-H "enclose:\"" \
-H "max_filter_ratio:1" \
-H "columns: STATION, DATE, LATITUDE, LONGITUDE, ELEVATION, NAME, REPORT_TYPE, SOURCE, HourlyAltimeterSetting, HourlyDewPointTemperature, HourlyDryBulbTemperature, HourlyPrecipitation, HourlyPresentWeatherType, HourlyPressureChange, HourlyPressureTendency, HourlyRelativeHumidity, HourlySkyConditions, HourlySeaLevelPressure, HourlyStationPressure, HourlyVisibility, HourlyWetBulbTemperature, HourlyWindDirection, HourlyWindGustSpeed, HourlyWindSpeed, Sunrise, Sunset, DailyAverageDewPointTemperature, DailyAverageDryBulbTemperature, DailyAverageRelativeHumidity, DailyAverageSeaLevelPressure, DailyAverageStationPressure, DailyAverageWetBulbTemperature, DailyAverageWindSpeed, DailyCoolingDegreeDays, DailyDepartureFromNormalAverageTemperature, DailyHeatingDegreeDays, DailyMaximumDryBulbTemperature, DailyMinimumDryBulbTemperature, DailyPeakWindDirection, DailyPeakWindSpeed, DailyPrecipitation, DailySnowDepth, DailySnowfall, DailySustainedWindDirection, DailySustainedWindSpeed, DailyWeather, MonthlyAverageRH, MonthlyDaysWithGT001Precip, MonthlyDaysWithGT010Precip, MonthlyDaysWithGT32Temp, MonthlyDaysWithGT90Temp, MonthlyDaysWithLT0Temp, MonthlyDaysWithLT32Temp, MonthlyDepartureFromNormalAverageTemperature, MonthlyDepartureFromNormalCoolingDegreeDays, MonthlyDepartureFromNormalHeatingDegreeDays, MonthlyDepartureFromNormalMaximumTemperature, MonthlyDepartureFromNormalMinimumTemperature, MonthlyDepartureFromNormalPrecipitation, MonthlyDewpointTemperature, MonthlyGreatestPrecip, MonthlyGreatestPrecipDate, MonthlyGreatestSnowDepth, MonthlyGreatestSnowDepthDate, MonthlyGreatestSnowfall, MonthlyGreatestSnowfallDate, MonthlyMaxSeaLevelPressureValue, MonthlyMaxSeaLevelPressureValueDate, MonthlyMaxSeaLevelPressureValueTime, MonthlyMaximumTemperature, MonthlyMeanTemperature, MonthlyMinSeaLevelPressureValue, MonthlyMinSeaLevelPressureValueDate, MonthlyMinSeaLevelPressureValueTime, MonthlyMinimumTemperature, MonthlySeaLevelPressure, MonthlyStationPressure, MonthlyTotalLiquidPrecipitation, MonthlyTotalSnowfall, MonthlyWetBulb, AWND, CDSD, CLDD, DSNW, HDSD, HTDD, NormalsCoolingDegreeDay, NormalsHeatingDegreeDay, ShortDurationEndDate005, ShortDurationEndDate010, ShortDurationEndDate015, ShortDurationEndDate020, ShortDurationEndDate030, ShortDurationEndDate045, ShortDurationEndDate060, ShortDurationEndDate080, ShortDurationEndDate100, ShortDurationEndDate120, ShortDurationEndDate150, ShortDurationEndDate180, ShortDurationPrecipitationValue005, ShortDurationPrecipitationValue010, ShortDurationPrecipitationValue015, ShortDurationPrecipitationValue020, ShortDurationPrecipitationValue030, ShortDurationPrecipitationValue045, ShortDurationPrecipitationValue060, ShortDurationPrecipitationValue080, ShortDurationPrecipitationValue100, ShortDurationPrecipitationValue120, ShortDurationPrecipitationValue150, ShortDurationPrecipitationValue180, REM, BackupDirection, BackupDistance, BackupDistanceUnit, BackupElements, BackupElevation, BackupEquipment, BackupLatitude, BackupLongitude, BackupName, WindEquipmentChangeDate" \
-XPUT http://$FE_PROXY/api/quickstart/weatherdata/_stream_load
Enter host password for user 'root':
{
"TxnId": 4,
"Label": "weather-0",
"Status": "Success",
"Message": "OK",
"NumberTotalRows": 22931,
"NumberLoadedRows": 22931,
"NumberFilteredRows": 0,
"NumberUnselectedRows": 0,
"LoadBytes": 15558550,
"LoadTimeMs": 404,
"BeginTxnTimeMs": 1,
"StreamLoadPlanTimeMs": 7,
"ReadDataTimeMs": 157,
"WriteDataTimeMs": 372,
"CommitAndPublishTimeMs": 23
}
MySQL クライアントで接続する
MySQL クライアントで接続していない場合は接続してください。kube-starrocks-fe-service
サービスの外部 IP アドレスと、Kubernetes secret starrocks-root-pass
に設定したパスワードを使用してください。
mysql -P9030 -h $MYSQL_IP -u root --prompt="StarRocks > " -p
質問に答える
These queries can be run in your SQL client. All of the queries use the quickstart
database.
USE quickstart;
How many crashes are there per hour in NYC?
SELECT COUNT(*),
date_trunc("hour", crashdata.CRASH_DATE) AS Time
FROM crashdata
GROUP BY Time
ORDER BY Time ASC
LIMIT 200;
Here is part of the output. Note that I am looking closer at January 6th and 7th as this is Monday and Tuesday of a non-holiday week. Looking at New Years Day is probably not indicative of a normal morning during rush-hour traffic.
| 14 | 2014-01-06 06:00:00 |
| 16 | 2014-01-06 07:00:00 |
| 43 | 2014-01-06 08:00:00 |
| 44 | 2014-01-06 09:00:00 |
| 21 | 2014-01-06 10:00:00 |
| 28 | 2014-01-06 11:00:00 |
| 34 | 2014-01-06 12:00:00 |
| 31 | 2014-01-06 13:00:00 |
| 35 | 2014-01-06 14:00:00 |
| 36 | 2014-01-06 15:00:00 |
| 33 | 2014-01-06 16:00:00 |
| 40 | 2014-01-06 17:00:00 |
| 35 | 2014-01-06 18:00:00 |
| 23 | 2014-01-06 19:00:00 |
| 16 | 2014-01-06 20:00:00 |
| 12 | 2014-01-06 21:00:00 |
| 17 | 2014-01-06 22:00:00 |
| 14 | 2014-01-06 23:00:00 |
| 10 | 2014-01-07 00:00:00 |
| 4 | 2014-01-07 01:00:00 |
| 1 | 2014-01-07 02:00:00 |
| 3 | 2014-01-07 03:00:00 |
| 2 | 2014-01-07 04:00:00 |
| 6 | 2014-01-07 06:00:00 |
| 16 | 2014-01-07 07:00:00 |
| 41 | 2014-01-07 08:00:00 |
| 37 | 2014-01-07 09:00:00 |
| 33 | 2014-01-07 10:00:00 |
It looks like about 40 accidents on a Monday or Tuesday morning during rush hour traffic, and around the same at 17:00 hours.
What is the average temperature in NYC?
SELECT avg(HourlyDryBulbTemperature),
date_trunc("hour", weatherdata.DATE) AS Time
FROM weatherdata
GROUP BY Time
ORDER BY Time ASC
LIMIT 100;
Output:
Note that this is data from 2014, NYC has not been this cold lately.
+-------------------------------+---------------------+
| avg(HourlyDryBulbTemperature) | Time |
+-------------------------------+---------------------+
| 25 | 2014-01-01 00:00:00 |
| 25 | 2014-01-01 01:00:00 |
| 24 | 2014-01-01 02:00:00 |
| 24 | 2014-01-01 03:00:00 |
| 24 | 2014-01-01 04:00:00 |
| 24 | 2014-01-01 05:00:00 |
| 25 | 2014-01-01 06:00:00 |
| 26 | 2014-01-01 07:00:00 |
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.
SELECT COUNT(DISTINCT c.COLLISION_ID) AS Crashes,
truncate(avg(w.HourlyDryBulbTemperature), 1) AS Temp_F,
truncate(avg(w.HourlyVisibility), 2) AS Visibility,
max(w.HourlyPrecipitation) AS Precipitation,
date_format((date_trunc("hour", c.CRASH_DATE)), '%d %b %Y %H:%i') AS Hour
FROM crashdata c
LEFT JOIN weatherdata w
ON date_trunc("hour", c.CRASH_DATE)=date_trunc("hour", w.DATE)
WHERE w.HourlyVisibility BETWEEN 0.0 AND 1.0
GROUP BY Hour
ORDER BY Crashes DESC
LIMIT 100;
The highest number of crashes in a single hour during low visibility is 129. There are multiple things to consider:
- 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
+---------+--------+------------+---------------+-------------------+
| Crashes | Temp_F | Visibility | Precipitation | Hour |
+---------+--------+------------+---------------+-------------------+
| 129 | 32 | 0.25 | 0.12 | 03 Feb 2014 08:00 |
| 114 | 32 | 0.25 | 0.12 | 03 Feb 2014 09:00 |
| 104 | 23 | 0.33 | 0.03 | 09 Jan 2015 08:00 |
| 96 | 26.3 | 0.33 | 0.07 | 01 Mar 2015 14:00 |
| 95 | 26 | 0.37 | 0.12 | 01 Mar 2015 15:00 |
| 93 | 35 | 0.75 | 0.09 | 18 Jan 2015 09:00 |
| 92 | 31 | 0.25 | 0.12 | 03 Feb 2014 10:00 |
| 87 | 26.8 | 0.5 | 0.09 | 01 Mar 2015 16:00 |
| 85 | 55 | 0.75 | 0.20 | 23 Dec 2015 17:00 |
| 85 | 20 | 0.62 | 0.01 | 06 Jan 2015 11:00 |
| 83 | 19.6 | 0.41 | 0.04 | 05 Mar 2015 13:00 |
| 80 | 20 | 0.37 | 0.02 | 06 Jan 2015 10:00 |
| 76 | 26.5 | 0.25 | 0.06 | 05 Mar 2015 09:00 |
| 71 | 26 | 0.25 | 0.09 | 05 Mar 2015 10:00 |
| 71 | 24.2 | 0.25 | 0.04 | 05 Mar 2015 11:00 |
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.
SELECT COUNT(DISTINCT c.COLLISION_ID) AS Crashes,
truncate(avg(w.HourlyDryBulbTemperature), 1) AS Temp_F,
truncate(avg(w.HourlyVisibility), 2) AS Visibility,
max(w.HourlyPrecipitation) AS Precipitation,
date_format((date_trunc("hour", c.CRASH_DATE)), '%d %b %Y %H:%i') AS Hour
FROM crashdata c
LEFT JOIN weatherdata w
ON date_trunc("hour", c.CRASH_DATE)=date_trunc("hour", w.DATE)
WHERE w.HourlyDryBulbTemperature BETWEEN 0.0 AND 40.5
GROUP BY Hour
ORDER BY Crashes DESC
LIMIT 100;
The results for freezing temperatures suprised me a little, I did not expect too much traffic on a Sunday morning in the city on a cold January day.A quick look at weather.com showed that there was a big storm with many crashes that day, just like what can be seen in the data.
+---------+--------+------------+---------------+-------------------+
| Crashes | Temp_F | Visibility | Precipitation | Hour |
+---------+--------+------------+---------------+-------------------+
| 192 | 34 | 1.5 | 0.09 | 18 Jan 2015 08:00 |
| 170 | 21 | NULL | | 21 Jan 2014 10:00 |
| 145 | 19 | NULL | | 21 Jan 2014 11:00 |
| 138 | 33.5 | 5 | 0.02 | 18 Jan 2015 07:00 |
| 137 | 21 | NULL | | 21 Jan 2014 09:00 |
| 129 | 32 | 0.25 | 0.12 | 03 Feb 2014 08:00 |
| 114 | 32 | 0.25 | 0.12 | 03 Feb 2014 09:00 |
| 104 | 23 | 0.7 | 0.04 | 09 Jan 2015 08:00 |
| 98 | 16 | 8 | 0.00 | 06 Mar 2015 08:00 |
| 96 | 26.3 | 0.33 | 0.07 | 01 Mar 2015 14:00 |
Drive carefully!
exit
クリーンアップ
終了して StarRocks クラスターと StarRocks オペレーターを削除したい場合は、このコマンドを実行してください。
helm delete starrocks
まとめ
このチュートリアルでは以下を行いました:
- Helm と StarRocks Operator を使用して StarRocks をデプロイしました
- ニューヨーク市が提供するクラッシュデータと NOAA が提供する気象データをロードしました
- SQL JOIN を使用して、低視界や氷結した道路での運転が悪い考えであることを分析しました
学ぶことはまだあります。Stream Load 中に行われたデータ変換については意図的に詳しく説明していません。curl コマンドに関する詳細は以下のノートにあります。
curl コマンドに関するノート
StarRocks 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 StarRocks
-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 StarRocks 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 in MM/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.
08/05/2014,9:10,BRONX,10469,40.8733019,-73.8536375,"(40.8733019, -73.8536375)",
This is the beginning of the columns:
parameter:
-H "columns:tmp_CRASH_DATE, tmp_CRASH_TIME, CRASH_DATE=str_to_date(concat_ws(' ', tmp_CRASH_DATE, tmp_CRASH_TIME), '%m/%d/%Y %H:%i')
This instructs StarRocks to:
- 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_DATE
andtmp_CRASH_TIME
together with a space between themstr_to_date()
creates a DATETIME from the concatenated string- store the resulting DATETIME in the column
CRASH_DATE
詳細情報
values.yaml
のデフォルト
Motor Vehicle Collisions - Crashes データセットは、ニューヨーク市によって提供され、これらの利用規約およびプライバシーポリシーに従います。
Local Climatological Data (LCD) は、NOAA によって提供され、免責事項およびプライバシーポリシーに従います。
Helm は Kubernetes のパッケージマネージャーです。Helm Chart は Helm パッケージであり、Kubernetes クラスター上でアプリケーションを実行するために必要なすべてのリソース定義を含んでいます。