Skip to content

Fix the chained UDF with Row type #411

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 17 commits into from
Feb 8, 2020

Conversation

elvaliuliuliu
Copy link
Contributor

@elvaliuliuliu elvaliuliuliu commented Feb 1, 2020

This is a follow PR of #376 which will fix the following chained UDF issue with Row type (#407):

    # Chained UDFs with GenericRow type.
    {
	var schema = new StructType(new[]
	{
	    new StructField("col1", new IntegerType()),
	    new StructField("col2", new StringType())
	});
	Func<Column, Column> udf1 = Udf<string>(
	    str => new GenericRow(new object[] { 1, "abc" }), schema);

	Func<Column, Column> udf2 = Udf<Row, string>(
	    row => row.GetAs<string>(1));

	Row[] rows = _df.Select(udf2(udf1(_df["name"]))).Collect().ToArray();
	Assert.Equal(3, rows.Length);

	var expected = new[] { "abc", "abc", "abc" };
	string[] actual = rows.Select(x => x[0].ToString()).ToArray();
	Assert.Equal(expected, actual);
    }

We compared with PySpark UDFs and found that Schema is not passed in chained UDF cases. So schema-less Row is created to handle chained UDF.

@imback82 imback82 added the enhancement New feature or request label Feb 7, 2020
@imback82 imback82 added this to the 0.9.0 milestone Feb 7, 2020
/// <summary>
/// Constructor for the schema-less Row class used for chained UDFs.
/// </summary>
/// <param name="genericRow">GenericRow to convert from</param>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no conversion happening here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor is for converting GenericRow to schema-less Row, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's just setting the given value to its member (not "convert"ing it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, make sense.

Copy link
Contributor

@imback82 imback82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@imback82 imback82 merged commit 6c8aea4 into dotnet:master Feb 8, 2020
@elvaliuliuliu elvaliuliuliu deleted the elva/chainedUdf branch February 8, 2020 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants