diff --git a/src/csharp/Microsoft.Spark.UnitTest/Sql/RowTests.cs b/src/csharp/Microsoft.Spark.UnitTest/Sql/RowTests.cs
index c86bf9d9..e057761b 100644
--- a/src/csharp/Microsoft.Spark.UnitTest/Sql/RowTests.cs
+++ b/src/csharp/Microsoft.Spark.UnitTest/Sql/RowTests.cs
@@ -86,7 +86,8 @@ namespace Microsoft.Spark.UnitTest
var pickledBytes = pickler.dumps(new[] { row1, row2 });
// Note that the following will invoke RowConstructor.construct().
- var unpickledData = PythonSerDe.GetUnpickledObjects(new MemoryStream(pickledBytes));
+ var unpickledData = PythonSerDe.GetUnpickledObjects(
+ new MemoryStream(pickledBytes), pickledBytes.Length);
Assert.Equal(2, unpickledData.Length);
Assert.Equal(row1, (unpickledData[0] as RowConstructor).GetRow());
diff --git a/src/csharp/Microsoft.Spark.Worker/Command/SqlCommandExecutor.cs b/src/csharp/Microsoft.Spark.Worker/Command/SqlCommandExecutor.cs
index 1526c9ef..b232b83a 100644
--- a/src/csharp/Microsoft.Spark.Worker/Command/SqlCommandExecutor.cs
+++ b/src/csharp/Microsoft.Spark.Worker/Command/SqlCommandExecutor.cs
@@ -11,7 +11,6 @@ using System.Linq;
using Apache.Arrow;
using Apache.Arrow.Ipc;
using Microsoft.Spark.Interop.Ipc;
-using Microsoft.Spark.IO;
using Microsoft.Spark.Sql;
using Microsoft.Spark.Utils;
using Razorvine.Pickle;
@@ -80,13 +79,12 @@ namespace Microsoft.Spark.Worker.Command
///
internal class PicklingSqlCommandExecutor : SqlCommandExecutor
{
- [ThreadStatic]
- private static MemoryStream s_writeOutputStream;
- [ThreadStatic]
- private static MaxLengthReadStream s_slicedReadStream;
[ThreadStatic]
private static Pickler s_pickler;
+ [ThreadStatic]
+ private static byte[] s_outputBuffer;
+
protected override CommandExecutorStat ExecuteCore(
Stream inputStream,
Stream outputStream,
@@ -118,10 +116,6 @@ namespace Microsoft.Spark.Worker.Command
$"Invalid message length: {messageLength}");
}
- MaxLengthReadStream readStream = s_slicedReadStream ??
- (s_slicedReadStream = new MaxLengthReadStream());
- readStream.Reset(inputStream, messageLength);
-
// Each row in inputRows is of type object[]. If a null is present in a row
// then the corresponding index column of the row object[] will be set to null.
// For example, (inputRows.Length == 2) and (inputRows[0][0] == null)
@@ -131,7 +125,7 @@ namespace Microsoft.Spark.Worker.Command
// |null|
// | 11|
// +----+
- object[] inputRows = PythonSerDe.GetUnpickledObjects(readStream);
+ object[] inputRows = PythonSerDe.GetUnpickledObjects(inputStream, messageLength);
for (int i = 0; i < inputRows.Length; ++i)
{
@@ -139,7 +133,9 @@ namespace Microsoft.Spark.Worker.Command
outputRows.Add(commandRunner.Run(0, inputRows[i]));
}
- WriteOutput(outputStream, outputRows);
+ // The initial (estimated) buffer size for pickling rows is set to the size of input pickled rows
+ // because the number of rows are the same for both input and output.
+ WriteOutput(outputStream, outputRows, messageLength);
stat.NumEntriesProcessed += inputRows.Length;
outputRows.Clear();
}
@@ -153,22 +149,25 @@ namespace Microsoft.Spark.Worker.Command
///
/// Stream to write to
/// Rows to write to
- private void WriteOutput(Stream stream, IEnumerable