|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using System.Linq;
|
8 | 8 | using System.Net;
|
| 9 | +using Microsoft.Spark.Interop; |
9 | 10 | using Microsoft.Spark.Interop.Ipc;
|
10 | 11 | using Microsoft.Spark.Network;
|
11 | 12 | using Microsoft.Spark.Sql.Streaming;
|
@@ -902,20 +903,26 @@ private IEnumerable<Row> GetRows(string funcName)
|
902 | 903 | /// <returns>A tuple of port number and secret string</returns>
|
903 | 904 | private (int, string) GetConnectionInfo(string funcName)
|
904 | 905 | {
|
905 |
| - var result = _jvmObject.Invoke(funcName); |
906 |
| - if (result is int) |
| 906 | + object result = _jvmObject.Invoke(funcName); |
| 907 | + Version version = SparkEnvironment.SparkVersion; |
| 908 | + return (version.Major, version.Minor, version.Build) switch |
907 | 909 | {
|
908 | 910 | // In spark 2.3.0, PythonFunction.serveIterator() returns a port number.
|
909 |
| - return ((int)result, string.Empty); |
910 |
| - } |
911 |
| - else |
912 |
| - { |
| 911 | + (2, 3, 0) => ((int)result, string.Empty), |
913 | 912 | // From spark >= 2.3.1, PythonFunction.serveIterator() returns a pair
|
914 | 913 | // where the first is a port number and the second is the secret
|
915 | 914 | // string to use for the authentication.
|
916 |
| - var pair = (JvmObjectReference[])result; |
917 |
| - return ((int)pair[0].Invoke("intValue"), (string)pair[1].Invoke("toString")); |
918 |
| - } |
| 915 | + (2, 3, _) => ParseConnectionInfo(result), |
| 916 | + (2, 4, _) => ParseConnectionInfo(result), |
| 917 | + (3, 0, _) => ParseConnectionInfo(result), |
| 918 | + _ => throw new NotSupportedException($"Spark {version} not supported.") |
| 919 | + }; |
| 920 | + } |
| 921 | + |
| 922 | + private (int, string) ParseConnectionInfo(object info) |
| 923 | + { |
| 924 | + var pair = (JvmObjectReference[])info; |
| 925 | + return ((int)pair[0].Invoke("intValue"), (string)pair[1].Invoke("toString")); |
919 | 926 | }
|
920 | 927 |
|
921 | 928 | private DataFrame WrapAsDataFrame(object obj) => new DataFrame((JvmObjectReference)obj);
|
|
0 commit comments