Go言語向けWordCountクイックスタート

このクイックスタートでは、Beamパイプラインを初めて実行し、BeamのGo SDKを使用して記述されたWordCountを、お好みのランナーで実行する手順を説明します。

Apache Beam Goコードベースへの貢献にご興味のある方は、貢献ガイドをご覧ください。

環境設定

Go向けのBeam SDKには、goバージョン1.20以降が必要です。こちらからダウンロードできます。ご使用のgoバージョンを確認するには、次のコマンドを実行してください。

go version

Goに不慣れな場合は、Go入門チュートリアルをご覧ください。

WordCountの実行

Apache Beamのexamplesディレクトリには、多くの例があります。すべての例は、例に記載されている必要な引数を渡して実行できます。

たとえば、wordcountを実行するには、次のコマンドを実行します。

go run github.com/apache/beam/sdks/v2/go/examples/wordcount@latest --input "gs://apache-beam-samples/shakespeare/kinglear.txt" --output counts
less counts
go run github.com/apache/beam/sdks/v2/go/examples/wordcount@latest --input gs://dataflow-samples/shakespeare/kinglear.txt \
            --output gs://<your-gcs-bucket>/counts \
            --runner dataflow \
            --project your-gcp-project \
            --region your-gcp-region \
            --temp_location gs://<your-gcs-bucket>/tmp/ \
            --staging_location gs://<your-gcs-bucket>/binaries/
# Build and run the Spark job server from Beam source.
# -PsparkMasterUrl is optional. If it is unset the job will be run inside an embedded Spark cluster.
./gradlew :runners:spark:3:job-server:runShadow -PsparkMasterUrl=spark://localhost:7077

# In a separate terminal, run:
go run github.com/apache/beam/sdks/v2/go/examples/wordcount@latest --input <PATH_TO_INPUT_FILE> \
            --output counts \
            --runner spark \
            --endpoint localhost:8099

次のステップ

問題が発生した場合は、お気軽にお問い合わせください