Skip to content

Commit 59efcfc

Browse files
authored
Merge pull request #529 from Microsoft/master
* REPL * improving debug experience * added new F# example
2 parents 3cee82e + da03e58 commit 59efcfc

File tree

70 files changed

+1804
-860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1804
-860
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ SparkCLRCodeCoverage.xml
4646
AdapterTestCoverage.xml
4747
TestResult.xml
4848
csharp/SparkCLR.compiled.nuspec
49+
cpp/Riosock.sdf
4950

5051
# Office Doc Temp files #
5152
#########################
52-
docs/~$SparkCLR.pptx
53-
docs/~$arkCLR.docx
53+
docs/~$Mobius.pptx
54+
docs/~$Mobius.docx

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ metricDataFrame.RegisterTempTable("metrics");
2525
var joinDataFrame = GetSqlContext().Sql(
2626
"SELECT joinedtable.datacenter" +
2727
", MAX(joinedtable.latency) maxlatency" +
28-
", AVG(joinedtable.latency) avglatency " +
28+
", AVG(joinedtable.latency) avglatency " +
2929
"FROM (" +
3030
"SELECT a.C1 as datacenter, b.C6 as latency " +
3131
"FROM requests a JOIN metrics b ON a.C0 = b.C3) joinedtable " +
@@ -79,21 +79,21 @@ StreamingContext sparkStreamingContext = StreamingContext.GetOrCreate(checkpoint
7979
sparkStreamingContext.Start();
8080
sparkStreamingContext.AwaitTermination();
8181
```
82-
Refer to [Mobius\csharp\Samples](csharp/Samples) directory and [sample usage](csharp/Samples/Microsoft.Spark.CSharp/samplesusage.md) for complete samples.
82+
Refer to [Mobius\csharp\Samples](./csharp/Samples) directory and [sample usage](./csharp/Samples/Microsoft.Spark.CSharp/samplesusage.md) for complete samples.
8383

8484
## API Documentation
8585

86-
Refer to [Mobius C# API documentation](csharp/Adapter/documentation/Mobius_API_Documentation.md) for the list of Spark's data processing operations supported in Mobius.
86+
Refer to [Mobius C# API documentation](./csharp/Adapter/documentation/Mobius_API_Documentation.md) for the list of Spark's data processing operations supported in Mobius.
8787

8888
## API Usage
8989

9090
Mobius API usage samples are available at:
9191

92-
* [Examples folder](./examples) which contains standalone [C# projects](/notes/running-mobius-app.md#running-mobius-examples-in-local-mode) that can be used as templates to start developing Mobius applications
92+
* [Examples folder](./examples) which contains standalone [C# projects](./notes/running-mobius-app.md#running-mobius-examples-in-local-mode) that can be used as templates to start developing Mobius applications
9393

94-
* [Samples project](csharp/Samples/Microsoft.Spark.CSharp/) which uses a comprehensive set of Mobius APIs to implement samples that are also used for functional validation of APIs
95-
96-
* Mobius performance test scenarios implemented in [C#](csharp/Perf/Microsoft.Spark.CSharp) and [Scala](scala/perf) for side by side comparison of Spark driver code
94+
* [Samples project](./csharp/Samples/Microsoft.Spark.CSharp/) which uses a comprehensive set of Mobius APIs to implement samples that are also used for functional validation of APIs
95+
96+
* Mobius performance test scenarios implemented in [C#](./csharp/Perf/Microsoft.Spark.CSharp) and [Scala](./scala/perf) for side by side comparison of Spark driver code
9797

9898
## Documents
9999

@@ -113,11 +113,12 @@ Refer to the [docs folder](docs) for design overview and other info on Mobius
113113
|Run samples (functional tests) in local mode |[Samples in Windows](notes/windows-instructions.md#running-samples) |[Samples in Linux](notes/linux-instructions.md#running-mobius-samples-in-linux) |
114114
|Run examples in local mode |[Examples in Windows](/notes/running-mobius-app.md#running-mobius-examples-in-local-mode) |[Examples in Linux](notes/linux-instructions.md#running-mobius-examples-in-linux) |
115115
|Run Mobius app |<ul><li>[Standalone cluster](notes/running-mobius-app.md#standalone-cluster)</li><li>[YARN cluster](notes/running-mobius-app.md#yarn-cluster)</li></ul> |<ul><li>[Linux cluster](notes/linux-instructions.md#running-mobius-applications-in-linux)</li><li>[Azure HDInsight Spark Cluster](/notes/linux-instructions.md#mobius-in-azure-hdinsight-spark-cluster)</li><li>[AWS EMR Spark Cluster](/notes/linux-instructions.md#mobius-in-amazon-web-services-emr-spark-cluster)</li> |
116+
|Run Mobius Shell |<ul><li>[Local](notes/mobius-shell.md#run-shell)</li><li>[YARN](notes/mobius-shell.md#run-shell)</li></ul> | Not supported yet |
116117

117118
### Useful Links
118-
* [Configuration parameters in Mobius](/notes/configuration-mobius.md)
119-
* [Troubleshoot errors in Mobius](/notes/troubleshooting-mobius.md)
120-
* [Debug Mobius apps](/notes/running-mobius-app.md#debug-mode)
119+
* [Configuration parameters in Mobius](./notes/configuration-mobius.md)
120+
* [Troubleshoot errors in Mobius](./notes/troubleshooting-mobius.md)
121+
* [Debug Mobius apps](./notes/running-mobius-app.md#debug-mode)
121122

122123
## Supported Spark Versions
123124

@@ -129,7 +130,7 @@ Mobius releases are available at https://github.com/Microsoft/Mobius/releases. R
129130

130131
[![NuGet Badge](https://buildstats.info/nuget/Microsoft.SparkCLR)](https://www.nuget.org/packages/Microsoft.SparkCLR)
131132

132-
Refer to [mobius-release-info.md](notes/mobius-release-info.md) for the details on versioning policy and the contents of the release.
133+
Refer to [mobius-release-info.md](./notes/mobius-release-info.md) for the details on versioning policy and the contents of the release.
133134

134135
## License
135136

@@ -145,7 +146,7 @@ Mobius is licensed under the MIT license. See [LICENSE](LICENSE) file for full l
145146
[![Join the chat at https://gitter.im/Microsoft/Mobius](https://badges.gitter.im/Microsoft/Mobius.svg)](https://gitter.im/Microsoft/Mobius?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
146147
[![Twitter](https://img.shields.io/twitter/url/http/twitter.com/MobiusForSpark.svg?style=social)](https://twitter.com/intent/tweet?text=@MobiusForSpark [your tweet] via @GitHub)
147148

148-
* Mobius project welcomes contributions. To contribute, follow the instructions in [CONTRIBUTING.md](notes/CONTRIBUTING.md)
149+
* Mobius project welcomes contributions. To contribute, follow the instructions in [CONTRIBUTING.md](./notes/CONTRIBUTING.md)
149150

150151
* Options to ask your question to the Mobius community
151152
* create issue on [GitHub](https://github.com/Microsoft/Mobius)

appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ test:
3737
assemblies:
3838
- csharp\AdapterTest\bin\Debug\AdapterTest.dll
3939
- csharp\WorkerTest\bin\Debug\WorkerTest.dll
40+
- csharp\ReplTest\bin\Debug\ReplTest.dll
4041

4142
# scripts to run after tests
4243
after_test:
4344
- cmd: echo [after_test] ProjectVersion=%ProjectVersion%
44-
- .\build\tools\Dynamic-Code-Coverage-Tools\CodeCoverage.exe collect /output:NativeCodeCoverage.coverage .\csharp\packages\NUnit.Console.3.0.1\tools\nunit3-console.exe .\csharp\WorkerTest\bin\Debug\WorkerTest.dll .\csharp\AdapterTest\bin\Debug\AdapterTest.dll
45+
- .\build\tools\Dynamic-Code-Coverage-Tools\CodeCoverage.exe collect /output:NativeCodeCoverage.coverage .\csharp\packages\NUnit.Console.3.0.1\tools\nunit3-console.exe .\csharp\WorkerTest\bin\Debug\WorkerTest.dll .\csharp\AdapterTest\bin\Debug\AdapterTest.dll .\csharp\ReplTest\bin\Debug\ReplTest.dll
4546
- .\build\tools\Dynamic-Code-Coverage-Tools\CodeCoverage.exe analyze /output:NativeCodeCoverage.xml NativeCodeCoverage.coverage
46-
- .\csharp\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:.\csharp\packages\NUnit.Console.3.0.1\tools\nunit3-console.exe -register:user "-targetargs:"".\csharp\WorkerTest\bin\Debug\WorkerTest.dll"" "".\csharp\AdapterTest\bin\Debug\AdapterTest.dll"" " -filter:"+[CSharpWorker*|Microsoft.Spark.CSharp*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\SparkCLRCodeCoverage.xml
47+
- .\csharp\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:.\csharp\packages\NUnit.Console.3.0.1\tools\nunit3-console.exe -register:user "-targetargs:"".\csharp\WorkerTest\bin\Debug\WorkerTest.dll"" "".\csharp\AdapterTest\bin\Debug\AdapterTest.dll"" "".\csharp\ReplTest\bin\Debug\ReplTest.dll"" " -filter:"+[CSharpWorker*|Microsoft.Spark.CSharp*|Repl]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\SparkCLRCodeCoverage.xml
4748
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
4849
- pip install codecov
4950
- codecov -f "NativeCodeCoverage.xml" "SparkCLRCodeCoverage.xml"

build/Build.cmd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if NOT EXIST "%SPARKCLR_HOME%\bin" mkdir "%SPARKCLR_HOME%\bin"
3636
if NOT EXIST "%SPARKCLR_HOME%\data" mkdir "%SPARKCLR_HOME%\data"
3737
if NOT EXIST "%SPARKCLR_HOME%\lib" mkdir "%SPARKCLR_HOME%\lib"
3838
if NOT EXIST "%SPARKCLR_HOME%\samples" mkdir "%SPARKCLR_HOME%\samples"
39+
if NOT EXIST "%SPARKCLR_HOME%\repl" mkdir "%SPARKCLR_HOME%\repl"
3940

4041
@echo Assemble Mobius Scala components
4142
pushd "%CMDHOME%\..\scala"
@@ -153,6 +154,11 @@ copy /y Samples\Microsoft.Spark.CSharp\bin\Release\* "%SPARKCLR_HOME%\samples\"
153154

154155
@echo Mobius Samples data
155156
copy /y Samples\Microsoft.Spark.CSharp\data\* "%SPARKCLR_HOME%\data\"
157+
158+
@echo SparkCLR REPL
159+
copy /y Worker\Microsoft.Spark.CSharp\bin\Release\* "%SPARKCLR_HOME%\repl\"
160+
copy /y Repl\bin\Release\* "%SPARKCLR_HOME%\repl\"
161+
156162
popd
157163

158164
@echo Download external dependencies

csharp/Adapter/Microsoft.Spark.CSharp/Configuration/ConfigurationService.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal class ConfigurationService : IConfigurationService
2424
public const string SPARKCLR_HOME = "SPARKCLR_HOME";
2525
public const string SPARK_MASTER = "spark.master";
2626
public const string CSHARPBACKEND_PORT = "CSHARPBACKEND_PORT";
27+
public const int CSHARPBACKEND_DEBUG_PORT = 5567;
2728

2829
private readonly ILoggerService logger = LoggerServiceFactory.GetLogger(typeof(ConfigurationService));
2930
private readonly SparkCLRConfiguration configuration;
@@ -178,13 +179,21 @@ internal SparkCLRDebugConfiguration(System.Configuration.Configuration configura
178179

179180
internal override int GetPortNumber()
180181
{
182+
int cSharpBackendPortNumber = CSHARPBACKEND_DEBUG_PORT;
181183
KeyValueConfigurationElement portConfig = appSettings.Settings[CSharpBackendPortNumberSettingKey];
182184
if (portConfig == null)
183185
{
184-
throw new ConfigurationErrorsException(string.Format("Need to set {0} value in App.config for running in DEBUG mode.", CSharpBackendPortNumberSettingKey));
186+
logger.LogInfo(
187+
string.Format(
188+
"Port number not set using setting {0} in App.config. Using default port {1} to connect to CSharpBackend",
189+
CSharpBackendPortNumberSettingKey, cSharpBackendPortNumber));
185190
}
186-
int cSharpBackendPortNumber = int.Parse(portConfig.Value);
187-
logger.LogInfo(string.Format("CSharpBackend port number read from app config {0}", cSharpBackendPortNumber));
191+
else
192+
{
193+
cSharpBackendPortNumber = int.Parse(portConfig.Value);
194+
logger.LogInfo(string.Format("CSharpBackend port number read from app config {0}. Using it to connect to CSharpBackend", cSharpBackendPortNumber));
195+
}
196+
188197
return cSharpBackendPortNumber;
189198
}
190199

csharp/Adapter/Microsoft.Spark.CSharp/Core/SparkContext.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ public class SparkContext
3232
/// </summary>
3333
internal static SparkContext GetActiveSparkContext()
3434
{
35-
return _activeSparkContext;
35+
return _activeSparkContext;
3636
}
3737

3838
private AccumulatorServer accumulatorServer;
3939
private int nextAccumulatorId;
4040

41+
/// <summary>
42+
/// Return a copy of this JavaSparkContext's configuration. The configuration ''cannot'' be changed at runtime.
43+
/// </summary>
44+
public SparkConf GetConf()
45+
{
46+
return new SparkConf(SparkContextProxy.GetConf());
47+
}
48+
4149
/// <summary>
4250
/// The version of Spark on which this application is running.
4351
/// </summary>
@@ -88,7 +96,7 @@ public int DefaultMinPartitions
8896
/// <param name="sparkHome">the path that holds spark bits</param>
8997
public SparkContext(string master, string appName, string sparkHome)
9098
: this(master, appName, sparkHome, null)
91-
{}
99+
{ }
92100

93101
/// <summary>
94102
/// Initializes a SparkContext instance with a specific master and application name.
@@ -97,15 +105,15 @@ public SparkContext(string master, string appName, string sparkHome)
97105
/// <param name="appName"></param>
98106
public SparkContext(string master, string appName)
99107
: this(master, appName, null, null)
100-
{}
108+
{ }
101109

102110
/// <summary>
103111
/// Initializes a SparkContext instance with a specific spark config.
104112
/// </summary>
105113
/// <param name="conf">A SparkConf object that represents the settings for spark</param>
106114
public SparkContext(SparkConf conf)
107115
: this(null, null, null, conf)
108-
{}
116+
{ }
109117

110118
/// <summary>
111119
/// when created from checkpoint
@@ -584,6 +592,27 @@ internal static byte[] BuildCommand(CSharpWorkerFunc workerFunc, SerializedMode
584592
Array.Reverse(lengthAsBytes);
585593
commandPayloadBytesList.Add(lengthAsBytes);
586594
commandPayloadBytesList.Add(modeBytes);
595+
596+
// add run mode
597+
// N - normal
598+
// R - repl
599+
var runMode = Environment.GetEnvironmentVariable("SPARKCLR_RUN_MODE") ?? "N";
600+
var runModeBytes = Encoding.UTF8.GetBytes(runMode);
601+
lengthAsBytes = BitConverter.GetBytes(runModeBytes.Length);
602+
Array.Reverse(lengthAsBytes);
603+
commandPayloadBytesList.Add(lengthAsBytes);
604+
commandPayloadBytesList.Add(runModeBytes);
605+
606+
if ("R".Equals(runMode, StringComparison.InvariantCultureIgnoreCase))
607+
{
608+
// add compilation dump directory
609+
var compilationDumpDirBytes = Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("SPARKCLR_SCRIPT_COMPILATION_DIR")?? ".");
610+
lengthAsBytes = BitConverter.GetBytes(compilationDumpDirBytes.Length);
611+
Array.Reverse(lengthAsBytes);
612+
commandPayloadBytesList.Add(lengthAsBytes);
613+
commandPayloadBytesList.Add(compilationDumpDirBytes);
614+
}
615+
587616
// add func
588617
var funcBytes = stream.ToArray();
589618
var funcBytesLengthAsBytes = BitConverter.GetBytes(funcBytes.Length);

csharp/Adapter/Microsoft.Spark.CSharp/Interop/SparkCLREnvironment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[assembly: InternalsVisibleTo("Tests.Common")]
1212
[assembly: InternalsVisibleTo("AdapterTest")]
1313
[assembly: InternalsVisibleTo("WorkerTest")]
14+
[assembly: InternalsVisibleTo("ReplTest")]
1415
// DynamicProxyGenAssembly2 is a temporary assembly built by mocking systems that use CastleProxy like Moq
1516
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
1617
namespace Microsoft.Spark.CSharp.Interop

csharp/Adapter/Microsoft.Spark.CSharp/Proxy/ISparkContextProxy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Spark.CSharp.Proxy
1414
{
1515
internal interface ISparkContextProxy
1616
{
17+
ISparkConfProxy GetConf();
1718
ISqlContextProxy CreateSqlContext();
1819
ISqlContextProxy CreateHiveContext();
1920
IColumnProxy CreateColumnFromName(string name);

csharp/Adapter/Microsoft.Spark.CSharp/Proxy/Ipc/SparkContextIpcProxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ internal class SparkContextIpcProxy : ISparkContextProxy
2323
private JvmObjectReference jvmAccumulatorReference;
2424
internal List<JvmObjectReference> jvmBroadcastReferences = new List<JvmObjectReference>();
2525

26+
public ISparkConfProxy GetConf()
27+
{
28+
return new SparkConfIpcProxy(new JvmObjectReference((string)SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jvmJavaContextReference, "getConf")));
29+
}
30+
2631
internal JvmObjectReference JvmSparkContextReference
2732
{
2833
get { return jvmSparkContextReference; }

csharp/AdapterTest/ConfigurationServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void TestDebugConfiguration()
3939
try
4040
{
4141
ConfigurationService debugConfiguration = new ConfigurationService();
42-
Assert.Throws<ConfigurationErrorsException>(() => Console.WriteLine(debugConfiguration.BackendPortNumber));
42+
Assert.AreEqual(ConfigurationService.CSHARPBACKEND_DEBUG_PORT, debugConfiguration.BackendPortNumber);
4343
Assert.Throws<Exception>(() => Console.WriteLine(debugConfiguration.GetCSharpWorkerExePath()));
4444
}
4545
finally

0 commit comments

Comments
 (0)