Skip to content

Latest commit

 

History

History
77 lines (68 loc) · 3.19 KB

ubuntu-instructions.md

File metadata and controls

77 lines (68 loc) · 3.19 KB

Getting Started with Spark.NET on Ubuntu

These instructions will show you how to run a .NET for Apache Spark app using .NET Core on Ubuntu 18.04.

Pre-requisites

For detailed instructions, you can see Building .NET for Apache Spark from Source on Ubuntu.

Authoring a .NET for Apache Spark App

  • Use the dotnet CLI to create a console application.
    dotnet new console -o HelloSpark
  • Install Microsoft.Spark Nuget package into the project from the spark nuget.org feed - see Ways to install Nuget Package
    cd HelloSpark
    dotnet add package Microsoft.Spark
  • Replace the contents of the Program.cs file with the following code:
    using Microsoft.Spark.Sql;
    
    namespace HelloSpark
    {
        class Program
        {
            static void Main(string[] args)
            {
                var spark = SparkSession.Builder().GetOrCreate();
                var df = spark.Read().Json("people.json");
                df.Show();
            }
        }
    }
  • Use the dotnet CLI to build the application:
    dotnet build

Running your .NET for Apache Spark App

  • Open your terminal and navigate into your app folder.
    cd <your-app-output-directory>
  • Create people.json with the following content:
    {"name":"Michael"}
    {"name":"Andy", "age":30}
    {"name":"Justin", "age":19}
  • Run your app.
    spark-submit \
    --class org.apache.spark.deploy.dotnet.DotnetRunner \
    --master local \
    microsoft-spark-2.4.x-<version>.jar \
    dotnet HelloSpark.dll
    Note: This command assumes you have downloaded Apache Spark and added it to your PATH environment variable to be able to use spark-submit, otherwise, you would have to use the full path (e.g., ~/spark/bin/spark-submit). For detailed instructions, you can see Building .NET for Apache Spark from Source on Ubuntu.
  • The output of the application should look similar to the output below:
    +----+-------+
    | age|   name|
    +----+-------+
    |null|Michael|
    |  30|   Andy|
    |  19| Justin|
    +----+-------+