Skip to content

Commit ab0e760

Browse files
Added the MySparkApp.
1 parent 25f7915 commit ab0e760

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30621.155
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySparkApp", "MySparkApp\MySparkApp.csproj", "{7E78FDB9-921D-41AD-9703-66BC71261450}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7E78FDB9-921D-41AD-9703-66BC71261450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7E78FDB9-921D-41AD-9703-66BC71261450}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7E78FDB9-921D-41AD-9703-66BC71261450}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7E78FDB9-921D-41AD-9703-66BC71261450}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {82AFA3F8-C83A-4162-BCD8-4FE72D7535CB}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Spark" Version="1.0.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<None Update="input.txt">
14+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
15+
</None>
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
3+
using Microsoft.Spark.Sql;
4+
using static Microsoft.Spark.Sql.Functions;
5+
6+
namespace MySparkApp
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
//Console.WriteLine("Hello World!");
13+
14+
// Create Spark session
15+
SparkSession spark =
16+
SparkSession
17+
.Builder()
18+
.AppName("word_count_sample")
19+
.GetOrCreate();
20+
21+
// Create initial DataFrame
22+
string filePath = args[0];
23+
DataFrame dataFrame = spark.Read().Text(filePath);
24+
25+
//Count words
26+
DataFrame words =
27+
dataFrame
28+
.Select(Split(Col("value"), " ").Alias("words"))
29+
.Select(Explode(Col("words")).Alias("word"))
30+
.GroupBy("word")
31+
.Count()
32+
.OrderBy(Col("count").Desc());
33+
34+
// Display results
35+
words.Show();
36+
37+
// Stop Spark session
38+
spark.Stop();
39+
}
40+
}
41+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hello World
2+
This .NET app uses .NET for Apache Spark
3+
This .NET app counts words with Apache Spark

Azure/DotNet4ApacheSpark/MySparkApp/text.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)