【问题标题】:How to correctly instantiate a spark session with dotnet spark?如何使用 dotnet spark 正确实例化 spark 会话?
【发布时间】:2019-09-10 14:53:00
【问题描述】:

我一直在关注 dotnet spark 上的文档以开始在 Windows 上使用该库。可以找到本指南:

在 GitHub 上:https://github.com/dotnet/spark/blob/master/docs/getting-started/windows-instructions.md

关于微软文档:https://docs.microsoft.com/en-us/dotnet/spark/tutorials/get-started

我似乎无法使用 C# 创建 spark 会话。我在命令行上安装了 spark 并且可以在命令行内运行它。这是我一直在使用的代码,与指南相同。

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();
        }
    }
}

当我在 Visual Studio 中运行程序时,出现错误:

System.Net.Internals.SocketExceptionFactory.ExtendedSocketException: 
'No connection could be made because the target machine actively refused it 127.0.0.1:5567'

上线:

var spark = SparkSession.Builder().GetOrCreate();

【问题讨论】:

  • 从控制台确保你有一个实例化的火花实例。如果在系统环境设置中定义了 spark 环境,则键入 spark-shell 并实例化 spark 并再次运行您的代码。
  • SPARK_HOME 是在环境变量和HADOOP_HOME 中定义的,我在运行代码之前已经启动了spark-shell。同样的错误。
  • 我认为 Visual Studio 不允许您从调试器连接。使用 args 传递 json 文件并尝试使用 spark-submit 调用您的 exe,如下所示 spark-submit \ --class org.apache.spark.deploy.dotnet.DotnetRunner \ --master local \ \ debug than, you may attach exe with visual studio debugger 在此调试模式下,DotnetRunner 不会启动 .NET 应用程序,而是等待它连接。将此命令提示符窗口保持打开状态。现在您可以使用任何调试器运行您的 .NET 应用程序来调试您的应用程序。

标签: c# .net apache-spark .net-spark


【解决方案1】:

我最终重新安装了软件包 (Microsoft.Spark),然后在 powershell 中运行给定 here 的调试命令。运行命令后,我能够将 Visual Studio 调试器附加到该进程,并且可以使用 C# 代码成功创建 spark 会话。

【讨论】:

    【解决方案2】:

    您正在尝试直接从 Visual Studio 调试您的解决方案。您需要创建一个部署环境。为此,您需要按照您自己发布的第二个链接的“运行您的 .NET for Apache Spark 应用程序”部分中的说明启动。

    打开powershell并输入:

    spark-submit `
    --class org.apache.spark.deploy.dotnet.DotnetRunner `
    --master local `
    microsoft-spark-2.4.x-<version>.jar `
    dotnet HelloSpark.dll
    

    如果你只需要调试,输入:

    spark-submit `
    --class org.apache.spark.deploy.dotnet.DotnetRunner `
    --master local `
    microsoft-spark-2.4.x-<version>.jar
    debug
    

    像往常一样在 Visual Studio 中工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-01
      • 2018-10-12
      • 2017-08-22
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多