This document provides an overview of the example applications inside Examples directory. These examples demonstrate how to use Spark Connect Swift to interact with Apache Spark in different contexts.
Start a Spark Connect Server:
docker run -it --rm -p 15002:15002 apache/spark:4.0.0-preview2 bash -c "/opt/spark/sbin/start-connect-server.sh --wait -c spark.log.level=ERROR"
The basic application example demonstrates fundamental operations with Apache Spark Connect, including:
Build and run the application:
# Using Docker docker build -t apache/spark-connect-swift:app . docker run -it --rm -e SPARK_REMOTE=sc://host.docker.internal:15002 apache/spark-connect-swift:app # From source code swift run
The Spark SQL REPL application example demonstrates interactive operations with ad-hoc Spark SQL queries with Apache Spark Connect, including:
Build and run the application:
# Using Docker docker build -t apache/spark-connect-swift:spark-sql . docker run -it --rm -e SPARK_REMOTE=sc://host.docker.internal:15002 apache/spark-connect-swift:spark-sql # From source code swift run
The Pi calculation example shows how to use Spark Connect Swift for computational tasks by calculating an approximation of π (pi) using the Monte Carlo method.
Build and run the application:
# Using Docker docker build -t apache/spark-connect-swift:pi . docker run --rm -e SPARK_REMOTE=sc://host.docker.internal:15002 apache/spark-connect-swift:pi # From source code swift run
The streaming example demonstrates how to process streaming data using Spark Connect Swift client, specifically for counting words from a network socket stream.
Start a Netcat server as the data source:
nc -lk 9999
Build and run the application:
# Using Docker docker build -t apache/spark-connect-swift:stream . docker run --rm -e SPARK_REMOTE=sc://host.docker.internal:15002 -e TARGET_HOST=host.docker.internal apache/spark-connect-swift:stream # From source code swift run
Type text into the Netcat terminal to see real-time word counting from Spark Connect Server container.
The web application example showcases how to integrate Spark Connect Swift with a web server using the Vapor framework.
Build and run the application:
# Using Docker docker build -t apache/spark-connect-swift:web . docker run -it --rm -p 8080:8080 -e SPARK_REMOTE=sc://host.docker.internal:15002 apache/spark-connect-swift:web # From source code swift run
Access the web application:
# Root endpoint $ curl http://127.0.0.1:8080/ Welcome to the Swift world. Say hello!% # Spark-powered endpoint curl http://127.0.0.1:8080/hello Hi, this is powered by the Apache Spark 4.0.0-preview2.%
All examples include:
These examples are designed to be used with Apache Spark 4.0.0 or newer, using the Spark Connect protocol for client-server interaction.