Skip to content

Spark 3.1.0 APIs - Column #887

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 4 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/csharp/Microsoft.Spark.E2ETest/IpcTests/Sql/ColumnTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Spark.E2ETest.Utils;
using Microsoft.Spark.Sql;
using Xunit;
using static Microsoft.Spark.Sql.Expressions.Window;
Expand Down Expand Up @@ -143,5 +144,18 @@ public void TestSignaturesV2_3_X()
Assert.Equal("col2", col2.ToString());
}

/// <summary>
/// Test signatures for APIs introduced in Spark 3.1.*.
/// </summary>
[SkipIfSparkVersionIsLessThan(Versions.V3_1_0)]
public void TestSignaturesV3_1_X()
{
Column col = Column("col");

Assert.IsType<Column>(col.WithField("col2", Lit(3)));

Assert.IsType<Column>(col.DropFields("col"));
Assert.IsType<Column>(col.DropFields("col", "col2"));
}
}
}
25 changes: 25 additions & 0 deletions src/csharp/Microsoft.Spark/Sql/Column.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,31 @@ public Column GetItem(object key)
return ApplyMethod("getItem", key);
}

/// <summary>
/// An expression that adds/replaces field in <see cref="Types.StructType"/> by name.
/// </summary>
/// <param name="fieldName">The name of the field</param>
/// <param name="column">Column to assign to the field</param>
/// <returns>
/// New column after adding/replacing field in <see cref="Types.StructType"/> by name.
/// </returns>
[Since(Versions.V3_1_0)]
public Column WithField(string fieldName, Column column)
{
return ApplyMethod("withField", fieldName, column);
}

/// <summary>
/// An expression that drops fields in <see cref="Types.StructType"/> by name.
/// </summary>
/// <param name="fieldNames">Name of fields to drop.</param>
/// <returns>New column after after dropping fields.</returns>
[Since(Versions.V3_1_0)]
public Column DropFields(params string[] fieldNames)
{
return ApplyMethod("dropFields", fieldNames);
}

/// <summary>
/// An expression that gets a field by name in a `StructType`.
/// </summary>
Expand Down