Skip to content

Added Pivot method to RelationalGroupedDataset #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ public void TestSignaturesV2_4_X()
_df.IntersectAll(_df);

_df.ExceptAll(_df);

{
RelationalGroupedDataset df = _df.GroupBy("name");

Assert.IsType<RelationalGroupedDataset>(df.Pivot("age"));

Assert.IsType<RelationalGroupedDataset>(df.Pivot(Col("age")));
}
}
}
}
16 changes: 16 additions & 0 deletions src/csharp/Microsoft.Spark/Sql/RelationalGroupedDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ public DataFrame Min(params string[] colNames) =>
public DataFrame Sum(params string[] colNames) =>
new DataFrame((JvmObjectReference)_jvmObject.Invoke("sum", (object)colNames));

/// <summary>
/// Pivots a column of the current DataFrame and performs the specified aggregation.
/// </summary>
/// <param name="pivotColumn">Name of the column to pivot</param>
/// <returns>New RelationalGroupedDataset object with pivot applied</returns>
public RelationalGroupedDataset Pivot(string pivotColumn) => new RelationalGroupedDataset(
(JvmObjectReference)_jvmObject.Invoke("pivot", pivotColumn), _dataFrame);

/// <summary>
/// Pivots a column of the current DataFrame and performs the specified aggregation.
/// </summary>
/// <param name="pivotColumn">The column to pivot</param>
/// <returns>New RelationalGroupedDataset object with pivot applied</returns>
public RelationalGroupedDataset Pivot(Column pivotColumn) => new RelationalGroupedDataset(
(JvmObjectReference)_jvmObject.Invoke("pivot", pivotColumn), _dataFrame);

internal DataFrame Apply(StructType returnType, Func<FxDataFrame, FxDataFrame> func)
{
DataFrameGroupedMapWorkerFunction.ExecuteDelegate wrapper =
Expand Down