Skip to content

Commit 6bdc9be

Browse files
authored
Expose Pivot() method in RelationalGroupedDataset (#598)
1 parent 2aa9bc4 commit 6bdc9be

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/csharp/Microsoft.Spark.E2ETest/IpcTests/Sql/DataFrameTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,14 @@ public void TestSignaturesV2_4_X()
673673
_df.IntersectAll(_df);
674674

675675
_df.ExceptAll(_df);
676+
677+
{
678+
RelationalGroupedDataset df = _df.GroupBy("name");
679+
680+
Assert.IsType<RelationalGroupedDataset>(df.Pivot("age"));
681+
682+
Assert.IsType<RelationalGroupedDataset>(df.Pivot(Col("age")));
683+
}
676684
}
677685
}
678686
}

src/csharp/Microsoft.Spark/Sql/RelationalGroupedDataset.cs

+18
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ public DataFrame Min(params string[] colNames) =>
8585
public DataFrame Sum(params string[] colNames) =>
8686
new DataFrame((JvmObjectReference)_jvmObject.Invoke("sum", (object)colNames));
8787

88+
/// <summary>
89+
/// Pivots a column of the current DataFrame and performs the specified aggregation.
90+
/// </summary>
91+
/// <param name="pivotColumn">Name of the column to pivot</param>
92+
/// <returns>New RelationalGroupedDataset object with pivot applied</returns>
93+
public RelationalGroupedDataset Pivot(string pivotColumn) =>
94+
new RelationalGroupedDataset(
95+
(JvmObjectReference)_jvmObject.Invoke("pivot", pivotColumn), _dataFrame);
96+
97+
/// <summary>
98+
/// Pivots a column of the current DataFrame and performs the specified aggregation.
99+
/// </summary>
100+
/// <param name="pivotColumn">The column to pivot</param>
101+
/// <returns>New RelationalGroupedDataset object with pivot applied</returns>
102+
public RelationalGroupedDataset Pivot(Column pivotColumn) =>
103+
new RelationalGroupedDataset(
104+
(JvmObjectReference)_jvmObject.Invoke("pivot", pivotColumn), _dataFrame);
105+
88106
internal DataFrame Apply(StructType returnType, Func<FxDataFrame, FxDataFrame> func)
89107
{
90108
DataFrameGroupedMapWorkerFunction.ExecuteDelegate wrapper =

0 commit comments

Comments
 (0)